Skip to content

Commit c1ccaf7

Browse files
Update CacheSettings structure.
* Add disk_path_mutable. * Deprecate the disk_path in favor of a new disk_path_mutable. * Update the SDK to use a new disk_path_mutable. * When disk_path_mutable is empty, disk_path is used (backwards compatibility). Resolves: OLPEDGE-1039 Signed-off-by: Mykhailo Kuchma <[email protected]>
1 parent 5b93b8b commit c1ccaf7

File tree

7 files changed

+54
-24
lines changed

7 files changed

+54
-24
lines changed

olp-cpp-sdk-core/include/olp/core/cache/CacheSettings.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include <boost/optional.hpp>
2525

26+
#include <olp/core/porting/deprecated.h>
27+
2628
namespace olp {
2729

2830
namespace cache {
@@ -40,8 +42,15 @@ struct CacheSettings {
4042
/**
4143
* @brief Path to save contents on disk
4244
*/
45+
OLP_SDK_DEPRECATED("Use disk_path_mutable instead. Will be removed 03.2020")
4346
boost::optional<std::string> disk_path = boost::none;
4447

48+
/**
49+
* @brief Path to the mutable (read-write) cache, where SDK will cache and
50+
* lookup the content. User should have write permissions.
51+
*/
52+
boost::optional<std::string> disk_path_mutable = boost::none;
53+
4554
/**
4655
* @brief Set the upper limit of disk space to use for persistent stores in
4756
* bytes. Default is 32 MB. Set it to std::uint64_t(-1) in order to never

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@
1717
* License-Filename: LICENSE
1818
*/
1919

20+
#include "olp/core/porting/warning_disable.h"
21+
22+
PORTING_PUSH_WARNINGS()
23+
PORTING_CLANG_GCC_DISABLE_WARNING("-Wdeprecated-declarations")
24+
// Generated class methods use a deprecated field and generate warning
2025
#include "olp/core/cache/DefaultCache.h"
26+
PORTING_POP_WARNINGS()
27+
2128
#include "DiskCache.h"
2229
#include "InMemoryCache.h"
2330
#include "olp/core/logging/Log.h"
@@ -57,6 +64,16 @@ bool StoreExpiry(const std::string& key, olp::cache::DiskCache& disk_cache,
5764
olp::cache::InMemoryCache::DefaultTimeProvider()()));
5865
}
5966

67+
void ValidateDiskPath(olp::cache::CacheSettings& settings) {
68+
if (!settings.disk_path_mutable) {
69+
PORTING_PUSH_WARNINGS()
70+
PORTING_CLANG_GCC_DISABLE_WARNING("-Wdeprecated-declarations")
71+
PORTING_MSVC_DISABLE_WARNINGS(4996)
72+
settings.disk_path_mutable = settings.disk_path;
73+
PORTING_POP_WARNINGS()
74+
}
75+
}
76+
6077
} // namespace
6178

