Skip to content

Commit

Permalink
Clean up schema manager interfaces (#1291)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaphet authored and dangleptr committed Nov 20, 2019
1 parent e407c62 commit 5ace754
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 173 deletions.
14 changes: 0 additions & 14 deletions src/meta/SchemaManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,16 @@ class SchemaManager {
TagID tag,
SchemaVer ver = -1) = 0;

virtual std::shared_ptr<const SchemaProviderIf> getTagSchema(folly::StringPiece spaceName,
folly::StringPiece tagName,
SchemaVer ver = -1) = 0;

// Returns a negative number when the schema does not exist
virtual StatusOr<SchemaVer> getNewestTagSchemaVer(GraphSpaceID space, TagID tag) = 0;

virtual SchemaVer getNewestTagSchemaVer(folly::StringPiece spaceName,
folly::StringPiece tagName) = 0;

virtual std::shared_ptr<const SchemaProviderIf> getEdgeSchema(GraphSpaceID space,
EdgeType edge,
SchemaVer ver = -1) = 0;

virtual std::shared_ptr<const SchemaProviderIf> getEdgeSchema(folly::StringPiece spaceName,
folly::StringPiece typeName,
SchemaVer ver = -1) = 0;

// Returns a negative number when the schema does not exist
virtual StatusOr<SchemaVer> getNewestEdgeSchemaVer(GraphSpaceID space, EdgeType edge) = 0;

virtual SchemaVer getNewestEdgeSchemaVer(folly::StringPiece spaceName,
folly::StringPiece typeName) = 0;

virtual StatusOr<GraphSpaceID> toGraphSpaceID(folly::StringPiece spaceName) = 0;

virtual StatusOr<TagID> toTagID(GraphSpaceID space, folly::StringPiece tagName) = 0;
Expand Down
72 changes: 0 additions & 72 deletions src/meta/ServerBasedSchemaManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,49 +41,13 @@ ServerBasedSchemaManager::getTagSchema(GraphSpaceID space, TagID tag, SchemaVer
return std::shared_ptr<const SchemaProviderIf>();
}

std::shared_ptr<const SchemaProviderIf>
ServerBasedSchemaManager::getTagSchema(folly::StringPiece spaceName,
folly::StringPiece tagName,
SchemaVer ver) {
auto spaceStatus = toGraphSpaceID(spaceName);
if (!spaceStatus.ok()) {
return std::shared_ptr<const SchemaProviderIf>();
}
auto spaceId = spaceStatus.value();
auto tagStatus = toTagID(spaceId, tagName);
if (!tagStatus.ok()) {
return std::shared_ptr<const SchemaProviderIf>();
}
auto tagId = tagStatus.value();
return getTagSchema(spaceId, tagId, ver);
}

// Returns a negative number when the schema does not exist
StatusOr<SchemaVer> ServerBasedSchemaManager::getNewestTagSchemaVer(GraphSpaceID space,
TagID tag) {
CHECK(metaClient_);
return metaClient_->getNewestTagVerFromCache(space, tag);
}

SchemaVer ServerBasedSchemaManager::getNewestTagSchemaVer(folly::StringPiece spaceName,
folly::StringPiece tagName) {
auto spaceStatus = toGraphSpaceID(spaceName);
if (!spaceStatus.ok()) {
return -1;
}
auto spaceId = spaceStatus.value();
auto tagStatus = toTagID(spaceId, tagName);
if (!tagStatus.ok()) {
return -1;
}
auto tagId = tagStatus.value();
auto ret = getNewestTagSchemaVer(spaceId, tagId);
if (!ret.ok()) {
return -1;
}
return ret.value();
}

std::shared_ptr<const SchemaProviderIf>
ServerBasedSchemaManager::getEdgeSchema(GraphSpaceID space, EdgeType edge, SchemaVer ver) {
VLOG(3) << "Get Edge Schema Space " << space << ", EdgeType " << edge << ", Version " << ver;
Expand All @@ -105,49 +69,13 @@ ServerBasedSchemaManager::getEdgeSchema(GraphSpaceID space, EdgeType edge, Schem
return std::shared_ptr<const SchemaProviderIf>();
}

std::shared_ptr<const SchemaProviderIf>
ServerBasedSchemaManager::getEdgeSchema(folly::StringPiece spaceName,
folly::StringPiece typeName,
SchemaVer ver) {
auto spaceStatus = toGraphSpaceID(spaceName);
if (!spaceStatus.ok()) {
return std::shared_ptr<const SchemaProviderIf>();
}
auto spaceId = spaceStatus.value();
auto edgeStatus = toEdgeType(spaceId, typeName);
if (!edgeStatus.ok()) {
return std::shared_ptr<const SchemaProviderIf>();
}
auto edgeType = edgeStatus.value();
return getEdgeSchema(spaceId, edgeType, ver);
}

// Returns a negative number when the schema does not exist
StatusOr<SchemaVer> ServerBasedSchemaManager::getNewestEdgeSchemaVer(GraphSpaceID space,
EdgeType edge) {
CHECK(metaClient_);
return metaClient_->getNewestEdgeVerFromCache(space, edge);
}

SchemaVer ServerBasedSchemaManager::getNewestEdgeSchemaVer(folly::StringPiece spaceName,
folly::StringPiece typeName) {
auto spaceStatus = toGraphSpaceID(spaceName);
if (!spaceStatus.ok()) {
return -1;
}
auto spaceId = spaceStatus.value();
auto edgeStatus = toEdgeType(spaceId, typeName);
if (!edgeStatus.ok()) {
return -1;
}
auto edgeType = edgeStatus.value();
auto ret = getNewestEdgeSchemaVer(spaceId, edgeType);
if (!ret.ok()) {
return -1;
}
return ret.value();
}

StatusOr<GraphSpaceID> ServerBasedSchemaManager::toGraphSpaceID(folly::StringPiece spaceName) {
CHECK(metaClient_);
return metaClient_->getSpaceIdByNameFromCache(spaceName.str());
Expand Down
16 changes: 0 additions & 16 deletions src/meta/ServerBasedSchemaManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,16 @@ class ServerBasedSchemaManager : public SchemaManager {
std::shared_ptr<const SchemaProviderIf> getTagSchema(
GraphSpaceID space, TagID tag, SchemaVer ver = -1) override;

std::shared_ptr<const SchemaProviderIf> getTagSchema(
folly::StringPiece spaceName,
folly::StringPiece tagName,
SchemaVer ver = -1) override;

// Returns a negative number when the schema does not exist
StatusOr<SchemaVer> getNewestTagSchemaVer(GraphSpaceID space, TagID tag) override;

SchemaVer getNewestTagSchemaVer(folly::StringPiece spaceName,
folly::StringPiece tagName) override;

// return the newest one if ver less 0
std::shared_ptr<const SchemaProviderIf> getEdgeSchema(
GraphSpaceID space, EdgeType edge, SchemaVer ver = -1) override;

std::shared_ptr<const SchemaProviderIf> getEdgeSchema(
folly::StringPiece spaceName,
folly::StringPiece typeName,
SchemaVer ver = -1) override;

// Returns a negative number when the schema does not exist
StatusOr<SchemaVer> getNewestEdgeSchemaVer(GraphSpaceID space, EdgeType edge) override;

SchemaVer getNewestEdgeSchemaVer(folly::StringPiece spaceName,
folly::StringPiece typeName) override;

StatusOr<GraphSpaceID> toGraphSpaceID(folly::StringPiece spaceName) override;

StatusOr<TagID> toTagID(GraphSpaceID space, folly::StringPiece tagName) override;
Expand Down
45 changes: 0 additions & 45 deletions src/storage/test/AdHocSchemaManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ void AdHocSchemaManager::removeTagSchema(GraphSpaceID space, TagID tag) {
tagSchemas_.erase(std::make_pair(space, tag));
}

std::shared_ptr<const nebula::meta::SchemaProviderIf>
AdHocSchemaManager::getTagSchema(folly::StringPiece spaceName,
folly::StringPiece tagName,
SchemaVer ver) {
auto space = toGraphSpaceID(spaceName).value();
return getTagSchema(space, toTagID(space, tagName).value(), ver);
}

std::shared_ptr<const nebula::meta::SchemaProviderIf>
AdHocSchemaManager::getTagSchema(GraphSpaceID space,
TagID tag,
Expand Down Expand Up @@ -84,12 +76,6 @@ AdHocSchemaManager::getTagSchema(GraphSpaceID space,
}
}

SchemaVer AdHocSchemaManager::getNewestTagSchemaVer(folly::StringPiece spaceName,
folly::StringPiece tagName) {
auto space = toGraphSpaceID(spaceName).value();
return getNewestTagSchemaVer(space, toTagID(space, tagName).value()).value();
}

StatusOr<SchemaVer> AdHocSchemaManager::getNewestTagSchemaVer(GraphSpaceID space, TagID tag) {
folly::RWSpinLock::ReadHolder rh(tagLock_);
auto it = tagSchemas_.find(std::make_pair(space, tag));
Expand All @@ -102,14 +88,6 @@ StatusOr<SchemaVer> AdHocSchemaManager::getNewestTagSchemaVer(GraphSpaceID space
}
}

std::shared_ptr<const nebula::meta::SchemaProviderIf>
AdHocSchemaManager::getEdgeSchema(folly::StringPiece spaceName,
folly::StringPiece typeName,
SchemaVer ver) {
auto space = toGraphSpaceID(spaceName).value();
return getEdgeSchema(space, toEdgeType(space, typeName).value(), ver);
}

std::shared_ptr<const nebula::meta::SchemaProviderIf>
AdHocSchemaManager::getEdgeSchema(GraphSpaceID space,
EdgeType edge,
Expand Down Expand Up @@ -142,12 +120,6 @@ AdHocSchemaManager::getEdgeSchema(GraphSpaceID space,
}
}

SchemaVer AdHocSchemaManager::getNewestEdgeSchemaVer(folly::StringPiece spaceName,
folly::StringPiece typeName) {
auto space = toGraphSpaceID(spaceName).value();
return getNewestEdgeSchemaVer(space, toEdgeType(space, typeName).value()).value();
}

StatusOr<SchemaVer> AdHocSchemaManager::getNewestEdgeSchemaVer(GraphSpaceID space, EdgeType edge) {
folly::RWSpinLock::ReadHolder rh(edgeLock_);
auto it = edgeSchemas_.find(std::make_pair(space, edge));
Expand Down Expand Up @@ -188,22 +160,5 @@ StatusOr<EdgeType> AdHocSchemaManager::toEdgeType(GraphSpaceID space, folly::Str
return -1;
}

// This interface is disabled
StatusOr<std::string> AdHocSchemaManager::toEdgeName(GraphSpaceID space, EdgeType edgeType) {
UNUSED(space);
UNUSED(edgeType);
LOG(FATAL) << "Unimplement";
return "";
}


// This interface is disabled
StatusOr<std::vector<std::string>> AdHocSchemaManager::getAllEdge(GraphSpaceID space) {
UNUSED(space);
LOG(FATAL) << "Unimplement";
std::vector<std::string> r = { "" };
return r;
}

} // namespace storage
} // namespace nebula
33 changes: 7 additions & 26 deletions src/storage/test/AdHocSchemaManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,52 +36,33 @@ class AdHocSchemaManager final : public nebula::meta::SchemaManager {
TagID tag,
SchemaVer version = -1) override;

// This interface is disabled
std::shared_ptr<const nebula::meta::SchemaProviderIf>
getTagSchema(folly::StringPiece spaceName,
folly::StringPiece tagName,
SchemaVer version = -1) override;

// Returns a negative number when the schema does not exist
StatusOr<SchemaVer> getNewestTagSchemaVer(GraphSpaceID space, TagID tag) override;

// This interface is disabled
SchemaVer getNewestTagSchemaVer(folly::StringPiece spaceName,
folly::StringPiece tagName) override;

std::shared_ptr<const nebula::meta::SchemaProviderIf>
getEdgeSchema(GraphSpaceID space,
EdgeType edge,
SchemaVer version = -1) override;

// This interface is disabled
std::shared_ptr<const nebula::meta::SchemaProviderIf>
getEdgeSchema(folly::StringPiece spaceName,
folly::StringPiece typeName,
SchemaVer version = -1) override;

// Returns a negative number when the schema does not exist
StatusOr<SchemaVer> getNewestEdgeSchemaVer(GraphSpaceID space, EdgeType edge) override;

// This interface is disabled
SchemaVer getNewestEdgeSchemaVer(folly::StringPiece spaceName,
folly::StringPiece typeName) override;

StatusOr<GraphSpaceID> toGraphSpaceID(folly::StringPiece spaceName) override;

StatusOr<TagID> toTagID(GraphSpaceID space, folly::StringPiece tagName) override;

// This interface is disabled
StatusOr<EdgeType> toEdgeType(GraphSpaceID space, folly::StringPiece typeName) override;

// This interface is disabled
StatusOr<std::string> toEdgeName(GraphSpaceID space, EdgeType edgeType) override;
StatusOr<std::string> toEdgeName(GraphSpaceID, EdgeType) override {
LOG(FATAL) << "Unimplemented";
}

// This interface is disabled
StatusOr<std::vector<std::string>> getAllEdge(GraphSpaceID space) override;
StatusOr<std::vector<std::string>> getAllEdge(GraphSpaceID) override {
LOG(FATAL) << "Unimplemented";
}

void init(nebula::meta::MetaClient *client = nullptr) override {
UNUSED(client);
void init(nebula::meta::MetaClient *) override {
}

protected:
Expand Down

0 comments on commit 5ace754

Please sign in to comment.