Skip to content

Commit 12f6d98

Browse files
taku910hiroyuki-komatsu
authored andcommitted
Remove the functionality to erase data updated 62 days before.
This restriction is no longer required. PiperOrigin-RevId: 802837210
1 parent 131f5a6 commit 12f6d98

File tree

5 files changed

+2
-119
lines changed

5 files changed

+2
-119
lines changed

src/rewriter/user_boundary_history_rewriter.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,7 @@ UserBoundaryHistoryRewriter::CheckResizeSegmentsRequest(
271271
return std::nullopt;
272272
}
273273

274-
bool UserBoundaryHistoryRewriter::Sync() {
275-
storage_.DeleteElementsUntouchedFor62Days();
276-
return true;
277-
}
274+
bool UserBoundaryHistoryRewriter::Sync() { return true; }
278275

279276
bool UserBoundaryHistoryRewriter::Reload() {
280277
const std::string filename = ConfigFileStream::GetFileName(kFileName);

src/rewriter/user_segment_history_rewriter.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -803,12 +803,7 @@ void UserSegmentHistoryRewriter::Finish(const ConversionRequest& request,
803803
revert_cache_.Insert(segments.revert_id(), revert_entries);
804804
}
805805

806-
bool UserSegmentHistoryRewriter::Sync() {
807-
if (storage_) {
808-
storage_->DeleteElementsUntouchedFor62Days();
809-
}
810-
return true;
811-
}
806+
bool UserSegmentHistoryRewriter::Sync() { return true; }
812807

813808
bool UserSegmentHistoryRewriter::Reload() {
814809
const std::string filename = ConfigFileStream::GetFileName(kFileName);

src/storage/lru_storage.cc

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ constexpr size_t kMaxValueSize = 1024; // 1024 byte
7272
// * 4 bytes for fingerprint seed
7373
constexpr size_t kFileHeaderSize = 12;
7474

75-
constexpr uint64_t k62DaysInSec = 62 * 24 * 60 * 60;
76-
7775
uint64_t GetFP(const char* ptr) { return LoadUnaligned<uint64_t>(ptr); }
7876

7977
uint32_t GetTimeStamp(const char* ptr) {
@@ -97,11 +95,6 @@ void Update(char* ptr, uint64_t fp, const char* value, size_t value_size) {
9795
std::copy_n(value, value_size, ptr);
9896
}
9997

100-
bool IsOlderThan62Days(uint64_t timestamp) {
101-
const uint64_t now = absl::ToUnixSeconds(Clock::GetAbslTime());
102-
return (timestamp + k62DaysInSec < now);
103-
}
104-
10598
class CompareByTimeStamp {
10699
public:
107100
bool operator()(const char* a, const char* b) const {
@@ -382,16 +375,10 @@ bool LruStorage::Open(char* ptr, size_t ptr_size) {
382375
next_item_ = (next != nullptr) ? next : end_;
383376
DCHECK_LE(next_item_, end_);
384377

385-
// At the time file is opened, perform clean up.
386-
DeleteElementsUntouchedFor62Days();
387-
388378
return true;
389379
}
390380

391381
void LruStorage::Close() {
392-
// Perform clean up before closing the file.
393-
DeleteElementsUntouchedFor62Days();
394-
395382
filename_.clear();
396383
mmap_.Close();
397384
lru_list_.clear();
@@ -406,9 +393,6 @@ const char* absl_nullable LruStorage::Lookup(const absl::string_view key,
406393
return nullptr;
407394
}
408395
const uint32_t timestamp = GetTimeStamp(*it->second);
409-
if (IsOlderThan62Days(timestamp)) {
410-
return nullptr;
411-
}
412396
*last_access_time = timestamp;
413397
return GetValue(*it->second);
414398
}
@@ -419,10 +403,6 @@ void LruStorage::GetAllValues(std::vector<std::string>* values) const {
419403
// Iterate data from the most recently used element to the least recently used
420404
// element.
421405
for (const char* ptr : lru_list_) {
422-
const uint32_t timestamp = GetTimeStamp(ptr);
423-
if (IsOlderThan62Days(timestamp)) {
424-
break;
425-
}
426406
// Default constructor of string is not applicable
427407
// because value's size() must return value_size_.
428408
DCHECK(ptr);
@@ -436,10 +416,6 @@ bool LruStorage::Touch(const absl::string_view key) {
436416
if (it == lru_map_.end()) {
437417
return false;
438418
}
439-
const uint32_t timestamp = GetTimeStamp(*it->second);
440-
if (IsOlderThan62Days(timestamp)) {
441-
return false;
442-
}
443419
Update(*it->second);
444420
// Move the node pointed to by it->second to the front.
445421
lru_list_.splice(lru_list_.begin(), lru_list_, it->second);
@@ -566,13 +542,6 @@ int LruStorage::DeleteElementsBefore(uint32_t timestamp) {
566542
return num_deleted;
567543
}
568544

569-
int LruStorage::DeleteElementsUntouchedFor62Days() {
570-
const uint64_t now = absl::ToUnixSeconds(Clock::GetAbslTime());
571-
const uint32_t timestamp =
572-
static_cast<uint32_t>((now > k62DaysInSec) ? now - k62DaysInSec : 0);
573-
return DeleteElementsBefore(timestamp);
574-
}
575-
576545
void LruStorage::Write(size_t i, uint64_t fp, const absl::string_view value,
577546
uint32_t last_access_time) {
578547
DCHECK_LT(i, size_);

src/storage/lru_storage.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ class LruStorage {
107107
// elements.
108108
int DeleteElementsBefore(uint32_t timestamp);
109109

110-
// Deletes all the elements that are not accessed for 62 days.
111-
// Returns the number of deleted elements.
112-
int DeleteElementsUntouchedFor62Days();
113-
114110
// Returns the byte length of each item, which is the user specified value
115111
// size + 12 bytes. Here, 12 bytes is used for fingerprint (8 bytes) and
116112
// timestamp (4 bytes).

src/storage/lru_storage_test.cc

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -483,79 +483,5 @@ TEST_F(LruStorageTest, DeleteElementsBefore) {
483483
EXPECT_EQ(values, kExpectedAfterDelete);
484484
}
485485

486-
TEST_F(LruStorageTest, DeleteElementsUntouchedFor62Days) {
487-
ScopedClockMock clock(absl::FromUnixSeconds(1));
488-
489-
constexpr size_t kValueSize = 4;
490-
constexpr size_t kNumElements = 4;
491-
LruStorage storage;
492-
TempFile file(testing::MakeTempFileOrDie());
493-
ASSERT_TRUE(storage.OpenOrCreate(file.path().c_str(), kValueSize,
494-
kNumElements, kSeed));
495-
496-
// Auto advance clock after opening the file; otherwise OpenOrCreate()
497-
// advances the clock.
498-
clock->Advance(absl::Seconds(1));
499-
500-
storage.Insert("1111", "aaaa");
501-
storage.Insert("2222", "bbbb");
502-
503-
// Advance clock for 63 days.
504-
clock->Advance(absl::Hours(63 * 24));
505-
506-
// Insert newer elements.
507-
storage.Insert("3333", "cccc");
508-
storage.Insert("4444", "dddd");
509-
510-
EXPECT_EQ(storage.DeleteElementsUntouchedFor62Days(), 2);
511-
512-
std::vector<std::string> values;
513-
storage.GetAllValues(&values);
514-
const std::vector<std::string> kExpectedAfterDelete = {
515-
"dddd",
516-
"cccc",
517-
};
518-
EXPECT_EQ(values, kExpectedAfterDelete);
519-
}
520-
521-
TEST_F(LruStorageTest, OldDataAreNotLookedUp) {
522-
ScopedClockMock clock(absl::FromUnixSeconds(1));
523-
524-
constexpr size_t kValueSize = 4;
525-
constexpr size_t kNumElements = 4;
526-
LruStorage storage;
527-
TempFile file(testing::MakeTempFileOrDie());
528-
ASSERT_TRUE(storage.OpenOrCreate(file.path().c_str(), kValueSize,
529-
kNumElements, kSeed));
530-
531-
EXPECT_TRUE(storage.Insert("1111", "aaaa"));
532-
EXPECT_TRUE(storage.Insert("2222", "bbbb"));
533-
534-
// The two elements can be looked up as they are still not 62-day old.
535-
EXPECT_EQ(storage.LookupAsString("1111"), "aaaa");
536-
EXPECT_EQ(storage.LookupAsString("2222"), "bbbb");
537-
EXPECT_TRUE(storage.Touch("1111"));
538-
EXPECT_TRUE(storage.Touch("2222"));
539-
540-
// Advance clock for 63 days.
541-
clock->Advance(absl::Hours(63 * 24));
542-
543-
// Insert new elements.
544-
EXPECT_TRUE(storage.Insert("3333", "cccc"));
545-
EXPECT_TRUE(storage.Insert("4444", "dddd"));
546-
547-
// The old two cannot be looked up.
548-
EXPECT_TRUE(storage.Lookup("1111") == nullptr);
549-
EXPECT_TRUE(storage.Lookup("2222") == nullptr);
550-
EXPECT_FALSE(storage.Touch("1111"));
551-
EXPECT_FALSE(storage.Touch("2222"));
552-
553-
// But the new ones are accessible.
554-
EXPECT_EQ(storage.LookupAsString("3333"), "cccc");
555-
EXPECT_EQ(storage.LookupAsString("4444"), "dddd");
556-
EXPECT_TRUE(storage.Touch("3333"));
557-
EXPECT_TRUE(storage.Touch("4444"));
558-
}
559-
560486
} // namespace storage
561487
} // namespace mozc

0 commit comments

Comments
 (0)