Skip to content

Commit 8b009b4

Browse files
authored
Correct Protect, Release and RemoveFromCache. (#1034)
Protect, Release and RemoveFromCache are sync and offline methods. If versioned client created with boost::none version and no online calls made yet, version is not initialized. In that case, the methods should fail. Resolves: OLPEDGE-2255 Signed-off-by: Kostiantyn Zvieriev <ext-kostiantyn.zvieriev@here.com>
1 parent c2b2603 commit 8b009b4

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/VersionedLayerClient.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ class DATASERVICE_READ_API VersionedLayerClient final {
351351
*
352352
* @param partition_id The partition ID that should be removed.
353353
*
354+
* @note Before calling the API, specify a layer version. You can set it using
355+
* the constructor or after the first online request.
356+
*
354357
* @return True if partition data is removed successfully; false otherwise.
355358
*/
356359
bool RemoveFromCache(const std::string& partition_id);
@@ -360,6 +363,9 @@ class DATASERVICE_READ_API VersionedLayerClient final {
360363
*
361364
* @param tile The tile key that should be removed.
362365
*
366+
* @note Before calling the API, specify a layer version. You can set it using
367+
* the constructor or after the first online request.
368+
*
363369
* @return True if tile data is removed successfully; false otherwise.
364370
*/
365371
bool RemoveFromCache(const geo::TileKey& tile);
@@ -405,6 +411,9 @@ class DATASERVICE_READ_API VersionedLayerClient final {
405411
* @note Please do not call `Protect` while the `Release` call for the same
406412
* catalog and layer is in progress.
407413
*
414+
* @note Before calling the API, specify a layer version. You can set it using
415+
* the constructor or after the first online request.
416+
*
408417
* @param tiles The list of tile keys to be protected.
409418
*
410419
* @return True if some keys were successfully added to the protected list;
@@ -423,6 +432,9 @@ class DATASERVICE_READ_API VersionedLayerClient final {
423432
* @note Please make sure that `Protect` will not be called for the same
424433
* catalog and layer while the `Release` call is in progress.
425434
*
435+
* @note Before calling the API, specify a layer version. You can set it using
436+
* the constructor or after the first online request.
437+
*
426438
* @param tiles The list of tile keys to be removed from protection.
427439
*
428440
* @return True if some keys were successfully removed from the protected

olp-cpp-sdk-dataservice-read/src/VersionedLayerClientImpl.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,15 @@ bool VersionedLayerClientImpl::RemoveFromCache(
444444
repository::PartitionsCacheRepository partitions_cache_repository(
445445
catalog_, settings_.cache);
446446
boost::optional<model::Partition> partition;
447+
auto version = catalog_version_.load();
448+
if (version == kInvalidVersion) {
449+
OLP_SDK_LOG_WARNING(
450+
kLogTag, "Method RemoveFromCache failed, version is not initialized");
451+
return false;
452+
}
453+
447454
if (!partitions_cache_repository.ClearPartitionMetadata(
448-
catalog_version_.load(), partition_id, layer_id_, partition)) {
455+
version, partition_id, layer_id_, partition)) {
449456
return false;
450457
}
451458

@@ -463,8 +470,15 @@ bool VersionedLayerClientImpl::RemoveFromCache(const geo::TileKey& tile) {
463470
read::QuadTreeIndex cached_tree;
464471
repository::PartitionsCacheRepository partitions_cache_repository(
465472
catalog_, settings_.cache);
466-
if (partitions_cache_repository.FindQuadTree(
467-
layer_id_, catalog_version_.load(), tile, cached_tree)) {
473+
auto version = catalog_version_.load();
474+
if (version == kInvalidVersion) {
475+
OLP_SDK_LOG_WARNING(
476+
kLogTag, "Method RemoveFromCache failed, version is not initialized");
477+
return false;
478+
}
479+
480+
if (partitions_cache_repository.FindQuadTree(layer_id_, version, tile,
481+
cached_tree)) {
468482
auto data = cached_tree.Find(tile, false);
469483
if (!data) {
470484
return true;
@@ -481,8 +495,7 @@ bool VersionedLayerClientImpl::RemoveFromCache(const geo::TileKey& tile) {
481495
}
482496
}
483497
return partitions_cache_repository.ClearQuadTree(
484-
layer_id_, cached_tree.GetRootTile(), kQuadTreeDepth,
485-
catalog_version_.load());
498+
layer_id_, cached_tree.GetRootTile(), kQuadTreeDepth, version);
486499
}
487500
return result;
488501
}
@@ -619,6 +632,11 @@ bool VersionedLayerClientImpl::Protect(const TileKeys& tiles) {
619632
return false;
620633
}
621634
auto version = catalog_version_.load();
635+
if (version == kInvalidVersion) {
636+
OLP_SDK_LOG_WARNING(kLogTag,
637+
"Method Protect failed, version is not initialized");
638+
return false;
639+
}
622640

623641
auto tiles_dependency_resolver =
624642
ProtectDependencyResolver(catalog_, layer_id_, version, settings_);
@@ -636,6 +654,11 @@ bool VersionedLayerClientImpl::Release(const TileKeys& tiles) {
636654
return false;
637655
}
638656
auto version = catalog_version_.load();
657+
if (version == kInvalidVersion) {
658+
OLP_SDK_LOG_WARNING(kLogTag,
659+
"Method Release failed, version is not initialized");
660+
return false;
661+
}
639662

640663
auto tiles_dependency_resolver =
641664
ReleaseDependencyResolver(catalog_, layer_id_, version, settings_);

0 commit comments

Comments
 (0)