Skip to content

Commit 502cf4f

Browse files
Merge the same QuadTree requests (#1197)
Merge the same quadtree requests during concurrent GetTile and PrefetchTiles API requests. Later this approach will be replaced with merging inside OlpClient. Additionally, take version into account when merging the requests. Resolves: OLPSUP-13676 Signed-off-by: Mykhailo Kuchma <[email protected]>
1 parent e47fe05 commit 502cf4f

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

olp-cpp-sdk-dataservice-read/src/repositories/PartitionsRepository.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ PartitionsRepository::GetPartitionsExtendedResponse(
172172
// OlpClient could handle that.
173173
const auto detail =
174174
partition_ids.empty() ? "" : HashPartitions(partition_ids);
175-
NamedMutex mutex(catalog_str + layer_id_ + detail);
175+
const auto version_str = version ? std::to_string(*version) : "";
176+
NamedMutex mutex(catalog_str + layer_id_ + version_str + detail);
176177
std::unique_lock<NamedMutex> lock(mutex, std::defer_lock);
177178

178179
// If we are not planning to go online or access the cache, do not lock.
@@ -349,7 +350,10 @@ QuadTreeIndexResponse PartitionsRepository::GetQuadTreeIndexForTile(
349350
const auto& root_tile_key = tile_key.ChangedLevelBy(-kAggregateQuadTreeDepth);
350351
const auto root_tile_here = root_tile_key.ToHereTile();
351352

352-
NamedMutex mutex(catalog_.ToString() + layer_id_ + root_tile_here + "Index");
353+
const auto quad_cache_key =
354+
cache_.CreateQuadKey(root_tile_key, kAggregateQuadTreeDepth, version);
355+
356+
NamedMutex mutex(quad_cache_key);
353357
std::unique_lock<NamedMutex> lock(mutex, std::defer_lock);
354358

355359
// If we are not planning to go online or access the cache, do not lock.

olp-cpp-sdk-dataservice-read/src/repositories/PrefetchTilesRepository.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <olp/core/thread/Atomic.h>
3333
#include <olp/core/thread/TaskScheduler.h>
3434
#include "ExtendedApiResponseHelpers.h"
35+
#include "NamedMutex.h"
3536
#include "PartitionsRepository.h"
3637
#include "QuadTreeIndex.h"
3738
#include "generated/api/QueryApi.h"
@@ -63,6 +64,7 @@ PrefetchTilesRepository::PrefetchTilesRepository(
6364
client::OlpClientSettings settings, client::ApiLookupClient client,
6465
boost::optional<std::string> billing_tag)
6566
: catalog_(std::move(catalog)),
67+
catalog_str_(catalog_.ToString()),
6668
layer_id_(layer_id),
6769
settings_(std::move(settings)),
6870
lookup_client_(std::move(client)),
@@ -195,6 +197,12 @@ client::NetworkStatistics PrefetchTilesRepository::LoadAggregatedSubQuads(
195197
while (root.Level() > aggregated_tile_key.Level()) {
196198
root = root.ChangedLevelBy(-kMaxQuadTreeIndexDepth - 1);
197199

200+
const auto quad_cache_key = cache_repository_.CreateQuadKey(
201+
root, kMaxQuadTreeIndexDepth, version);
202+
203+
NamedMutex mutex(quad_cache_key);
204+
std::unique_lock<NamedMutex> lock(mutex);
205+
198206
if (!cache_repository_.ContainsTree(root, kMaxQuadTreeIndexDepth,
199207
version)) {
200208
QuadTreeResponse response = DownloadVersionedQuadTree(
@@ -217,6 +225,12 @@ SubQuadsResponse PrefetchTilesRepository::GetVersionedSubQuads(
217225
QuadTreeIndex quad_tree;
218226
client::NetworkStatistics network_stats;
219227

228+
const auto quad_cache_key =
229+
cache_repository_.CreateQuadKey(tile, kMaxQuadTreeIndexDepth, version);
230+
231+
NamedMutex mutex(quad_cache_key);
232+
std::unique_lock<NamedMutex> lock(mutex);
233+
220234
if (cache_repository_.Get(tile, depth, version, quad_tree)) {
221235
OLP_SDK_LOG_DEBUG_F(kLogTag,
222236
"GetSubQuads found in cache, tile='%s', "

olp-cpp-sdk-dataservice-read/src/repositories/PrefetchTilesRepository.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ class PrefetchTilesRepository {
122122
client::CancellationContext context);
123123

124124
private:
125-
client::HRN catalog_;
126-
std::string layer_id_;
125+
const client::HRN catalog_;
126+
const std::string catalog_str_;
127+
const std::string layer_id_;
127128
client::OlpClientSettings settings_;
128129
client::ApiLookupClient lookup_client_;
129130
PartitionsCacheRepository cache_repository_;

0 commit comments

Comments
 (0)