Skip to content

Commit

Permalink
GetProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
critical27 committed Sep 14, 2021
1 parent 4c53153 commit efcbed5
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/kvstore/KVEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ class KVEngine {
virtual nebula::cpp2::ErrorCode setDBOption(const std::string& configKey,
const std::string& configValue) = 0;

// Get DB Property
virtual ErrorOr<nebula::cpp2::ErrorCode, std::string> getProperty(
const std::string& property) = 0;

virtual nebula::cpp2::ErrorCode compact() = 0;

virtual nebula::cpp2::ErrorCode flush() = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/kvstore/KVStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ class KVStore {

virtual std::vector<std::string> getDataRoot() const = 0;

virtual ErrorOr<nebula::cpp2::ErrorCode, std::string> getProperty(
GraphSpaceID spaceId, const std::string& property) = 0;

protected:
KVStore() = default;
};
Expand Down
21 changes: 21 additions & 0 deletions src/kvstore/NebulaStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1168,5 +1168,26 @@ nebula::cpp2::ErrorCode NebulaStore::multiPutWithoutReplicator(GraphSpaceID spac
return nebula::cpp2::ErrorCode::SUCCEEDED;
}

ErrorOr<nebula::cpp2::ErrorCode, std::string> NebulaStore::getProperty(
GraphSpaceID spaceId, const std::string& property) {
auto spaceRet = space(spaceId);
if (!ok(spaceRet)) {
LOG(ERROR) << "Get Space " << spaceId << " Failed";
return error(spaceRet);
}
auto space = nebula::value(spaceRet);

folly::dynamic obj = folly::dynamic::object;
for (size_t i = 0; i < space->engines_.size(); i++) {
auto val = space->engines_[i]->getProperty(property);
if (!ok(val)) {
return error(val);
}
auto eng = folly::stringPrintf("Engine %zu", i);
obj[eng] = std::move(value(val));
}
return folly::toJson(obj);
}

} // namespace kvstore
} // namespace nebula
3 changes: 3 additions & 0 deletions src/kvstore/NebulaStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ class NebulaStore : public KVStore, public Handler {
nebula::cpp2::ErrorCode multiPutWithoutReplicator(GraphSpaceID spaceId,
std::vector<KV> keyValues) override;

ErrorOr<nebula::cpp2::ErrorCode, std::string> getProperty(GraphSpaceID spaceId,
const std::string& property) override;

private:
void loadPartFromDataPath();

Expand Down
10 changes: 10 additions & 0 deletions src/kvstore/RocksEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,16 @@ nebula::cpp2::ErrorCode RocksEngine::setDBOption(const std::string& configKey,
}
}

ErrorOr<nebula::cpp2::ErrorCode, std::string> RocksEngine::getProperty(
const std::string& property) {
std::string value;
if (!db_->GetProperty(property, &value)) {
return nebula::cpp2::ErrorCode::E_INVALID_PARM;
} else {
return value;
}
}

nebula::cpp2::ErrorCode RocksEngine::compact() {
rocksdb::CompactRangeOptions options;
options.change_level = FLAGS_rocksdb_compact_change_level;
Expand Down
2 changes: 2 additions & 0 deletions src/kvstore/RocksEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ class RocksEngine : public KVEngine {
nebula::cpp2::ErrorCode setDBOption(const std::string& configKey,
const std::string& configValue) override;

ErrorOr<nebula::cpp2::ErrorCode, std::string> getProperty(const std::string& property) override;

nebula::cpp2::ErrorCode compact() override;

nebula::cpp2::ErrorCode flush() override;
Expand Down
1 change: 1 addition & 0 deletions src/storage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ nebula_add_library(
http/StorageHttpDownloadHandler.cpp
http/StorageHttpAdminHandler.cpp
http/StorageHttpStatsHandler.cpp
http/StorageHttpPropertyHandler.cpp
)

nebula_add_library(
Expand Down
4 changes: 4 additions & 0 deletions src/storage/StorageServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "storage/http/StorageHttpAdminHandler.h"
#include "storage/http/StorageHttpDownloadHandler.h"
#include "storage/http/StorageHttpIngestHandler.h"
#include "storage/http/StorageHttpPropertyHandler.h"
#include "storage/http/StorageHttpStatsHandler.h"
#include "storage/transaction/TransactionManager.h"
#include "version/Version.h"
Expand Down Expand Up @@ -104,6 +105,9 @@ bool StorageServer::initWebService() {
router.get("/rocksdb_stats").handler([](web::PathParams&&) {
return new storage::StorageHttpStatsHandler();
});
router.get("/rocksdb_property").handler([this](web::PathParams&&) {
return new storage::StorageHttpPropertyHandler(schemaMan_.get(), kvstore_.get());
});

auto status = webSvc_->start();
return status.ok();
Expand Down
17 changes: 17 additions & 0 deletions src/storage/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,23 @@ nebula_add_test(
gtest
)

nebula_add_test(
NAME
storage_http_property_test
SOURCES
StorageHttpPropertyHandlerTest.cpp
OBJECTS
$<TARGET_OBJECTS:storage_http_handler>
$<TARGET_OBJECTS:ws_obj>
${storage_test_deps}
LIBRARIES
${ROCKSDB_LIBRARIES}
${THRIFT_LIBRARIES}
${PROXYGEN_LIBRARIES}
wangle
gtest
)

nebula_add_test(
NAME
scan_edge_test
Expand Down

0 comments on commit efcbed5

Please sign in to comment.