AMashenkov commented on code in PR #3358:
URL: https://github.com/apache/ignite-3/pull/3358#discussion_r1522943035


##########
modules/index/src/main/java/org/apache/ignite/internal/index/IndexManager.java:
##########
@@ -198,6 +198,56 @@ private CompletableFuture<Boolean> 
onIndexCreate(CreateIndexEventParameters para
         });
     }
 
+    private void onIndexRemoved(RemoveIndexEventParameters parameters) {
+        inBusyLock(busyLock, () -> {
+            int indexId = parameters.indexId();
+            int catalogVersion = parameters.catalogVersion();
+            int previousCatalogVersion = catalogVersion - 1;
+
+            // Retrieve descriptor during synchronous call, before the 
previous catalog version could be concurrently compacted.
+            CatalogIndexDescriptor indexDescriptor = 
catalogService.index(indexId, previousCatalogVersion);
+            assert indexDescriptor != null : "index";
+
+            int tableId = indexDescriptor.tableId();
+
+            if (catalogService.table(tableId, catalogVersion) == null) {
+                // Nothing to do. Index will be destroyed along with the table.
+                return;
+            }
+
+            destructionEventsQueue.enqueue(new 
DestroyIndexEvent(catalogVersion, indexId, tableId));
+        });
+    }
+
+    private CompletableFuture<Void> onLwmChanged(HybridTimestamp ts) {
+        return inBusyLockAsync(busyLock, () -> {
+            int newEarliestCatalogVersion = 
catalogService.activeCatalogVersion(hybridTimestampToLong(ts));
+
+            List<DestroyIndexEvent> events = 
destructionEventsQueue.drainUpTo(newEarliestCatalogVersion);
+
+            if (events.isEmpty()) {
+                return nullCompletedFuture();
+            }
+
+            List<CompletableFuture<Void>> futures = events.stream()
+                    .map(event -> destroyIndexAsync(event.indexId(), 
event.tableId()))
+                    .collect(toList());
+
+            return allOf(futures.toArray(CompletableFuture[]::new));
+        });
+    }
+
+    private CompletableFuture<Void> destroyIndexAsync(int indexId, int 
tableId) {
+        return runAsync(() -> inBusyLock(busyLock, () -> {

Review Comment:
   There should be symmetry bw `registerIndex` and `unregisterIndex`.
   The `registerIndex` method doesn't return a future.
   
   Also, LWM may not wait for index storage destruction. I rewrote to a sync 
call.



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