Skip to content

Commit 403f01e

Browse files
authored
Make prefetch report all statuses on cancel. (#1151)
Prefetch must give statuses for all tiles, so user can check what is loaded and what requests are failed. Same for cancel, if atleast one tile prefetched successfully. Resolves: OAM-740 Signed-off-by: Kostiantyn Zvieriev <[email protected]>
1 parent ae27252 commit 403f01e

File tree

2 files changed

+30
-41
lines changed

2 files changed

+30
-41
lines changed

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

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -177,22 +177,19 @@ client::CancellationToken VersionedLayerClientImpl::PrefetchPartitions(
177177

178178
client::CancellationContext execution_context;
179179

180-
auto prefetch_callback = [=](PrefetchPartitionsResponse response) {
181-
if (execution_context.IsCancelled()) {
182-
callback(ApiError(ErrorCode::Cancelled, "Canceled"));
183-
} else {
184-
callback(response);
185-
}
186-
};
187-
188180
return task_sink_.AddTask(
189181
[=](client::CancellationContext context) {
182+
if (context.IsCancelled()) {
183+
callback(ApiError(ErrorCode::Cancelled, "Canceled"));
184+
return;
185+
}
186+
190187
if (request.GetPartitionIds().empty()) {
191188
OLP_SDK_LOG_WARNING_F(
192189
kLogTag,
193190
"PrefetchPartitions : invalid request, catalog=%s, layer=%s",
194191
catalog_.ToCatalogHRNString().c_str(), layer_id_.c_str());
195-
prefetch_callback(
192+
callback(
196193
ApiError(ErrorCode::InvalidArgument, "Empty partitions list"));
197194
return;
198195
}
@@ -209,7 +206,7 @@ client::CancellationToken VersionedLayerClientImpl::PrefetchPartitions(
209206
"failed, catalog=%s, key=%s",
210207
catalog_.ToCatalogHRNString().c_str(),
211208
key.c_str());
212-
prefetch_callback(response.GetError());
209+
callback(response.GetError());
213210
return;
214211
}
215212

@@ -282,13 +279,13 @@ client::CancellationToken VersionedLayerClientImpl::PrefetchPartitions(
282279
};
283280

284281
auto call_user_callback =
285-
[prefetch_callback](PrefetchPartitionsResponse result) {
282+
[callback](PrefetchPartitionsResponse result) {
286283
if (result.IsSuccessful() &&
287284
result.GetResult().GetPartitions().size() == 0) {
288-
prefetch_callback(ApiError(client::ErrorCode::Unknown,
289-
"No partitions were prefetched."));
285+
callback(ApiError(client::ErrorCode::Unknown,
286+
"No partitions were prefetched."));
290287
} else {
291-
prefetch_callback(std::move(result));
288+
callback(std::move(result));
292289
}
293290
};
294291

@@ -327,22 +324,18 @@ client::CancellationToken VersionedLayerClientImpl::PrefetchTiles(
327324

328325
client::CancellationContext execution_context;
329326

330-
auto prefetch_callback = [=](PrefetchTilesResponse response) {
331-
if (execution_context.IsCancelled()) {
332-
callback(ApiError(ErrorCode::Cancelled, "Canceled"));
333-
} else {
334-
callback(response);
335-
}
336-
};
337-
338327
return task_sink_.AddTask(
339328
[=](client::CancellationContext context) mutable -> void {
329+
if (context.IsCancelled()) {
330+
callback(ApiError(ErrorCode::Cancelled, "Canceled"));
331+
return;
332+
}
333+
340334
if (request.GetTileKeys().empty()) {
341335
OLP_SDK_LOG_WARNING_F(
342336
kLogTag, "PrefetchTiles : invalid request, catalog=%s, layer=%s",
343337
catalog_.ToCatalogHRNString().c_str(), layer_id_.c_str());
344-
prefetch_callback(
345-
ApiError(ErrorCode::InvalidArgument, "Empty tile key list"));
338+
callback(ApiError(ErrorCode::InvalidArgument, "Empty tile key list"));
346339
return;
347340
}
348341

@@ -355,7 +348,7 @@ client::CancellationToken VersionedLayerClientImpl::PrefetchTiles(
355348
OLP_SDK_LOG_WARNING_F(
356349
kLogTag, "PrefetchTiles: getting catalog version failed, key=%s",
357350
key.c_str());
358-
prefetch_callback(response.GetError());
351+
callback(response.GetError());
359352
return;
360353
}
361354

@@ -390,7 +383,7 @@ client::CancellationToken VersionedLayerClientImpl::PrefetchTiles(
390383
OLP_SDK_LOG_WARNING_F(kLogTag,
391384
"PrefetchTiles: tile/level mismatch, key=%s",
392385
key.c_str());
393-
prefetch_callback(
386+
callback(
394387
ApiError(ErrorCode::InvalidArgument, "TileKeys/levels mismatch"));
395388
return;
396389
}
@@ -461,8 +454,8 @@ client::CancellationToken VersionedLayerClientImpl::PrefetchTiles(
461454
};
462455

463456
auto download_job = std::make_shared<PrefetchTilesHelper::DownloadJob>(
464-
std::move(download), std::move(append_result),
465-
std::move(prefetch_callback), std::move(status_callback));
457+
std::move(download), std::move(append_result), std::move(callback),
458+
std::move(status_callback));
466459

467460
return PrefetchTilesHelper::Prefetch(
468461
std::move(download_job), std::move(roots), std::move(query),

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -165,24 +165,20 @@ client::CancellationToken VolatileLayerClientImpl::PrefetchTiles(
165165

166166
client::CancellationContext execution_context;
167167

168-
auto prefetch_callback = [=](PrefetchTilesResponse response) {
169-
if (execution_context.IsCancelled()) {
170-
callback(ApiError(ErrorCode::Cancelled, "Canceled"));
171-
} else {
172-
callback(response);
173-
}
174-
};
175-
176168
return task_sink_.AddTask(
177169
[=](client::CancellationContext context) mutable -> void {
170+
if (context.IsCancelled()) {
171+
callback(ApiError(ErrorCode::Cancelled, "Canceled"));
172+
return;
173+
}
174+
178175
const auto& tile_keys = request.GetTileKeys();
179176
if (tile_keys.empty()) {
180177
OLP_SDK_LOG_WARNING_F(kLogTag,
181178
"PrefetchTiles : invalid request, layer=%s",
182179
layer_id_.c_str());
183180

184-
prefetch_callback(
185-
ApiError(ErrorCode::InvalidArgument, "Empty tile key list"));
181+
callback(ApiError(ErrorCode::InvalidArgument, "Empty tile key list"));
186182
return;
187183
}
188184

@@ -210,7 +206,7 @@ client::CancellationToken VolatileLayerClientImpl::PrefetchTiles(
210206
OLP_SDK_LOG_WARNING_F(kLogTag,
211207
"PrefetchTiles: tile/level mismatch, key=%s",
212208
key.c_str());
213-
prefetch_callback(
209+
callback(
214210
ApiError(ErrorCode::InvalidArgument, "TileKeys/levels mismatch"));
215211
return;
216212
}
@@ -277,8 +273,8 @@ client::CancellationToken VolatileLayerClientImpl::PrefetchTiles(
277273
};
278274

279275
auto download_job = std::make_shared<PrefetchTilesHelper::DownloadJob>(
280-
std::move(download), std::move(append_result),
281-
std::move(prefetch_callback), nullptr);
276+
std::move(download), std::move(append_result), std::move(callback),
277+
nullptr);
282278
return PrefetchTilesHelper::Prefetch(
283279
std::move(download_job), std::move(roots), std::move(query),
284280
std::move(filter), task_sink_, request.GetPriority(), context);

0 commit comments

Comments
 (0)