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             1024             100          10000  avgt    8     
318.541 ±    12.416  us/op
   8 threads            1024             100          10000  avgt    8     
418.963 ±    30.124  us/op
   8 threads + sync     1024             100          10000  avgt    8     
878.342 ±    92.320  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            10000             100          10000  avgt    8    
3481.707 ±    37.420  us/op
   8 threads           10000             100          10000  avgt    8    
4652.641 ±   124.261  us/op
   8 threads + sync    10000             100          10000  avgt    8    
8283.897 ±   588.364  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
   
   1 thread           100000             100          10000  avgt    8   
62899.692 ± 11203.015  us/op
   8 threads          100000             100          10000  avgt    8   
66636.729 ±  6559.783  us/op
   8 threads + sync   100000             100          10000  avgt    8  
159911.761 ± 54040.121  us/op
   ```
   
   
   The results obtained on my machine show that there are no contention between 
threads during this operation (or it is not significant).



-- 
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]

Reply via email to