Skip to content

Commit

Permalink
1, fixed unused introducer. 2, Unified schema version number to int64…
Browse files Browse the repository at this point in the history
…_t (vesoft-inc#325)

* 1, fixed unused introducer. 2, Unified schema version number to int64_t

* Using SchemaVer instead of int64_t

* Fixed folly::to(int64_t)

* Address comments
  • Loading branch information
boshengchen authored and dangleptr committed May 8, 2019
1 parent 3effb76 commit c42f535
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/dataman/ResultSchemaProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ResultSchemaProvider : public meta::SchemaProviderIf {
explicit ResultSchemaProvider(cpp2::Schema);
virtual ~ResultSchemaProvider() = default;

int32_t getVersion() const noexcept override {
SchemaVer getVersion() const noexcept override {
return schemaVer_;
}

Expand All @@ -51,14 +51,14 @@ class ResultSchemaProvider : public meta::SchemaProviderIf {
const folly::StringPiece name) const override;

protected:
int32_t schemaVer_{0};
SchemaVer schemaVer_{0};

ColumnDefs columns_;
// Map of Hash64(field_name) -> array index
UnorderedMap<uint64_t, int64_t> nameIndex_;

// Default constructor, only used by SchemaWriter
explicit ResultSchemaProvider(int32_t ver = 0) : schemaVer_(ver) {}
explicit ResultSchemaProvider(SchemaVer ver = 0) : schemaVer_(ver) {}
};

} // namespace nebula
Expand Down
4 changes: 2 additions & 2 deletions src/dataman/RowReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ std::unique_ptr<RowReader> RowReader::getEdgePropReader(
std::unique_ptr<RowReader> RowReader::getRowReader(
folly::StringPiece row,
std::shared_ptr<const meta::SchemaProviderIf> schema) {
int32_t ver = getSchemaVer(row);
SchemaVer ver = getSchemaVer(row);
CHECK_EQ(ver, schema->getVersion());
return std::unique_ptr<RowReader>(new RowReader(row, std::move(schema)));
}
Expand Down Expand Up @@ -268,7 +268,7 @@ int32_t RowReader::numFields() const noexcept {
}


int32_t RowReader::schemaVer() const noexcept {
SchemaVer RowReader::schemaVer() const noexcept {
return schema_->getVersion();
}

Expand Down
2 changes: 1 addition & 1 deletion src/dataman/RowReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class RowReader {

virtual ~RowReader() = default;

int32_t schemaVer() const noexcept;
SchemaVer schemaVer() const noexcept;
int32_t numFields() const noexcept;

Iterator begin() const noexcept;
Expand Down
14 changes: 7 additions & 7 deletions src/dataman/RowWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ RowWriter::RowWriter(std::shared_ptr<const SchemaProviderIf> schema)


int64_t RowWriter::size() const noexcept {
int32_t offsetBytes = calcOccupiedBytes(cord_.size());
int32_t verBytes = 0;
auto offsetBytes = calcOccupiedBytes(cord_.size());
SchemaVer verBytes = 0;
if (schema_->getVersion() > 0) {
verBytes = calcOccupiedBytes(schema_->getVersion());
}
Expand All @@ -52,12 +52,12 @@ void RowWriter::encodeTo(std::string& encoded) noexcept {
}

// Header information
int32_t offsetBytes = calcOccupiedBytes(cord_.size());
auto offsetBytes = calcOccupiedBytes(cord_.size());
char header = offsetBytes - 1;

int32_t ver = schema_->getVersion();
SchemaVer ver = schema_->getVersion();
if (ver > 0) {
int32_t verBytes = calcOccupiedBytes(ver);
auto verBytes = calcOccupiedBytes(ver);
header |= verBytes << 5;
encoded.append(&header, 1);
// Schema version is stored in Little Endian
Expand All @@ -84,8 +84,8 @@ Schema RowWriter::moveSchema() {
}


int32_t RowWriter::calcOccupiedBytes(uint64_t v) const noexcept {
int32_t bytes = 0;
int64_t RowWriter::calcOccupiedBytes(uint64_t v) const noexcept {
int64_t bytes = 0;
do {
bytes++;
v >>= 8;
Expand Down
2 changes: 1 addition & 1 deletion src/dataman/RowWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class RowWriter {
writeInt(T v);

// Calculate the number of bytes occupied (ignore the leading 0s)
int32_t calcOccupiedBytes(uint64_t v) const noexcept;
int64_t calcOccupiedBytes(uint64_t v) const noexcept;
};

} // namespace nebula
Expand Down
2 changes: 1 addition & 1 deletion src/dataman/SchemaWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace nebula {

class SchemaWriter : public ResultSchemaProvider {
public:
explicit SchemaWriter(int32_t ver = 0) : ResultSchemaProvider(ver) {}
explicit SchemaWriter(SchemaVer ver = 0) : ResultSchemaProvider(ver) {}

// Move the schema out of the writer
cpp2::Schema moveSchema() noexcept;
Expand Down
4 changes: 2 additions & 2 deletions src/interface/meta.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ struct ListTagsResp {
struct ReadTagReq {
1: common.GraphSpaceID space_id,
2: common.TagID tag_id,
3: i64 version,
3: common.SchemaVer version,
}

struct GetTagResp {
Expand Down Expand Up @@ -181,7 +181,7 @@ struct ListEdgesResp {
struct GetEdgeReq {
1: common.GraphSpaceID space_id,
2: common.EdgeType edge_type,
3: i64 version,
3: common.SchemaVer version,
}

struct GetEdgeResp {
Expand Down
2 changes: 1 addition & 1 deletion src/meta/FileBasedSchemaManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ std::shared_ptr<const SchemaProviderIf> FileBasedSchemaManager::readSchema(

if (fname == "__version") {
try {
schema->ver_ = folly::to<int32_t>(type);
schema->ver_ = folly::to<SchemaVer>(type);
if (schema->ver_ < 0) {
LOG(ERROR) << "Invalid schema version: " << schema->ver_;
return std::shared_ptr<SchemaProviderIf>();
Expand Down
2 changes: 1 addition & 1 deletion src/meta/NebulaSchemaProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace nebula {
namespace meta {

int32_t NebulaSchemaProvider::getVersion() const noexcept {
SchemaVer NebulaSchemaProvider::getVersion() const noexcept {
return ver_;
}

Expand Down
4 changes: 2 additions & 2 deletions src/meta/NebulaSchemaProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class NebulaSchemaProvider : public SchemaProviderIf {
};

public:
int32_t getVersion() const noexcept override;
SchemaVer getVersion() const noexcept override;
size_t getNumFields() const noexcept override;

int64_t getFieldIndex(const folly::StringPiece name) const override;
Expand All @@ -57,7 +57,7 @@ class NebulaSchemaProvider : public SchemaProviderIf {
NebulaSchemaProvider() = default;

protected:
int32_t ver_{-1};
SchemaVer ver_{-1};

// fieldname -> index
std::unordered_map<std::string, int64_t> fieldNameIndex_;
Expand Down
2 changes: 1 addition & 1 deletion src/meta/SchemaProviderIf.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class SchemaProviderIf {
public:
virtual ~SchemaProviderIf() = default;

virtual int32_t getVersion() const noexcept = 0;
virtual SchemaVer getVersion() const noexcept = 0;
virtual size_t getNumFields() const noexcept = 0;

virtual int64_t getFieldIndex(const folly::StringPiece name) const = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/meta/client/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ MetaClient::listTagSchemas(GraphSpaceID spaceId) {
req.set_space_id(std::move(spaceId));
return getResponse(std::move(req), [] (auto client, auto request) {
return client->future_listTags(request);
}, [this] (cpp2::ListTagsResp&& resp) -> decltype(auto){
}, [] (cpp2::ListTagsResp&& resp) -> decltype(auto){
return std::move(resp).get_tags();
});
}
Expand All @@ -679,7 +679,7 @@ MetaClient::listEdgeSchemas(GraphSpaceID spaceId) {
req.set_space_id(std::move(spaceId));
return getResponse(std::move(req), [] (auto client, auto request) {
return client->future_listEdges(request);
}, [this] (cpp2::ListEdgesResp&& resp) -> decltype(auto) {
}, [] (cpp2::ListEdgesResp&& resp) -> decltype(auto) {
return std::move(resp).get_edges();
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/meta/test/TestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ class TestUtils {
return ret;
}

static void mockTag(kvstore::KVStore* kv, int32_t tagNum, int64_t version = 0) {
static void mockTag(kvstore::KVStore* kv, int32_t tagNum, SchemaVer version = 0) {
std::vector<nebula::kvstore::KV> tags;
int64_t ver = version;
SchemaVer ver = version;
for (auto t = 0; t < tagNum; t++) {
TagID tagId = t;
nebula::cpp2::Schema srcsch;
Expand Down

0 comments on commit c42f535

Please sign in to comment.