Skip to content

Commit

Permalink
fix ttl not work when ttl column has default value (#4961)
Browse files Browse the repository at this point in the history
  • Loading branch information
critical27 authored Dec 1, 2022
1 parent 7083d72 commit 417907f
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/clients/meta/MetaClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,16 @@ class MetaClient : public BaseMetaClient {
StatusOr<std::vector<std::pair<PartitionID, cpp2::ListenerType>>>
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<ListenersMap> getListenersByHostFromCache(const HostAddr& host);

// Get listener address of given (spaceId + partId + type)
StatusOr<HostAddr> getListenerHostsBySpacePartType(GraphSpaceID spaceId,
PartitionID partId,
cpp2::ListenerType type);

// Get all listener type + address of given (spaceId + partId)
StatusOr<std::vector<RemoteListenerInfo>> getListenerHostTypeBySpacePartType(GraphSpaceID spaceId,
PartitionID partId);

Expand Down
10 changes: 8 additions & 2 deletions src/storage/CommonUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@

#include "storage/CommonUtils.h"

#include "storage/exec/QueryUtils.h"

namespace nebula {
namespace storage {

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,
Expand Down
9 changes: 9 additions & 0 deletions src/storage/CommonUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/storage/exec/QueryUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -119,7 +120,7 @@ class QueryUtils final {
*/
static StatusOr<nebula::Value> 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()));
Expand Down
34 changes: 34 additions & 0 deletions tests/tck/features/ttl/TTL.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

0 comments on commit 417907f

Please sign in to comment.