Skip to content

Commit 525a0ae

Browse files
Limit number of compactions (#1380)
Run compaction for a limited number of attempts since leveldb does not signal in any way that it failed to compact, and we may try to compact indefinitely. Relates-To: OLPSUP-22147 Signed-off-by: Andrey Kashcheev <ext-andrey.kashcheev@here.com>
1 parent e59acd9 commit 525a0ae

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

olp-cpp-sdk-core/src/cache/DiskCache.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 HERE Europe B.V.
2+
* Copyright (C) 2019-2023 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -178,9 +178,12 @@ void DiskCache::Compact() {
178178
if (database_ && !compacting_.exchange(true)) {
179179
OLP_SDK_LOG_INFO(kLogTag, "Compact: Compacting database started");
180180

181+
const auto kMaxCompactionAttempts = 3u;
182+
auto current_attempt = 0u;
181183
do {
182184
database_->CompactRange(nullptr, nullptr);
183-
} while (!CheckCompactionFinished(*database_));
185+
} while (++current_attempt < kMaxCompactionAttempts &&
186+
!CheckCompactionFinished(*database_));
184187

185188
compacting_ = false;
186189

0 commit comments

Comments
 (0)