xtern commented on code in PR #2982:
URL: https://github.com/apache/ignite-3/pull/2982#discussion_r1440380010
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/mapping/MappingServiceImpl.java:
##########
@@ -96,12 +108,54 @@ public CompletableFuture<List<MappedFragment>>
map(MultiStepPlan multiStepPlan)
return initialTopologyFuture.thenComposeAsync(ignore ->
map0(multiStepPlan), taskExecutor);
}
+ /** Called when the primary replica has expired. */
+ public CompletableFuture<Boolean>
onPrimaryReplicaExpired(PrimaryReplicaEventParameters parameters) {
+ assert parameters != null;
+ assert parameters.groupId() instanceof TablePartitionId;
+
+ int tabId = ((TablePartitionId) parameters.groupId()).tableId();
+
+ return CompletableFuture.supplyAsync(() -> {
+ mappingsCache.values().removeIf(value ->
value.tableIds.contains(tabId));
+
+ return false;
+ }, ForkJoinPool.commonPool());
Review Comment:
Benchmark scenario:
* create cache + fill cache
* measure the time of **10** calls `mappingsCache.values().removeIf(value ->
value.tableIds.contains(RANDOM_TABLE_ID));`
Measuring time for single thread and for multiple threads.
`8 threads + sync` means that the `mappingsCache.values().removeIf(value ->
value.tableIds.contains(RANDOM_TABLE_ID));` is enclosed in a synchronized block
(to reduce possible contention when scanning).
`tablesInPlan` - size of set `tableIds`.
`totalTables` - total number of table IDs (the lower this number, the more
cache elements will be deleted in one scan)
```
Benchmark (cacheSize) (tablesInPlan) (totalTables) Mode Cnt
Score Error Units
1 thread 1024 10 10000 avgt 8
298.156 ± 16.015 us/op
8 threads 1024 10 10000 avgt 8
401.057 ± 14.550 us/op
8 threads + sync 1024 10 10000 avgt 8
1577.090 ± 77.315 us/op
1 thread 10000 10 10000 avgt 8
2974.037 ± 115.337 us/op
8 threads 10000 10 10000 avgt 8
4595.802 ± 282.642 us/op
8 threads + sync 10000 10 10000 avgt 8
15558.993 ± 1107.365 us/op
1 thread 100000 10 10000 avgt 8
37814.228 ± 3901.386 us/op
8 threads 100000 10 10000 avgt 8
56042.789 ± 2641.133 us/op
8 threads + sync 100000 10 10000 avgt 8
170200.745 ± 50732.738 us/op
```
The results obtained on my machine show that there is no contention between
threads during this operation (or it is not significant).
benchmark code:
https://gist.github.com/xtern/2efa0cc2c1dc6b5f87d44e4394735f3e
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]