Skip to content

Commit c2b2603

Browse files
Extended IsCached API to support aggregated tiles (#1030)
This gives functionality to check if the aggregated data is available. Change the IsCached behavior when the version is not set. Resolves: OLPSUP-11431 Signed-off-by: Mykhailo Kuchma <ext-mykhailo.kuchma@here.com>
1 parent 157464e commit c2b2603

File tree

5 files changed

+101
-58
lines changed

5 files changed

+101
-58
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@ class DATASERVICE_READ_API VersionedLayerClient final {
369369
*
370370
* @param partition_id The partition ID.
371371
*
372+
* @note Before calling the API, specify a layer version. You can set it using
373+
* the constructor or after the first online request.
374+
*
372375
* @return True if the partition data is cached; false otherwise.
373376
*/
374377
bool IsCached(const std::string& partition_id) const;
@@ -377,10 +380,15 @@ class DATASERVICE_READ_API VersionedLayerClient final {
377380
* @brief Checks whether the tile is cached.
378381
*
379382
* @param tile The tile key.
383+
* @param aggregated The aggregated flag, used to specify whether the tile is
384+
* aggregated or not.
385+
*
386+
* @note Before calling the API, specify a layer version. You can set it using
387+
* the constructor or after the first online request.
380388
*
381389
* @return True if the tile data is cached; false otherwise.
382390
*/
383-
bool IsCached(const geo::TileKey& tile) const;
391+
bool IsCached(const geo::TileKey& tile, bool aggregated = false) const;
384392

385393
/**
386394
* @brief Protects tile keys from eviction.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ bool VersionedLayerClient::IsCached(const std::string& partition_id) const {
112112
return impl_->IsCached(partition_id);
113113
}
114114

115-
bool VersionedLayerClient::IsCached(const geo::TileKey& tile) const {
116-
return impl_->IsCached(tile);
115+
bool VersionedLayerClient::IsCached(const geo::TileKey& tile,
116+
bool aggregated) const {
117+
return impl_->IsCached(tile, aggregated);
117118
}
118119

119120
bool VersionedLayerClient::Protect(const TileKeys& tiles) {

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

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -489,33 +489,48 @@ bool VersionedLayerClientImpl::RemoveFromCache(const geo::TileKey& tile) {
489489
return true;
490490
}
491491

492-
bool VersionedLayerClientImpl::IsCached(const std::string& partition_id) const {
493-
repository::PartitionsCacheRepository partitions_cache_repository(
494-
catalog_, settings_.cache);
492+
bool VersionedLayerClientImpl::IsCached(const std::string& partition_id) {
493+
auto version = catalog_version_.load();
494+
if (version == kInvalidVersion) {
495+
OLP_SDK_LOG_WARNING(kLogTag,
496+
"Method IsCached failed, version is not initialized");
497+
return false;
498+
}
499+
500+
auto cache = settings_.cache;
501+
502+
repository::PartitionsCacheRepository partitions_repo(catalog_, cache);
503+
495504
std::string handle;
496-
if (partitions_cache_repository.GetPartitionHandle(
497-
catalog_version_.load(), partition_id, layer_id_, handle)) {
498-
repository::DataCacheRepository data_cache_repository(catalog_,
499-
settings_.cache);
500-
return data_cache_repository.IsCached(layer_id_, handle);
505+
if (partitions_repo.GetPartitionHandle(version, partition_id, layer_id_,
506+
handle)) {
507+
repository::DataCacheRepository data_repo(catalog_, cache);
508+
return data_repo.IsCached(layer_id_, handle);
501509
}
502510
return false;
503511
}
504512

505-
bool VersionedLayerClientImpl::IsCached(const geo::TileKey& tile) const {
513+
bool VersionedLayerClientImpl::IsCached(const geo::TileKey& tile,
514+
bool aggregated) {
515+
auto version = catalog_version_.load();
516+
if (version == kInvalidVersion) {
517+
OLP_SDK_LOG_WARNING(kLogTag,
518+
"Method IsCached failed, version is not initialized");
519+
return false;
520+
}
521+
506522
read::QuadTreeIndex cached_tree;
507523

508-
repository::PartitionsCacheRepository partitions_cache_repository(
509-
catalog_, settings_.cache);
510-
if (partitions_cache_repository.FindQuadTree(
511-
layer_id_, catalog_version_.load(), tile, cached_tree)) {
512-
auto data = cached_tree.Find(tile, false);
513-
if (!data) {
514-
return false;
524+
auto cache = settings_.cache;
525+
526+
repository::PartitionsCacheRepository partitions_repo(catalog_, cache);
527+
528+
if (partitions_repo.FindQuadTree(layer_id_, version, tile, cached_tree)) {
529+
auto data = cached_tree.Find(tile, aggregated);
530+
if (data) {
531+
repository::DataCacheRepository data_repo(catalog_, cache);
532+
return data_repo.IsCached(layer_id_, data->data_handle);
515533
}
516-
repository::DataCacheRepository data_cache_repository(catalog_,
517-
settings_.cache);
518-
return data_cache_repository.IsCached(layer_id_, data->data_handle);
519534
}
520535
return false;
521536
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ class VersionedLayerClientImpl {
6666
virtual client::CancellationToken GetData(TileRequest request,
6767
DataResponseCallback callback);
6868

69-
virtual client::CancellableFuture<DataResponse> GetData(
70-
TileRequest request);
69+
virtual client::CancellableFuture<DataResponse> GetData(TileRequest request);
7170

7271
virtual client::CancellationToken GetPartitions(
7372
PartitionsRequest request, PartitionsResponseCallback callback);
@@ -86,9 +85,9 @@ class VersionedLayerClientImpl {
8685

8786
virtual bool RemoveFromCache(const geo::TileKey& tile);
8887

89-
virtual bool IsCached(const std::string& partition_id) const;
88+
virtual bool IsCached(const std::string& partition_id);
9089

91-
virtual bool IsCached(const geo::TileKey& tile) const;
90+
virtual bool IsCached(const geo::TileKey& tile, bool aggregated = false);
9291

9392
virtual client::CancellationToken GetAggregatedData(
9493
TileRequest request, AggregatedDataResponseCallback callback);

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

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,12 +1522,12 @@ TEST_F(DataserviceReadVersionedLayerClientTest,
15221522
TEST_F(DataserviceReadVersionedLayerClientTest, PrefetchAggregatedTile) {
15231523
constexpr auto kLayerId = "hype-test-prefetch";
15241524

1525-
auto client = std::make_shared<read::VersionedLayerClient>(
1526-
kCatalog, kLayerId, boost::none, settings_);
1525+
const auto requested_tile = geo::TileKey::FromHereTile("23618365");
1526+
1527+
read::VersionedLayerClient client(kCatalog, kLayerId, boost::none, settings_);
15271528

15281529
{
15291530
SCOPED_TRACE("Prefetch aggregated tile");
1530-
const auto requested_tile = geo::TileKey::FromHereTile("23618365");
15311531

15321532
EXPECT_CALL(*network_mock_,
15331533
Send(IsGetRequest(URL_QUADKEYS_92259), _, _, _, _))
@@ -1540,7 +1540,7 @@ TEST_F(DataserviceReadVersionedLayerClientTest, PrefetchAggregatedTile) {
15401540

15411541
auto promise = std::make_shared<std::promise<PrefetchTilesResponse>>();
15421542
auto future = promise->get_future();
1543-
auto token = client->PrefetchTiles(
1543+
auto token = client.PrefetchTiles(
15441544
request, [promise](PrefetchTilesResponse response) {
15451545
promise->set_value(std::move(response));
15461546
});
@@ -1557,6 +1557,18 @@ TEST_F(DataserviceReadVersionedLayerClientTest, PrefetchAggregatedTile) {
15571557
ASSERT_TRUE(tile_response->IsSuccessful());
15581558
ASSERT_TRUE(tile_response->tile_key_.IsParentOf(requested_tile));
15591559
}
1560+
{
1561+
SCOPED_TRACE("Check that the tile is available as aggregated");
1562+
EXPECT_TRUE(client.IsCached(requested_tile, true));
1563+
EXPECT_FALSE(client.IsCached(requested_tile));
1564+
}
1565+
{
1566+
SCOPED_TRACE("Check that the tile can be accesed with GetAggregatedData");
1567+
auto future = client.GetAggregatedData(
1568+
read::TileRequest().WithTileKey(requested_tile));
1569+
auto result = future.GetFuture().get();
1570+
EXPECT_TRUE(result.IsSuccessful());
1571+
}
15601572
}
15611573

15621574
TEST_F(DataserviceReadVersionedLayerClientTest, PrefetchTilesWrongLevels) {
@@ -2983,40 +2995,48 @@ TEST_F(DataserviceReadVersionedLayerClientTest, RemoveFromCacheTileKey) {
29832995
}
29842996

29852997
TEST_F(DataserviceReadVersionedLayerClientTest, CheckIfPartitionCached) {
2986-
EXPECT_CALL(*network_mock_, Send(_, _, _, _, _))
2987-
.WillOnce(ReturnHttpResponse(GetResponse(http::HttpStatusCode::OK),
2988-
HTTP_RESPONSE_LOOKUP))
2989-
.WillOnce(ReturnHttpResponse(GetResponse(http::HttpStatusCode::OK),
2990-
kHttpResponsePartition_269))
2991-
.WillOnce(ReturnHttpResponse(GetResponse(http::HttpStatusCode::OK),
2992-
kHttpResponseBlobData_269));
2993-
2994-
auto client = std::make_shared<read::VersionedLayerClient>(
2995-
kCatalog, kTestLayer, kTestVersion, settings_);
2996-
2997-
// load and cache some data
2998-
auto promise = std::make_shared<std::promise<DataResponse>>();
2999-
auto future = promise->get_future();
2998+
settings_.cache = client::OlpClientSettingsFactory::CreateDefaultCache({});
2999+
{
3000+
SCOPED_TRACE("Download and check");
30003001

3001-
auto data_request = read::DataRequest().WithPartitionId(kTestPartition);
3002-
auto token = client->GetData(data_request, [promise](DataResponse response) {
3003-
promise->set_value(response);
3004-
});
3002+
EXPECT_CALL(*network_mock_, Send(_, _, _, _, _))
3003+
.WillOnce(ReturnHttpResponse(GetResponse(http::HttpStatusCode::OK),
3004+
HTTP_RESPONSE_LOOKUP))
3005+
.WillOnce(ReturnHttpResponse(GetResponse(http::HttpStatusCode::OK),
3006+
kHttpResponsePartition_269))
3007+
.WillOnce(ReturnHttpResponse(GetResponse(http::HttpStatusCode::OK),
3008+
kHttpResponseBlobData_269));
30053009

3006-
ASSERT_NE(future.wait_for(kWaitTimeout), std::future_status::timeout);
3007-
DataResponse response = future.get();
3010+
read::VersionedLayerClient client(kCatalog, kTestLayer, kTestVersion,
3011+
settings_);
30083012

3009-
ASSERT_TRUE(response.IsSuccessful()) << response.GetError().GetMessage();
3010-
ASSERT_NE(response.GetResult(), nullptr);
3011-
ASSERT_NE(response.GetResult()->size(), 0u);
3013+
auto data_request = read::DataRequest().WithPartitionId(kTestPartition);
3014+
auto future = client.GetData(data_request).GetFuture();
30123015

3013-
// check the data is available in cache
3014-
ASSERT_TRUE(client->IsCached(kTestPartition));
3016+
ASSERT_NE(future.wait_for(kWaitTimeout), std::future_status::timeout);
3017+
DataResponse response = future.get();
30153018

3016-
// remove the data from cache
3017-
ASSERT_TRUE(client->RemoveFromCache(kTestPartition));
3019+
ASSERT_TRUE(response.IsSuccessful()) << response.GetError().GetMessage();
3020+
ASSERT_NE(response.GetResult(), nullptr);
3021+
ASSERT_NE(response.GetResult()->size(), 0u);
30183022

3019-
ASSERT_FALSE(client->IsCached(kTestPartition));
3023+
// check the data is available in cache
3024+
ASSERT_TRUE(client.IsCached(kTestPartition));
3025+
}
3026+
{
3027+
SCOPED_TRACE("Client without version can't check");
3028+
read::VersionedLayerClient client(kCatalog, kTestLayer, boost::none,
3029+
settings_);
3030+
EXPECT_FALSE(client.IsCached(kTestPartition));
3031+
}
3032+
{
3033+
SCOPED_TRACE("IsCached after removal");
3034+
read::VersionedLayerClient client(kCatalog, kTestLayer, kTestVersion,
3035+
settings_);
3036+
ASSERT_TRUE(client.IsCached(kTestPartition));
3037+
ASSERT_TRUE(client.RemoveFromCache(kTestPartition));
3038+
ASSERT_FALSE(client.IsCached(kTestPartition));
3039+
}
30203040
}
30213041

30223042
TEST_F(DataserviceReadVersionedLayerClientTest, CheckIfTileKeyCached) {

0 commit comments

Comments
 (0)