Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Support TTL for index #382

Merged
merged 7 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/meta/processors/BaseProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,6 @@ class BaseProcessor {
StatusOr<cpp2::Schema>
getLatestTagSchema(GraphSpaceID spaceId, const TagID tagId);

/**
* Check if tag or edge has ttl
*/
bool tagOrEdgeHasTTL(const cpp2::Schema& latestSchema);

/**
* Return the edgeType for name.
*/
Expand Down
10 changes: 0 additions & 10 deletions src/meta/processors/BaseProcessor.inl
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,6 @@ BaseProcessor<RESP>::getLatestEdgeSchema(GraphSpaceID spaceId, const EdgeType ed
}


template <typename RESP>
bool BaseProcessor<RESP>::tagOrEdgeHasTTL(const cpp2::Schema& latestSchema) {
auto schemaProp = latestSchema.get_schema_prop();
if (schemaProp.get_ttl_col() && !schemaProp.get_ttl_col()->empty()) {
return true;
}
return false;
}


template<typename RESP>
StatusOr<IndexID>
BaseProcessor<RESP>::getIndexID(GraphSpaceID spaceId, const std::string& indexName) {
Expand Down
7 changes: 0 additions & 7 deletions src/meta/processors/indexMan/CreateEdgeIndexProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@ void CreateEdgeIndexProcessor::process(const cpp2::CreateEdgeIndexReq& req) {
}

auto latestEdgeSchema = schemaRet.value();
if (tagOrEdgeHasTTL(latestEdgeSchema)) {
LOG(ERROR) << "Edge: " << edgeName << " has ttl, not create index";
handleErrorCode(cpp2::ErrorCode::E_INDEX_WITH_TTL);
onFinished();
return;
}

const auto& schemaCols = latestEdgeSchema.get_columns();
std::vector<cpp2::ColumnDef> columns;
for (auto &field : fields) {
Expand Down
7 changes: 0 additions & 7 deletions src/meta/processors/indexMan/CreateTagIndexProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@ void CreateTagIndexProcessor::process(const cpp2::CreateTagIndexReq& req) {
}

auto latestTagSchema = schemaRet.value();
if (tagOrEdgeHasTTL(latestTagSchema)) {
LOG(ERROR) << "Tag: " << tagName << " has ttl, not create index";
handleErrorCode(cpp2::ErrorCode::E_INDEX_WITH_TTL);
onFinished();
return;
}

const auto& schemaCols = latestTagSchema.get_columns();
std::vector<cpp2::ColumnDef> columns;
for (auto &field : fields) {
Expand Down
25 changes: 21 additions & 4 deletions src/meta/processors/schemaMan/AlterEdgeProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ void AlterEdgeProcessor::process(const cpp2::AlterEdgeReq& req) {
}
}

auto& alterSchemaProp = req.get_schema_prop();
if (existIndex) {
int64_t duration = 0;
if (alterSchemaProp.get_ttl_duration()) {
duration = *alterSchemaProp.get_ttl_duration();
}
std::string col;
if (alterSchemaProp.get_ttl_col()) {
col = *alterSchemaProp.get_ttl_col();
}
if (!col.empty() && duration > 0) {
LOG(ERROR) << "Alter edge error, index and ttl conflict";
handleErrorCode(cpp2::ErrorCode::E_UNSUPPORTED);
onFinished();
return;
}
}

for (auto& edgeItem : edgeItems) {
auto &cols = edgeItem.get_schema().get_columns();
for (auto& col : cols) {
Expand All @@ -82,18 +100,17 @@ void AlterEdgeProcessor::process(const cpp2::AlterEdgeReq& req) {
onFinished();
return;
}

// Update schema property if edge not index
auto& alterSchemaProp = req.get_schema_prop();
auto retCode = MetaServiceUtils::alterSchemaProp(columns, prop, alterSchemaProp, existIndex);
if (retCode != cpp2::ErrorCode::SUCCEEDED) {
LOG(ERROR) << "Alter edge property error " << static_cast<int32_t>(retCode);
handleErrorCode(retCode);
onFinished();
return;
}
if (!existIndex) {
schema.set_schema_prop(std::move(prop));
}

schema.set_schema_prop(std::move(prop));
schema.set_columns(std::move(columns));

std::vector<kvstore::KV> data;
Expand Down
24 changes: 20 additions & 4 deletions src/meta/processors/schemaMan/AlterTagProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ void AlterTagProcessor::process(const cpp2::AlterTagReq& req) {
}
}

auto& alterSchemaProp = req.get_schema_prop();

if (existIndex) {
int64_t duration = 0;
if (alterSchemaProp.get_ttl_duration()) {
duration = *alterSchemaProp.get_ttl_duration();
}
std::string col;
if (alterSchemaProp.get_ttl_col()) {
col = *alterSchemaProp.get_ttl_col();
}
if (!col.empty() && duration > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can ttl and index coexist?

Copy link
Contributor Author

@bright-starry-sky bright-starry-sky Apr 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, they can coexist. I saved the timestamp value to index val.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

existIndex means there is an index,
!col.empty() && duration> 0 means there is ttl

Why is there an error here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

existIndex means there is an index,
!col.empty() && duration> 0 means there is ttl

Why is there an error here?

if index exists, not allow to alter TTL properties.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, i know what you mean.
But the prop schema prop is in the schema, not the schema prop in AlterTagReq.

Your current logic is that when alter tag, as long as there is index and ttl, an error will be reported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, i know what you mean.
But the prop schema prop is in the schema, not the schema prop in AlterTagReq.

Your current logic is that when alter tag, as long as there is index and ttl, an error will be reported.

yes,there should be an error thrown here, either alter ttl or alter column (excepted for add column )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean:
here logic is unreasonable.
As long as there are index and ttl, here are not allowed to alter tag

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean:
here logic is unreasonable.
As long as there are index and ttl, here are not allowed to alter tag

good point. 🐂B
artimg

LOG(ERROR) << "Alter tag error, index and ttl conflict";
handleErrorCode(cpp2::ErrorCode::E_UNSUPPORTED);
onFinished();
return;
}
}

for (auto& tagItem : tagItems) {
auto &cols = tagItem.get_schema().get_columns();
for (auto& col : cols) {
Expand All @@ -83,7 +102,6 @@ void AlterTagProcessor::process(const cpp2::AlterTagReq& req) {
}

// Update schema property if tag not index
auto& alterSchemaProp = req.get_schema_prop();
auto retCode = MetaServiceUtils::alterSchemaProp(columns, prop, alterSchemaProp, existIndex);
if (retCode != cpp2::ErrorCode::SUCCEEDED) {
LOG(ERROR) << "Alter tag property error " << static_cast<int32_t>(retCode);
Expand All @@ -92,9 +110,7 @@ void AlterTagProcessor::process(const cpp2::AlterTagReq& req) {
return;
}

if (!existIndex) {
schema.set_schema_prop(std::move(prop));
}
schema.set_schema_prop(std::move(prop));
schema.set_columns(std::move(columns));

std::vector<kvstore::KV> data;
Expand Down
Loading