Skip to content

Commit

Permalink
fix build kvserver
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Feb 27, 2023
1 parent b0a33a2 commit 2aa300b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ You will see the following result if successful:

client getvalues value = [test_value]

## Enable SDK

If you want to enable sdk verification, add a flag to the command

./example/start_kv_server.sh --define enable_sdk=True

## FAQ

Expand Down
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ http_archive(
http_archive(
name = "pybind11",
build_file = "@pybind11_bazel//:pybind11.BUILD",
strip_prefix = "pybind11-2.10.3",
urls = ["https://github.com/pybind/pybind11/archive/v2.10.3.tar.gz"],
strip_prefix = "pybind11-2.6.2",
urls = ["https://github.com/pybind/pybind11/archive/v2.6.2.tar.gz"],
)

load("@pybind11_bazel//:python_configure.bzl", "python_configure")
Expand Down
2 changes: 1 addition & 1 deletion example/start_kv_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SERVER_PATH=./bazel-bin/kv_server/kv_server
SERVER_CONFIG=example/kv_config.config
WORK_PATH=$PWD

bazel build kv_server:kv_server --define enable_sdk=True
bazel build kv_server:kv_server $@
nohup $SERVER_PATH $SERVER_CONFIG $WORK_PATH/cert/node1.key.pri $WORK_PATH/cert/cert_1.cert > server0.log &
nohup $SERVER_PATH $SERVER_CONFIG $WORK_PATH/cert/node2.key.pri $WORK_PATH/cert/cert_2.cert > server1.log &
nohup $SERVER_PATH $SERVER_CONFIG $WORK_PATH/cert/node3.key.pri $WORK_PATH/cert/cert_3.cert > server2.log &
Expand Down
30 changes: 14 additions & 16 deletions kv_server/BUILD
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package(default_visibility = ["//visibility:public"])
load(
"@bazel_skylib//rules:common_settings.bzl",
"bool_flag",
)

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")

bool_flag(
name = "enable_sdk",
build_setting_default = False,
# This visibility is working, however the config_setting is in same package.
visibility = ["//visibility:private"]
visibility = ["//visibility:private"],
)

config_setting(
name = "custom",
values = {"define": "enable_sdk=True"},
name = "custom",
values = {"define": "enable_sdk=True"},
visibility = ["//visibility:private"],
)

cc_library(
Expand All @@ -23,14 +20,15 @@ cc_library(
hdrs = ["py_verificator.h"],
deps = [
"//common:comm",
"@pybind11" ,
"@pybind11//:pybind11_embed",
"@pybind11",
"@pybind11//:pybind11_embed",
],
)

cc_test(
name = "py_verificator_test",
srcs = ["py_verificator_test.cpp"],
tags = ["manual"],
deps = [
":py_verificator",
"//common/test:test_main",
Expand All @@ -41,6 +39,10 @@ cc_library(
name = "kv_server_executor",
srcs = ["kv_server_executor.cpp"],
hdrs = ["kv_server_executor.h"],
copts = select({
":custom": ["-DENABLED_SDK"],
"//conditions:default": [],
}),
deps = [
"//common:comm",
"//config:resdb_config_utils",
Expand All @@ -49,13 +51,9 @@ cc_library(
"//execution:transaction_executor_impl",
"//proto:kv_server_cc_proto",
] + select({
":custom":[":py_verificator"],
"//conditions:default": [],
":custom": [":py_verificator"],
"//conditions:default": [],
}),
copts = select({
":custom":["-DENABLED_SDK"],
"//conditions:default": [],
})
)

cc_test(
Expand Down
3 changes: 0 additions & 3 deletions kv_server/kv_server_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ KVServerExecutor::KVServerExecutor(const ResConfigData& config_data,
equip_leveldb_ = config_data.leveldb_info().enable_leveldb();

#ifdef ENABLED_SDK
LOG(ERROR)<<"here?";
require_txn_validation_ = config_data.require_txn_validation();
require_txn_validation_ = true;
if (require_txn_validation_) {
py_verificator_ = std::make_unique<PYVerificator>();
}
Expand Down Expand Up @@ -80,7 +78,6 @@ std::unique_ptr<std::string> KVServerExecutor::ExecuteData(

void KVServerExecutor::Set(const std::string& key, const std::string& value) {
#ifdef ENABLED_SDK
LOG(ERROR)<<"here?";
if (require_txn_validation_) {
bool is_valid = py_verificator_->Validate(value);
if (!is_valid) {
Expand Down
1 change: 1 addition & 0 deletions kv_server/py_verificator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ PYVerificator::PYVerificator() {

// Validate transactions committed by the Python SDK
bool PYVerificator::Validate(const std::string& transaction) {
LOG(ERROR) << "validate";
auto locals = py::dict("transaction"_a = transaction);

py::exec(R"(
Expand Down

0 comments on commit 2aa300b

Please sign in to comment.