vldpyatkov commented on a change in pull request #330:
URL: https://github.com/apache/ignite-3/pull/330#discussion_r708429383



##########
File path: 
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java
##########
@@ -240,301 +360,38 @@ private void createTableLocally(
      * @param tblId Table id.
      * @param assignment Affinity assignment.
      */
-    private void dropTableLocally(String name, UUID tblId, 
List<List<ClusterNode>> assignment) {
-        int partitions = assignment.size();
-
-        for (int p = 0; p < partitions; p++)
-            raftMgr.stopRaftGroup(raftGroupName(tblId, p), assignment.get(p));
-
-        TableImpl table = tables.get(name);
-
-        assert table != null : "There is no table with the name specified 
[name=" + name + ']';
-
-        onEvent(TableEvent.DROP, new TableEventParameters(table), null);
-    }
-
-    /**
-     * Compounds a RAFT group unique name.
-     *
-     * @param tableId Table identifier.
-     * @param partition Number of table partitions.
-     * @return A RAFT group name.
-     */
-    @NotNull private String raftGroupName(UUID tableId, int partition) {
-        return tableId + "_part_" + partition;
-    }
-
-    /**
-     * Table configuration changed callback.
-     *
-     * @param rev Storage revision.
-     * @param oldCfg Old configuration.
-     * @param newCfg New configuration.
-     * @return Operation future.
-     */
-    @NotNull private CompletableFuture<?> onConfigurationChanged(
-        long rev,
-        @Nullable NamedListView<TableView> oldCfg,
-        @Nullable NamedListView<TableView> newCfg
-    ) {
-        Set<String> tablesToStart = (newCfg == null || newCfg.namedListKeys() 
== null) ?
-            Collections.emptySet() :
-            newCfg.namedListKeys().stream().filter(t -> 
!oldCfg.namedListKeys().contains(t)).collect(Collectors.toSet());
-
-        Set<String> tablesToStop = (oldCfg == null || oldCfg.namedListKeys() 
== null) ?
-            Collections.emptySet() :
-            oldCfg.namedListKeys().stream().filter(t -> 
!newCfg.namedListKeys().contains(t)).collect(Collectors.toSet());
-
-        List<CompletableFuture<Boolean>> futs = new ArrayList<>();
-
-        final Set<String> schemaChanged =
-            (oldCfg != null && oldCfg.namedListKeys() != null && newCfg != 
null && newCfg.namedListKeys() != null) ?
-                oldCfg.namedListKeys().stream()
-                    .filter(tblName -> 
newCfg.namedListKeys().contains(tblName)) // Filter changed tables.
-                    .filter(tblName -> {
-                        final TableView newTbl = newCfg.get(tblName);
-                        final TableView oldTbl = oldCfg.get(tblName);
-
-                        assert newTbl.columns().namedListKeys() != null && 
oldTbl.columns().namedListKeys() != null;
-
-                        if 
(!newTbl.columns().namedListKeys().equals(oldTbl.columns().namedListKeys()))
-                            return true;
-
-                        return 
newTbl.columns().namedListKeys().stream().anyMatch(k -> {
-                            final ColumnView newCol = newTbl.columns().get(k);
-                            final ColumnView oldCol = oldTbl.columns().get(k);
-
-                            assert oldCol != null;
-
-                            if (!Objects.equals(newCol.type(), oldCol.type()))
-                                throw new SchemaModificationException("Columns 
type change is not supported.");
-
-                            if (!Objects.equals(newCol.nullable(), 
oldCol.nullable()))
-                                throw new SchemaModificationException("Column 
nullability change is not supported");
-
-                            if (!Objects.equals(newCol.name(), oldCol.name()) 
&&
-                                oldTbl.indices().namedListKeys().stream()
-                                    .map(n -> oldTbl.indices().get(n))
-                                    .filter(idx -> 
PrimaryIndex.PRIMARY_KEY_INDEX_NAME.equals(idx.name()))
-                                    .anyMatch(idx -> 
idx.columns().namedListKeys().stream()
-                                        .anyMatch(c -> 
idx.columns().get(c).name().equals(oldCol.name()))
-                                    ))
-                                throw new SchemaModificationException("Key 
column rename is not supported");
-
-                            return !Objects.equals(newCol.name(), 
oldCol.name()) ||
-                                !Objects.equals(newCol.defaultValue(), 
oldCol.defaultValue());
-                        });
-                    }).collect(Collectors.toSet()) :
-                Collections.emptySet();
-
-        if (!tablesToStart.isEmpty())
-            futs.addAll(startTables(tablesToStart, rev, newCfg));
-
-        if (!schemaChanged.isEmpty())
-            futs.addAll(changeSchema(schemaChanged, oldCfg, newCfg));
-
-        if (!tablesToStop.isEmpty())
-            futs.addAll(stopTables(tablesToStop));
-
-        return CompletableFuture.allOf(futs.toArray(CompletableFuture[]::new));
-    }
-
-    /**
-     * Start tables routine.
-     *
-     * @param tbls Tables to start.
-     * @param rev Metastore revision.
-     * @param cfgs Table configurations.
-     * @return Table creation futures.
-     */
-    private List<CompletableFuture<Boolean>> startTables(Set<String> tbls, 
long rev, NamedListView<TableView> cfgs) {
-        boolean hasMetastorageLocally = 
metaStorageMgr.hasMetastorageLocally(nodeCfgMgr);
-
-        List<CompletableFuture<Boolean>> futs = new ArrayList<>();
-
-        for (String tblName : tbls) {
-            TableView tableView = cfgs.get(tblName);
-
-            UUID tblId = new UUID(rev, 0L);
-
-            if (hasMetastorageLocally) {
-                var key = new ByteArray(INTERNAL_PREFIX + tblId);
-                futs.add(metaStorageMgr.invoke(
-                    Conditions.notExists(key),
-                    Operations.put(key, 
tableView.name().getBytes(StandardCharsets.UTF_8)),
-                    Operations.noop())
-                    .thenCompose(res -> schemaMgr.initSchemaForTable(tblId, 
tableView.name()))
-                    .thenCompose(res -> affMgr.calculateAssignments(tblId, 
tableView.name())));
-            }
-
-            final CompletableFuture<AffinityEventParameters> affinityReadyFut 
= new CompletableFuture<>();
-            final CompletableFuture<SchemaEventParameters> schemaReadyFut = 
new CompletableFuture<>();
-
-            CompletableFuture.allOf(affinityReadyFut, schemaReadyFut)
-                .exceptionally(e -> {
-                    LOG.error("Failed to create a new table [name=" + tblName 
+ ", id=" + tblId + ']', e);
-
-                    onEvent(TableEvent.CREATE, new TableEventParameters(tblId, 
tblName), e);
-
-                    return null;
-                })
-                .thenRun(() -> createTableLocally(
-                    tblName,
-                    tblId,
-                    affinityReadyFut.join().assignment(),
-                    schemaReadyFut.join().schemaRegistry()
-                ));
+    private void dropTableLocally(String name, IgniteUuid tblId, 
List<List<ClusterNode>> assignment) {
+        try {
+            int partitions = assignment.size();
 
-            affMgr.listen(AffinityEvent.CALCULATED, new EventListener<>() {
-                @Override public boolean notify(@NotNull 
AffinityEventParameters parameters, @Nullable Throwable e) {
-                    if (!tblId.equals(parameters.tableId()))
-                        return false;
+            for (int p = 0; p < partitions; p++)
+                raftMgr.stopRaftGroup(raftGroupName(tblId, p), 
assignment.get(p));
 
-                    if (e == null)
-                        affinityReadyFut.complete(parameters);
-                    else
-                        affinityReadyFut.completeExceptionally(e);
+            TableImpl table = tables.get(name);
 
-                    return true;
-                }
+            assert table != null : "There is no table with the name specified 
[name=" + name + ']';
 
-                @Override public void remove(@NotNull Throwable e) {
-                    affinityReadyFut.completeExceptionally(e);
-                }
-            });
+            tables.remove(name);
+            tablesById.remove(table.tableId());
 
-            schemaMgr.listen(SchemaEvent.INITIALIZED, new EventListener<>() {
-                @Override public boolean notify(@NotNull SchemaEventParameters 
parameters, @Nullable Throwable e) {
-                    if (!tblId.equals(parameters.tableId()) && 
parameters.schemaRegistry().lastSchemaVersion() >= 1)
-                        return false;
+            fireEvent(TableEvent.DROP, new TableEventParameters(table), null);
 
-                    if (e == null)
-                        schemaReadyFut.complete(parameters);
-                    else
-                        schemaReadyFut.completeExceptionally(e);
-
-                    return true;
-                }
-
-                @Override public void remove(@NotNull Throwable e) {
-                    schemaReadyFut.completeExceptionally(e);
-                }
-            });
+            Optional.ofNullable(dropTblIntention.get(tblId)).ifPresent(f -> 
f.complete(null));
         }
-
-        return futs;
-    }
-
-    /**
-     * Drop tables routine.
-     *
-     * @param tbls Tables to drop.
-     * @return Table drop futures.
-     */
-    private List<CompletableFuture<Boolean>> stopTables(Set<String> tbls) {
-        boolean hasMetastorageLocally = 
metaStorageMgr.hasMetastorageLocally(nodeCfgMgr);
-
-        List<CompletableFuture<Boolean>> futs = new ArrayList<>();
-
-        for (String tblName : tbls) {
-            TableImpl t = tables.get(tblName);
-
-            UUID tblId = t.tableId();
-
-            if (hasMetastorageLocally) {
-                var key = new ByteArray(INTERNAL_PREFIX + tblId);
-
-                futs.add(affMgr.removeAssignment(tblId)
-                    .thenCompose(res -> schemaMgr.unregisterSchemas(tblId))
-                    .thenCompose(res ->
-                        metaStorageMgr.invoke(Conditions.exists(key),
-                            Operations.remove(key),
-                            Operations.noop())));
-            }
-
-            affMgr.listen(AffinityEvent.REMOVED, new EventListener<>() {
-                @Override public boolean notify(@NotNull 
AffinityEventParameters parameters, @Nullable Throwable e) {
-                    if (!tblId.equals(parameters.tableId()))
-                        return false;
-
-                    if (e == null)
-                        dropTableLocally(tblName, tblId, 
parameters.assignment());
-                    else
-                        onEvent(TableEvent.DROP, new 
TableEventParameters(tblId, tblName), e);
-
-                    return true;
-                }
-
-                @Override public void remove(@NotNull Throwable e) {
-                    onEvent(TableEvent.DROP, new TableEventParameters(tblId, 
tblName), e);
-                }
-            });
+        catch (Exception e) {

Review comment:
       Drop table event with the exception have to fire 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to