You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "AMashenkov (via GitHub)" <gi...@apache.org> on 2024/02/15 16:33:31 UTC

[PR] IGNITE-21535 Create catalog events for destroying table and index [ignite-3]

AMashenkov opened a new pull request, #3221:
URL: https://github.com/apache/ignite-3/pull/3221

   Thank you for submitting the pull request.
   
   To streamline the review process of the patch and ensure better code quality
   we ask both an author and a reviewer to verify the following:
   
   ### The Review Checklist
   - [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:  
   \- There is a single JIRA ticket related to the pull request.  
   \- The web-link to the pull request is attached to the JIRA ticket.  
   \- The JIRA ticket has the Patch Available state.  
   \- The description of the JIRA ticket explains WHAT was made, WHY and HOW.  
   \- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
   - [ ] **Design:** new code conforms with the design principles of the components it is added to.
   - [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
   - [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
   - [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
   
   ### Notes
   - [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21535 Create catalog events for destroying table and index [ignite-3]

Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov commented on code in PR #3221:
URL: https://github.com/apache/ignite-3/pull/3221#discussion_r1491308787


##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogManagerImpl.java:
##########
@@ -437,21 +442,57 @@ class OnUpdateHandlerImpl implements OnUpdateHandler {
         @Override
         public CompletableFuture<Void> handle(UpdateLogEvent event, HybridTimestamp metaStorageUpdateTimestamp, long causalityToken) {
             if (event instanceof SnapshotEntry) {
-                return handle((SnapshotEntry) event);
+                return handle((SnapshotEntry) event, causalityToken);
             }
 
             return handle((VersionedUpdate) event, metaStorageUpdateTimestamp, causalityToken);
         }
 
-        private CompletableFuture<Void> handle(SnapshotEntry event) {
+        private CompletableFuture<Void> handle(SnapshotEntry event, long causalityToken) {
             Catalog catalog = event.snapshot();
 
+            // Use reverse order to find latest descriptors.
+            Collection<Catalog> droppedCatalogVersions = catalogByVer.headMap(catalog.version(), false).descendingMap().values();
+
+            // Collect destroy events for dropped tables/indexes.
+            IntSet droppedObjects = new IntOpenHashSet();
+            List<Fireable> events = new ArrayList<>();
+
+            droppedCatalogVersions.forEach(oldCatalog -> oldCatalog.indexes().stream()
+                    .filter(idx -> catalog.index(idx.id()) == null)
+                    .filter(idx -> droppedObjects.add(idx.id()))
+                    .forEach(idx -> events.add(
+                            new DestroyIndexEvent(idx.id(), idx.tableId(), tableZoneDescriptor(oldCatalog, idx.tableId()).partitions()))
+                    ));
+
+            droppedObjects.clear();
+            droppedCatalogVersions.forEach(oldCatalog -> oldCatalog.tables().stream()
+                    .filter(tbl -> catalog.table(tbl.id()) == null)
+                    .filter(tbl -> droppedObjects.add(tbl.id()))
+                    .forEach(tbl -> events.add(new DestroyTableEvent(tbl.id(), tableZoneDescriptor(oldCatalog, tbl.id()).partitions()))));
+
             // On recovery phase, we must register catalog from the snapshot.
             // In other cases, it is ok to rewrite an existed version, because it's exactly the same.
             registerCatalog(catalog);
-            truncateUpTo(catalog);
 
-            return nullCompletedFuture();
+            List<CompletableFuture<?>> eventFutures = new ArrayList<>(events.size());
+
+            for (Fireable fireEvent : events) {
+                eventFutures.add(fireEvent(
+                        fireEvent.eventType(),
+                        fireEvent.createEventParameters(causalityToken, catalog.version())
+                ));
+            }
+
+            return allOf(eventFutures.toArray(CompletableFuture[]::new))
+                    .whenComplete((ignore, err) -> {
+                        if (err != null) {
+                            LOG.warn("Failed to compact catalog.", err);
+                            //TODO: IGNITE-14611 Pass exception to an error handler?
+                        } else {
+                            truncateUpTo(catalog);

Review Comment:
   I'm not sure if we can truncate catalog right after events are fired, and be sure all components retrieved all the required info from catalog during synchronous `notify` 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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21535 Create catalog events for destroying table and index [ignite-3]

Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov merged PR #3221:
URL: https://github.com/apache/ignite-3/pull/3221


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21535 Create catalog events for destroying table and index [ignite-3]

Posted by "korlov42 (via GitHub)" <gi...@apache.org>.
korlov42 commented on code in PR #3221:
URL: https://github.com/apache/ignite-3/pull/3221#discussion_r1493784350


##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogManagerImpl.java:
##########
@@ -498,6 +539,10 @@ private CompletableFuture<Void> handle(VersionedUpdate update, HybridTimestamp m
         }
     }
 
+    private static CatalogZoneDescriptor tableZoneDescriptor(Catalog oldCatalog, int tableId) {

Review Comment:
   does prefix `old` make sense here? (`oldCatalog`)



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogManagerImpl.java:
##########
@@ -498,6 +539,10 @@ private CompletableFuture<Void> handle(VersionedUpdate update, HybridTimestamp m
         }
     }
 
+    private static CatalogZoneDescriptor tableZoneDescriptor(Catalog oldCatalog, int tableId) {
+        return Objects.requireNonNull(oldCatalog.zone(Objects.requireNonNull(oldCatalog.table(tableId)).zoneId()));

Review Comment:
   such pattern doesn't make any sense. You either have to provide context for every `requireNonNull` (like `Objects.requireNonNull(oldCatalog.table(tableId), "table")`), or put `requireNonNull` on distinct line with temporal variable (`var table = Objects.requireNonNull(oldCatalog.table(tableId))`). Otherwise you will get `NPE at line X` with no chance to get what exactly was not found in catalog



##########
modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogManagerSelfTest.java:
##########
@@ -393,6 +395,31 @@ public void testDropTable() {
         assertSame(schema, manager.activeSchema(clock.nowLong()));
     }
 
+    @Test
+    void testReCreateTableWithSameName() {
+        assertThat(manager.execute(simpleTable(TABLE_NAME)), willBe(nullValue()));
+
+        int catalogVersion = manager.latestCatalogVersion();
+        CatalogTableDescriptor table1 = manager.table(TABLE_NAME, clock.nowLong());
+        assertNotNull(table1);
+
+        // Drop table.
+        assertThat(manager.execute(dropTableCommand(TABLE_NAME)), willBe(nullValue()));
+        assertNull(manager.table(TABLE_NAME, clock.nowLong()));
+
+        // Re-create table with same name.
+        assertThat(manager.execute(simpleTable(TABLE_NAME)), willBe(nullValue()));
+
+        CatalogTableDescriptor table2 = manager.table(TABLE_NAME, clock.nowLong());
+        assertNotNull(table2);
+
+        // Ensure these are different tables.
+        assertNotEquals(table1.id(), table2.id());
+
+        // Ensure table is available for historical queries.
+        manager.table(table1.id(), catalogVersion);

Review Comment:
   should we add any assertion here? 



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org