Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ttl not work when ttl column has default value #4961

Merged
merged 3 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
9 changes: 7 additions & 2 deletions src/storage/CommonUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@

#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()) {
critical27 marked this conversation as resolved.
Show resolved Hide resolved
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
35 changes: 35 additions & 0 deletions tests/tck/features/ttl/TTL.feature
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,38 @@ Feature: TTLTest
Then the result should be, in any order:
| age |
And drop the used space

@wtf
critical27 marked this conversation as resolved.
Show resolved Hide resolved
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 |