From 417907f11aa297bb19d33b342d3edbfd0c9d1b8f Mon Sep 17 00:00:00 2001 From: Doodle <13706157+critical27@users.noreply.github.com> Date: Thu, 1 Dec 2022 09:33:19 +0800 Subject: [PATCH] fix ttl not work when ttl column has default value (#4961) --- src/clients/meta/MetaClient.h | 4 ++++ src/storage/CommonUtils.cpp | 10 +++++++-- src/storage/CommonUtils.h | 9 ++++++++ src/storage/exec/QueryUtils.h | 3 ++- tests/tck/features/ttl/TTL.feature | 34 ++++++++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/clients/meta/MetaClient.h b/src/clients/meta/MetaClient.h index 2278d0db262..013c9d919d1 100644 --- a/src/clients/meta/MetaClient.h +++ b/src/clients/meta/MetaClient.h @@ -442,12 +442,16 @@ class MetaClient : public BaseMetaClient { StatusOr>> getListenersBySpaceHostFromCache(GraphSpaceID spaceId, const HostAddr& host); + // Given host, get the all peers info. This function is used for listener to start up related + // listener part StatusOr getListenersByHostFromCache(const HostAddr& host); + // Get listener address of given (spaceId + partId + type) StatusOr getListenerHostsBySpacePartType(GraphSpaceID spaceId, PartitionID partId, cpp2::ListenerType type); + // Get all listener type + address of given (spaceId + partId) StatusOr> getListenerHostTypeBySpacePartType(GraphSpaceID spaceId, PartitionID partId); diff --git a/src/storage/CommonUtils.cpp b/src/storage/CommonUtils.cpp index f1693b8e5f9..f1d0e6e52bd 100644 --- a/src/storage/CommonUtils.cpp +++ b/src/storage/CommonUtils.cpp @@ -5,6 +5,8 @@ #include "storage/CommonUtils.h" +#include "storage/exec/QueryUtils.h" + namespace nebula { namespace storage { @@ -12,8 +14,12 @@ bool CommonUtils::checkDataExpiredForTTL(const meta::SchemaProviderIf* schema, RowReader* reader, const std::string& ttlCol, int64_t ttlDuration) { - auto v = reader->getValueByName(ttlCol); - return checkDataExpiredForTTL(schema, v, ttlCol, ttlDuration); + auto v = QueryUtils::readValue(reader, ttlCol, schema); + if (!v.ok()) { + VLOG(3) << "failed to read ttl property"; + return false; + } + return checkDataExpiredForTTL(schema, v.value(), ttlCol, ttlDuration); } bool CommonUtils::checkDataExpiredForTTL(const meta::SchemaProviderIf* schema, diff --git a/src/storage/CommonUtils.h b/src/storage/CommonUtils.h index 0cab8f44c67..af23b3ee2af 100644 --- a/src/storage/CommonUtils.h +++ b/src/storage/CommonUtils.h @@ -251,6 +251,15 @@ struct RuntimeContext { class CommonUtils final { public: + /** + * @brief check whether data is expired by comparing ttl property and current time + * + * @param schema **Latest** schema + * @param reader RowReader of current value + * @param ttlCol Ttl property name + * @param ttlDuration Ttl property duration + * @return Whether data is expired + */ static bool checkDataExpiredForTTL(const meta::SchemaProviderIf* schema, RowReader* reader, const std::string& ttlCol, diff --git a/src/storage/exec/QueryUtils.h b/src/storage/exec/QueryUtils.h index 1fe1103cf17..561f538a764 100644 --- a/src/storage/exec/QueryUtils.h +++ b/src/storage/exec/QueryUtils.h @@ -9,6 +9,7 @@ #include "common/base/Base.h" #include "common/expression/Expression.h" #include "common/utils/DefaultValueContext.h" +#include "common/utils/NebulaKeyUtils.h" #include "storage/CommonUtils.h" #include "storage/context/StorageExpressionContext.h" #include "storage/query/QueryBaseProcessor.h" @@ -119,7 +120,7 @@ class QueryUtils final { */ static StatusOr readValue(RowReader* reader, const std::string& propName, - const meta::NebulaSchemaProvider* schema) { + const meta::SchemaProviderIf* schema) { auto field = schema->field(propName); if (!field) { return Status::Error(folly::stringPrintf("Fail to read prop %s ", propName.c_str())); diff --git a/tests/tck/features/ttl/TTL.feature b/tests/tck/features/ttl/TTL.feature index 36e4ae3d022..2aca8f1c872 100644 --- a/tests/tck/features/ttl/TTL.feature +++ b/tests/tck/features/ttl/TTL.feature @@ -490,3 +490,37 @@ Feature: TTLTest Then the result should be, in any order: | age | And drop the used space + + Scenario: TTLTest ttl column has default + Given having executed: + """ + CREATE TAG t1(name string, age int) + """ + And wait 3 seconds + When executing query: + """ + INSERT VERTEX t1(name, age) VALUES "1":("tom", 18) + """ + Then the execution should be successful + When executing query: + """ + ALTER TAG t1 ADD(n int default 1669726461) + """ + Then the execution should be successful + When executing query: + """ + ALTER TAG t1 TTL_DURATION = 30, TTL_COL = "n"; + """ + Then the execution should be successful + And wait 3 seconds + When executing query: + """ + INSERT VERTEX t1(name, age) VALUES "2":("jerry", 18) + """ + Then the execution should be successful + When executing query: + """ + match (v) return v limit 10 + """ + Then the result should be, in any order: + | v |