/Users/deen/code/yugabyte-db/src/yb/docdb/expiration.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #include "yb/docdb/expiration.h" |
15 | | |
16 | | #include "yb/server/hybrid_clock.h" |
17 | | |
18 | | #include "yb/util/result.h" |
19 | | |
20 | | namespace yb { |
21 | | namespace docdb { |
22 | | |
23 | 93 | Result<MonoDelta> Expiration::ComputeRelativeTtl(const HybridTime& input_time) { |
24 | 93 | if (input_time < write_ht) |
25 | 0 | return STATUS(Corruption, "Read time earlier than record write time."); |
26 | 93 | if (ttl == Value::kMaxTtl || ttl.IsNegative()) |
27 | 6 | return ttl; |
28 | 87 | MonoDelta elapsed_time = MonoDelta::FromNanoseconds( |
29 | 87 | server::HybridClock::GetPhysicalValueNanos(input_time) - |
30 | 87 | server::HybridClock::GetPhysicalValueNanos(write_ht)); |
31 | | // This way, we keep the default TTL, and all negative TTLs are expired. |
32 | 87 | MonoDelta new_ttl(ttl); |
33 | 87 | return new_ttl -= elapsed_time; |
34 | 87 | } |
35 | | |
36 | 0 | std::string Expiration::ToString() const { |
37 | 0 | return YB_STRUCT_TO_STRING(ttl, write_ht, always_override); |
38 | 0 | } |
39 | | |
40 | | } // namespace docdb |
41 | | } // namespace yb |