Skip to content

Commit c30ea4c

Browse files
committed
fix:ttl
1 parent 651dae3 commit c30ea4c

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

src/storage/src/base_meta_value_format.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,12 @@ class ParsedBaseMetaValue : public ParsedInternalValue {
8080
uint64_t etime = DecodeFixed64(internal_value_str->data() + offset);
8181

8282
ctime_ = (ctime & ~(1ULL << 63));
83-
// if ctime_==ctime, means ctime_ storaged in seconds
84-
if (ctime_ == ctime) {
83+
if ((ctime & (1ULL << 63)) == 0) {
8584
ctime_ *= 1000;
8685
}
86+
8787
etime_ = (etime & ~(1ULL << 63));
88-
// if etime_==etime, means etime_ storaged in seconds
89-
if (etime == etime_) {
88+
if ((etime & (1ULL << 63)) == 0) {
9089
etime_ *= 1000;
9190
}
9291
}
@@ -100,7 +99,7 @@ class ParsedBaseMetaValue : public ParsedInternalValue {
10099
type_ = static_cast<DataType>(static_cast<uint8_t>(internal_value_slice[0]));
101100
offset += kTypeLength;
102101
user_value_ = Slice(internal_value_slice.data() + offset,
103-
internal_value_slice.size() - kBaseMetaValueSuffixLength - offset);
102+
internal_value_slice.size() - kBaseMetaValueSuffixLength - offset);
104103
offset += user_value_.size();
105104
version_ = DecodeFixed64(internal_value_slice.data() + offset);
106105
offset += sizeof(uint64_t);
@@ -110,14 +109,17 @@ class ParsedBaseMetaValue : public ParsedInternalValue {
110109
offset += sizeof(ctime_);
111110
uint64_t etime = DecodeFixed64(internal_value_slice.data() + offset);
112111

112+
// 修复时间戳解析问题:只有当时间戳没有毫秒标志时才乘以 1000
113+
// 毫秒时间戳的最高位是 1,秒时间戳的最高位是 0
113114
ctime_ = (ctime & ~(1ULL << 63));
114-
// if ctime_!=ctime, means ctime_ storaged in seconds
115-
if (ctime_ == ctime) {
115+
if ((ctime & (1ULL << 63)) == 0) {
116+
// 秒时间戳,转换为毫秒
116117
ctime_ *= 1000;
117118
}
119+
118120
etime_ = (etime & ~(1ULL << 63));
119-
// if etime_!=etime, means etime_ storaged in seconds
120-
if (etime == etime_) {
121+
if ((etime & (1ULL << 63)) == 0) {
122+
// 秒时间戳,转换为毫秒
121123
etime_ *= 1000;
122124
}
123125
}

src/storage/src/strings_value_format.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,12 @@ class ParsedStringsValue : public ParsedInternalValue {
8787
uint64_t etime = DecodeFixed64(internal_value_str->data() + offset);
8888

8989
ctime_ = (ctime & ~(1ULL << 63));
90-
// if ctime_==ctime, means ctime_ storaged in seconds
91-
if (ctime_ == ctime) {
90+
if ((ctime & (1ULL << 63)) == 0) {
9291
ctime_ *= 1000;
9392
}
93+
9494
etime_ = (etime & ~(1ULL << 63));
95-
// if etime_==etime, means etime_ storaged in seconds
96-
if (etime == etime_) {
95+
if ((etime & (1ULL << 63)) == 0) {
9796
etime_ *= 1000;
9897
}
9998
}
@@ -113,14 +112,17 @@ class ParsedStringsValue : public ParsedInternalValue {
113112
offset += kTimestampLength;
114113
uint64_t etime = DecodeFixed64(internal_value_slice.data() + offset);
115114

115+
// 修复时间戳解析问题:只有当时间戳没有毫秒标志时才乘以 1000
116+
// 毫秒时间戳的最高位是 1,秒时间戳的最高位是 0
116117
ctime_ = (ctime & ~(1ULL << 63));
117-
// if ctime_==ctime, means ctime_ storaged in seconds
118-
if (ctime_ == ctime) {
118+
if ((ctime & (1ULL << 63)) == 0) {
119+
// 秒时间戳,转换为毫秒
119120
ctime_ *= 1000;
120121
}
122+
121123
etime_ = (etime & ~(1ULL << 63));
122-
// if etime_==etime, means etime_ storaged in seconds
123-
if (etime == etime_) {
124+
if ((etime & (1ULL << 63)) == 0) {
125+
// 秒时间戳,转换为毫秒
124126
etime_ *= 1000;
125127
}
126128
}

0 commit comments

Comments
 (0)