Skip to content

Commit

Permalink
Open cache in r/o mode on no space left errors (#1375)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
andrey-kashcheev authored Dec 12, 2022
1 parent 94402c9 commit ccdf6ec
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ olp::cache::DefaultCache::StorageOpenResult ToStorageOpenResult(
case olp::cache::OpenResult::Fail:
return StorageOpenResult::OpenDiskPathFailure;
case olp::cache::OpenResult::Corrupted:
case olp::cache::OpenResult::IOError:
return StorageOpenResult::ProtectedCacheCorrupted;
case olp::cache::OpenResult::Repaired:
case olp::cache::OpenResult::Success:
Expand Down Expand Up @@ -847,12 +848,27 @@ DefaultCache::StorageOpenResult DefaultCacheImpl::SetupProtectedCache() {
"r/o mode, disk_path_protected='%s'",
settings_.disk_path_protected.get().c_str());
open_mode = static_cast<OpenOptions>(open_mode | OpenOptions::ReadOnly);
is_read_only = true;
}
}

auto status = protected_cache_->Open(
settings_.disk_path_protected.get(), settings_.disk_path_protected.get(),
protected_storage_settings, open_mode, false);

if (status == OpenResult::IOError && !is_read_only) {
OLP_SDK_LOG_INFO_F(
kLogTag,
"Failed to open in r/w mode, trying r/o, disk_path_protected='%s'",
settings_.disk_path_protected.get().c_str());

open_mode = static_cast<OpenOptions>(open_mode | OpenOptions::ReadOnly);
status =
protected_cache_->Open(settings_.disk_path_protected.get(),
settings_.disk_path_protected.get(),
protected_storage_settings, open_mode, false);
}

if (status != OpenResult::Success) {
OLP_SDK_LOG_ERROR_F(kLogTag, "Failed to open protected cache %s",
settings_.disk_path_protected.get().c_str());
Expand Down
7 changes: 7 additions & 0 deletions olp-cpp-sdk-core/src/cache/DiskCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ OpenResult DiskCache::Open(const std::string& data_path,

if (status.IsCorruption() || status.IsIOError()) {
if (is_read_only || !repair_if_broken) {
if (status.IsIOError()) {
OLP_SDK_LOG_ERROR_F(
kLogTag, "Open: IO error, cache_path='%s', error='%s'",
versioned_data_path.c_str(), status.ToString().c_str());
return OpenResult::IOError;
}

OLP_SDK_LOG_ERROR_F(
kLogTag, "Open: cache corrupted, cache_path='%s', error='%s'",
versioned_data_path.c_str(), status.ToString().c_str());
Expand Down
2 changes: 2 additions & 0 deletions olp-cpp-sdk-core/src/cache/DiskCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ enum class OpenResult {
Fail,
/// The store was corrupted or store compaction was interrupted.
Corrupted,
/// Opening the store failed due to IO error.
IOError,
/// The store was corrupted and has been repaired. Internal integrity might be
/// broken.
Repaired,
Expand Down

0 comments on commit ccdf6ec

Please sign in to comment.