6279
namespace olp {
@@ -104,7 +121,7 @@ bool DefaultCache::Clear() {
104121
}
105122
if (SetupStorage() != DefaultCache::StorageOpenResult::Success) {
106123
OLP_SDK_LOG_DEBUG_F(kLogTag, "Failed to reopen the diskcache %s",
107-
settings_.disk_path.get().c_str());
124+
settings_.disk_path_mutable.get().c_str());
108125
return false;
109126
}
110127
return true;
@@ -281,7 +298,11 @@ DefaultCache::StorageOpenResult DefaultCache::SetupStorage() {
281298
if (settings_.max_memory_cache_size > 0) {
282299
memory_cache_.reset(new InMemoryCache(settings_.max_memory_cache_size));
283300
}
284-
if (settings_.disk_path) {
301+
302+
// Temporary code for backwards compatibility.
303+
ValidateDiskPath(settings_);
304+
305+
if (settings_.disk_path_mutable) {
285306
StorageSettings storage_settings;
286307
storage_settings.max_disk_storage = settings_.max_disk_storage;
287308
storage_settings.max_chunk_size = settings_.max_chunk_size;
@@ -290,12 +311,12 @@ DefaultCache::StorageOpenResult DefaultCache::SetupStorage() {
290311
storage_settings.max_file_size = settings_.max_file_size;
291312

292313
disk_cache_ = std::make_unique<DiskCache>();
293-
auto status =
294-
disk_cache_->Open(settings_.disk_path.get(), settings_.disk_path.get(),
295-
storage_settings, OpenOptions::Default);
314+
auto status = disk_cache_->Open(settings_.disk_path_mutable.get(),
315+
settings_.disk_path_mutable.get(),
316+
storage_settings, OpenOptions::Default);
296317
if (status == OpenResult::Fail) {
297318
disk_cache_.reset();
298-
settings_.disk_path = boost::none;
319+
settings_.disk_path_mutable = boost::none;
299320
result = OpenDiskPathFailure;
300321
}
301322
}

olp-cpp-sdk-core/tests/cache/DefaultCacheTest.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
TEST(DefaultCacheTest, BasicTest) {
3131
olp::cache::CacheSettings settings;
32-
settings.disk_path = olp::utils::Dir::TempDirectory() + "/unittest";
32+
settings.disk_path_mutable = olp::utils::Dir::TempDirectory() + "/unittest";
3333
olp::cache::DefaultCache cache(settings);
3434
ASSERT_EQ(olp::cache::DefaultCache::Success, cache.Open());
3535
ASSERT_TRUE(cache.Clear());
@@ -129,7 +129,7 @@ TEST(DefaultCacheTest, RemoveWithPrefix) {
129129
TEST(DefaultCacheTest, BasicDiskTest) {
130130
olp::cache::CacheSettings settings;
131131
settings.max_memory_cache_size = 0;
132-
settings.disk_path = olp::utils::Dir::TempDirectory() + "/unittest";
132+
settings.disk_path_mutable = olp::utils::Dir::TempDirectory() + "/unittest";
133133
olp::cache::DefaultCache cache(settings);
134134
ASSERT_EQ(olp::cache::DefaultCache::Success, cache.Open());
135135
ASSERT_TRUE(cache.Clear());
@@ -146,7 +146,7 @@ TEST(DefaultCacheTest, BasicDiskTest) {
146146
TEST(DefaultCacheTest, ExpiredDiskTest) {
147147
olp::cache::CacheSettings settings;
148148
settings.max_memory_cache_size = 0;
149-
settings.disk_path = olp::utils::Dir::TempDirectory() + "/unittest";
149+
settings.disk_path_mutable = olp::utils::Dir::TempDirectory() + "/unittest";
150150
olp::cache::DefaultCache cache(settings);
151151
ASSERT_EQ(olp::cache::DefaultCache::Success, cache.Open());
152152
ASSERT_TRUE(cache.Clear());
@@ -196,7 +196,7 @@ TEST(DefaultCacheTest, ExpiredMemTest) {
196196

197197
TEST(DefaultCacheTest, BadPath) {
198198
olp::cache::CacheSettings settings;
199-
settings.disk_path = std::string("/////this/is/a/bad/path");
199+
settings.disk_path_mutable = std::string("/////this/is/a/bad/path");
200200
olp::cache::DefaultCache cache(settings);
201201
ASSERT_EQ(olp::cache::DefaultCache::OpenDiskPathFailure, cache.Open());
202202

@@ -212,7 +212,7 @@ TEST(DefaultCacheTest, BadPath) {
212212

213213
TEST(DefaultCacheTest, AlreadyInUsePath) {
214214
olp::cache::CacheSettings settings;
215-
settings.disk_path = olp::utils::Dir::TempDirectory() + "/unittest";
215+
settings.disk_path_mutable = olp::utils::Dir::TempDirectory() + "/unittest";
216216
olp::cache::DefaultCache cache(settings);
217217
ASSERT_EQ(olp::cache::DefaultCache::Success, cache.Open());
218218

tests/integration/olp-cpp-sdk-dataservice-read/CatalogClientCacheTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ class CatalogClientCacheTest : public CatalogClientTestBase {
3939
}
4040
case CacheType::DISK: {
4141
settings.max_memory_cache_size = 0;
42-
settings.disk_path =
42+
settings.disk_path_mutable =
4343
olp::utils::Dir::TempDirectory() + kClientTestCacheDir;
44-
ClearCache(settings.disk_path.get());
44+
ClearCache(settings.disk_path_mutable.get());
4545
break;
4646
}
4747
case CacheType::BOTH: {
48-
settings.disk_path =
48+
settings.disk_path_mutable =
4949
olp::utils::Dir::TempDirectory() + kClientTestCacheDir;
50-
ClearCache(settings.disk_path.get());
50+
ClearCache(settings.disk_path_mutable.get());
5151
break;
5252
}
5353
case CacheType::NONE: {

tests/integration/olp-cpp-sdk-dataservice-read/VersionedLayerClientCacheTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ class VersionedLayerClientCacheTest : public CatalogClientTestBase {
4343
}
4444
case CacheType::DISK: {
4545
settings.max_memory_cache_size = 0;
46-
settings.disk_path =
46+
settings.disk_path_mutable =
4747
olp::utils::Dir::TempDirectory() + kClientTestCacheDir;
48-
ClearCache(settings.disk_path.get());
48+
ClearCache(settings.disk_path_mutable.get());
4949
break;
5050
}
5151
case CacheType::BOTH: {
52-
settings.disk_path =
52+
settings.disk_path_mutable =
5353
olp::utils::Dir::TempDirectory() + kClientTestCacheDir;
54-
ClearCache(settings.disk_path.get());
54+
ClearCache(settings.disk_path_mutable.get());
5555
break;
5656
}
5757
case CacheType::NONE: {

tests/integration/olp-cpp-sdk-dataservice-read/VolatileLayerClientCacheTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ class VolatileLayerClientCacheTest : public CatalogClientTestBase {
4343
}
4444
case CacheType::DISK: {
4545
settings.max_memory_cache_size = 0;
46-
settings.disk_path =
46+
settings.disk_path_mutable =
4747
olp::utils::Dir::TempDirectory() + kClientTestCacheDir;
48-
ClearCache(settings.disk_path.get());
48+
ClearCache(settings.disk_path_mutable.get());
4949
break;
5050
}
5151
case CacheType::BOTH: {
52-
settings.disk_path =
52+
settings.disk_path_mutable =
5353
olp::utils::Dir::TempDirectory() + kClientTestCacheDir;
54-
ClearCache(settings.disk_path.get());
54+
ClearCache(settings.disk_path_mutable.get());
5555
break;
5656
}
5757
case CacheType::NONE: {

tests/performance/MemoryTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ TestConfiguration ShortRunningTestWithDiskCache() {
415415
if (location.empty()) {
416416
location = utils::Dir::TempDirectory() + "/performance_test";
417417
}
418-
settings.disk_path = location;
418+
settings.disk_path_mutable = location;
419419

420420
TestConfiguration configuration;
421421
configuration.configuration_name = "short_test_disk_cache";

0 commit comments

Comments
 (0)