Skip to content

Commit 6738052

Browse files
author
Liubov Didkivska
authored
Refactor prefetch functionality. (#722)
* Refactor prefetch functionality. Split functionality to two categories. With default min/max levels prefetch only requested tiles. With valid levels, which differs prefetch all tiles in subtree from min to max levels. Create slicing of subtree using depth equal 4. Update tests. Add integration test for sibling tiles. Resolves:OLPSUP-9847 Signed-off-by: Liubov Didkivska <[email protected]>
1 parent a3ead20 commit 6738052

File tree

8 files changed

+262
-169
lines changed

8 files changed

+262
-169
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace read {
4545
class DATASERVICE_READ_API PrefetchTilesRequest final {
4646
public:
4747
/**
48-
* @brief Gets a vector with the tile keys.
48+
* @brief Get the vector of the root tile keys.
4949
*
5050
* @return The vector with the tile keys.
5151
*/
@@ -54,9 +54,9 @@ class DATASERVICE_READ_API PrefetchTilesRequest final {
5454
}
5555

5656
/**
57-
* @brief Sets the tile keys for the request.
57+
* @brief Sets the vector of the root tile keys for the request.
5858
*
59-
* @param tile_keys The vector with the tile keys.
59+
* @param tile_keys The vector with the root tile keys of the prefetch.
6060
*
6161
* @return A reference to the updated `PrefetchTilesRequest` instance.
6262
*/
@@ -67,9 +67,10 @@ class DATASERVICE_READ_API PrefetchTilesRequest final {
6767
}
6868

6969
/**
70-
* @brief Sets the tile keys for the request.
70+
* @brief Sets the vector of the root tile keys for the request.
7171
*
72-
* @param tile_keys The rvalue reference to the vector with the tile keys.
72+
* @param tile_keys The rvalue reference to the vector with the root tile keys
73+
* of the prefetch.
7374
*
7475
* @return A reference to the updated `PrefetchTilesRequest` instance.
7576
*/
@@ -80,25 +81,26 @@ class DATASERVICE_READ_API PrefetchTilesRequest final {
8081
}
8182

8283
/**
83-
* @brief Gets the minimum tile level.
84+
* @brief Gets the minimum tiles level to prefetch.
8485
*
8586
* @return The minimum tile level.
8687
*/
8788
inline unsigned int GetMinLevel() const { return min_level_; }
8889

8990
/**
90-
* @brief Sets the minimum tile level for the request.
91+
* @brief Sets the minimum tiles level for the request.
9192
*
92-
* @param min_level The minimum tile level.
93+
* @param min_level The minimum tiles level to prefetch.
9394
*
9495
* @return A reference to the updated `PrefetchTilesRequest` instance.
9596
*/
9697
inline PrefetchTilesRequest& WithMinLevel(unsigned int min_level) {
9798
min_level_ = min_level;
9899
return *this;
99100
}
101+
100102
/**
101-
* @brief Gets the maximum tile level.
103+
* @brief Gets the maximum tiles level to prefetch.
102104
*
103105
* @return The maximum tile level.
104106
*/
@@ -107,7 +109,7 @@ class DATASERVICE_READ_API PrefetchTilesRequest final {
107109
/**
108110
* @brief Sets the maximum tile level for the request.
109111
*
110-
* @param max_level The maximum tile level.
112+
* @param max_level The maximum tile level to prefetch.
111113
*
112114
* @return A reference to the updated `PrefetchTilesRequest` instance.
113115
*/

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,12 @@ class DATASERVICE_READ_API VersionedLayerClient final {
278278
/**
279279
* @brief Prefetches a set of tiles asynchronously.
280280
*
281-
* This method recursively downloads all tile keys from the `minLevel`
282-
* parameter to the `maxLevel` parameter of the \c PrefetchTilesRequest
283-
* object. It helps to reduce the network load by using the prefetched tiles
284-
* data from the cache.
281+
* This method recursively downloads all tile keys from the `min_level`
282+
* parameter to the `max_level` parameter of the \c PrefetchTilesRequest
283+
* object for the given root tiles. If min_level/max_level are the same or
284+
* default, only tiles listed in \c PrefetchTilesRequest will be downloaded.
285+
* Only tiles will be downloaded which are not already present in the cache,
286+
* this helps reduce the network load.
285287
*
286288
* @note This method does not guarantee that all tiles are available offline
287289
* as the cache might overflow, and data might be evicted at any point.
@@ -300,10 +302,12 @@ class DATASERVICE_READ_API VersionedLayerClient final {
300302
/**
301303
* @brief Prefetches a set of tiles asynchronously.
302304
*
303-
* This method recursively downloads all tile keys from the `minLevel`
304-
* parameter to the `maxLevel` parameter of the \c PrefetchTilesRequest
305-
* object. It helps to reduce the network load by using the prefetched tiles
306-
* data from the cache.
305+
* This method recursively downloads all tile keys from the `min_level`
306+
* parameter to the `max_level` parameter of the \c PrefetchTilesRequest
307+
* object for the given root tiles. If min_level/max_level are the same or
308+
* default, only tiles listed in \c PrefetchTilesRequest will be downloaded.
309+
* Only tiles will be downloaded which are not already present in the cache,
310+
* this helps reduce the network load.
307311
*
308312
* @note This method does not guarantee that all tiles are available offline
309313
* as the cache might overflow, and data might be evicted at any point.

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

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -229,23 +229,31 @@ client::CancellationToken VersionedLayerClientImpl::PrefetchTiles(
229229

230230
// Calculate the minimal set of Tile keys and depth to
231231
// cover tree.
232-
auto sub_quads = repository::PrefetchTilesRepository::EffectiveTileKeys(
233-
request.GetTileKeys(), request.GetMinLevel(),
234-
request.GetMaxLevel());
235-
236-
if (sub_quads.empty()) {
232+
bool request_only_input_tiles =
233+
!(request.GetMinLevel() > 0 &&
234+
request.GetMinLevel() < request.GetMaxLevel() &&
235+
request.GetMaxLevel() < geo::TileKey().Level() &&
236+
request.GetMinLevel() < geo::TileKey().Level());
237+
unsigned int min_level =
238+
(request_only_input_tiles ? 0 : request.GetMinLevel());
239+
unsigned int max_level =
240+
(request_only_input_tiles ? 0 : request.GetMaxLevel());
241+
242+
auto sliced_tiles = repository::PrefetchTilesRepository::GetSlicedTiles(
243+
request.GetTileKeys(), min_level, max_level);
244+
245+
if (sliced_tiles.empty()) {
237246
OLP_SDK_LOG_WARNING_F(kLogTag,
238247
"PrefetchTiles: tile/level mismatch, key=%s",
239248
key.c_str());
240249
return {{ErrorCode::InvalidArgument, "TileKeys/levels mismatch"}};
241250
}
242251

243252
OLP_SDK_LOG_DEBUG_F(kLogTag, "PrefetchTiles, subquads=%zu, key=%s",
244-
sub_quads.size(), key.c_str());
253+
sliced_tiles.size(), key.c_str());
245254

246-
// Now get metadata for subtiles using QueryApi::QuadTreeIndex
247255
auto sub_tiles = repository::PrefetchTilesRepository::GetSubTiles(
248-
catalog, layer_id, request, sub_quads, context, settings);
256+
catalog, layer_id, request, sliced_tiles, context, settings);
249257

250258
if (!sub_tiles.IsSuccessful()) {
251259
return sub_tiles.GetError();
@@ -269,19 +277,38 @@ client::CancellationToken VersionedLayerClientImpl::PrefetchTiles(
269277
std::vector<CancellationContext> contexts;
270278
contexts.reserve(tiles_result.size() + 1u);
271279
auto it = tiles_result.begin();
280+
auto skip_tile = [&](const geo::TileKey& tile_key) {
281+
if (request_only_input_tiles) {
282+
if (std::find(request.GetTileKeys().begin(),
283+
request.GetTileKeys().end(),
284+
tile_key) == request.GetTileKeys().end()) {
285+
return true;
286+
}
287+
} else if (tile_key.Level() < request.GetMinLevel() ||
288+
tile_key.Level() > request.GetMaxLevel()) {
289+
// tile outside min/max segment, skip this tile
290+
return true;
291+
}
292+
return false;
293+
};
272294

273295
while (!context.IsCancelled() && it != tiles_result.end()) {
296+
auto tile = it->first;
297+
auto handle = it->second;
298+
if (skip_tile(tile)) {
299+
it++;
300+
continue;
301+
}
302+
274303
auto promise = std::make_shared<PrefetchResultPromise>();
275304
auto flag = std::make_shared<std::atomic_bool>(false);
276305
futures->emplace_back(promise->get_future());
277-
278-
auto tile = it->first;
279-
auto handle = it->second;
280306
auto context_it = contexts.emplace(contexts.end());
281307

282308
AddTask(settings.task_scheduler, pending_requests,
283309
[=](CancellationContext inner_context) {
284-
// Get blob data
310+
// TODO: Get blob data need to be changed to check if data
311+
// in cache, if not, only than load it
285312
auto data = repository::DataRepository::GetVersionedData(
286313
catalog, layer_id,
287314
DataRequest().WithDataHandle(handle).WithBillingTag(

0 commit comments

Comments
 (0)