forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommonUtils.cpp
53 lines (46 loc) · 1.5 KB
/
CommonUtils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* Copyright (c) 2020 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License,
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/
#include "base/Base.h"
#include "storage/CommonUtils.h"
namespace nebula {
namespace storage {
bool checkDataExpiredForTTL(const meta::SchemaProviderIf* schema,
RowReader* reader,
const std::string& ttlCol,
int64_t ttlDuration) {
auto now = time::WallClock::fastNowInSec();
const auto& ftype = schema->getFieldType(ttlCol);
int64_t v = 0;
switch (ftype.type) {
case nebula::cpp2::SupportedType::TIMESTAMP:
case nebula::cpp2::SupportedType::INT: {
auto ret = reader->getInt<int64_t>(ttlCol, v);
if (ret != ResultType::SUCCEEDED) {
// Reading wrong data should not be deleted
return false;
}
break;
}
case nebula::cpp2::SupportedType::VID: {
auto ret = reader->getVid(ttlCol, v);
if (ret != ResultType::SUCCEEDED) {
// Reading wrong data should not be deleted
return false;
}
break;
}
default: {
VLOG(1) << "Unsupport TTL column type";
return false;
}
}
if (now > (v + ttlDuration)) {
return true;
}
return false;
}
} // namespace storage
} // namespace nebula