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



##########
File path: 
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java
##########
@@ -540,16 +575,52 @@ private void createTableLocally(
                         schemaRegistry
                 );
 
-                tables.put(name, table);
-                tablesById.put(tblId, table);
+                tablesVv.update(causalityToken, previous -> {
+                    var val = previous == null ? new HashMap() : new 
HashMap<>(previous);
+
+                    val.put(name, table);
+
+                    return val;
+                }, th -> {
+                    throw new 
IgniteInternalException(IgniteStringFormatter.format("Cannot create a table 
[name={}, id={}]", name, tblId),
+                            th);
+                });
+
+                tablesByIdVv.update(causalityToken, previous -> {
+                    var val = previous == null ? new HashMap() : new 
HashMap<>(previous);
+
+                    val.put(tblId, table);
+
+                    return val;
+                }, th -> {
+                    throw new 
IgniteInternalException(IgniteStringFormatter.format("Cannot create a table 
[name={}, id={}]", name, tblId),
+                            th);
+                });
 
-                fireEvent(TableEvent.CREATE, new TableEventParameters(table), 
null);
+                completeApiCreateFuture(table);
+
+                fireEvent(TableEvent.CREATE, new 
TableEventParameters(causalityToken, table), null);
             } catch (Exception e) {
-                fireEvent(TableEvent.CREATE, new TableEventParameters(tblId, 
name), e);
+                fireEvent(TableEvent.CREATE, new 
TableEventParameters(causalityToken, tblId, name), e);
             }
         }).join();
     }
 
+    /**
+     * Completes appropriate future to return result from API {@link 
TableManager#createTable(String, Consumer)}.
+     *
+     * @param table Table.
+     */
+    private void completeApiCreateFuture(TableImpl table) {
+        CompletableFuture<Table> tblFut = tableCreateFuts.get(table.tableId());
+
+        if (tblFut != null) {
+            tblFut.complete(table);
+
+            tableCreateFuts.values().removeIf(fut -> fut == tblFut);
+        }
+    }

Review comment:
       This future can be repeated in the map (tableCreateFuts), because update 
closure may execute several times.
   It is a tricky way to return a result after configuration update has handled.




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