Skip to content

Commit ccdf6ec

Browse files
Open cache in r/o mode on no space left errors (#1375)
Since protected cache could be used as a static cache it is expected to be able to use it even when there is no available space on device. But when protected cache is being open in R/W mode levelDb may try to create some files and this failure would be treated later as a corrupted cache. Instead, on `no space left` errors we will try to open the cache again but in read-only mode to enforce static behavior. Relates-To: OLPSUP-21193 Signed-off-by: Andrey Kashcheev <ext-andrey.kashcheev@here.com>
1 parent 94402c9 commit ccdf6ec

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ olp::cache::DefaultCache::StorageOpenResult ToStorageOpenResult(
128128
case olp::cache::OpenResult::Fail:
129129
return StorageOpenResult::OpenDiskPathFailure;
130130
case olp::cache::OpenResult::Corrupted:
131+
case olp::cache::OpenResult::IOError:
131132
return StorageOpenResult::ProtectedCacheCorrupted;
132133
case olp::cache::OpenResult::Repaired:
133134
case olp::cache::OpenResult::Success:
@@ -847,12 +848,27 @@ DefaultCache::StorageOpenResult DefaultCacheImpl::SetupProtectedCache() {
847848
"r/o mode, disk_path_protected='%s'",
848849
settings_.disk_path_protected.get().c_str());
849850
open_mode = static_cast<OpenOptions>(open_mode | OpenOptions::ReadOnly);
851+
is_read_only = true;
850852
}
851853
}
852854

853855
auto status = protected_cache_->Open(
854856
settings_.disk_path_protected.get(), settings_.disk_path_protected.get(),
855857
protected_storage_settings, open_mode, false);
858+
859+
if (status == OpenResult::IOError && !is_read_only) {
860+
OLP_SDK_LOG_INFO_F(
861+
kLogTag,
862+
"Failed to open in r/w mode, trying r/o, disk_path_protected='%s'",
863+
settings_.disk_path_protected.get().c_str());
864+
865+
open_mode = static_cast<OpenOptions>(open_mode | OpenOptions::ReadOnly);
866+
status =
867+
protected_cache_->Open(settings_.disk_path_protected.get(),
868+
settings_.disk_path_protected.get(),
869+
protected_storage_settings, open_mode, false);
870+
}
871+
856872
if (status != OpenResult::Success) {
857873
OLP_SDK_LOG_ERROR_F(kLogTag, "Failed to open protected cache %s",
858874
settings_.disk_path_protected.get().c_str());

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,13 @@ OpenResult DiskCache::Open(const std::string& data_path,
247247

248248
if (status.IsCorruption() || status.IsIOError()) {
249249
if (is_read_only || !repair_if_broken) {
250+
if (status.IsIOError()) {
251+
OLP_SDK_LOG_ERROR_F(
252+
kLogTag, "Open: IO error, cache_path='%s', error='%s'",
253+
versioned_data_path.c_str(), status.ToString().c_str());
254+
return OpenResult::IOError;
255+
}
256+
250257
OLP_SDK_LOG_ERROR_F(
251258
kLogTag, "Open: cache corrupted, cache_path='%s', error='%s'",
252259
versioned_data_path.c_str(), status.ToString().c_str());

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ enum class OpenResult {
5757
Fail,
5858
/// The store was corrupted or store compaction was interrupted.
5959
Corrupted,
60+
/// Opening the store failed due to IO error.
61+
IOError,
6062
/// The store was corrupted and has been repaired. Internal integrity might be
6163
/// broken.
6264
Repaired,

0 commit comments

Comments
 (0)