You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by am...@apache.org on 2023/08/24 15:50:32 UTC
[ignite-3] 02/02: Use sync service instead of configuration.
This is an automated email from the ASF dual-hosted git repository.
amashenkov pushed a commit to branch ignite-19499
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
commit 0e4ff15d2778680c5369f8ffbc1e0981827cf329
Author: amashenkov <an...@gmail.com>
AuthorDate: Thu Aug 24 18:48:29 2023 +0300
Use sync service instead of configuration.
---
.../internal/table/distributed/TableManager.java | 91 ++++++++++------------
1 file changed, 40 insertions(+), 51 deletions(-)
diff --git a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java
index 8581f93056..99001a22bd 100644
--- a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java
+++ b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java
@@ -1822,60 +1822,32 @@ public class TableManager extends Producer<TableEvent, TableEventParameters> imp
* @return Future representing pending completion of the operation.
*/
private CompletableFuture<List<Table>> tablesAsyncInternal() {
- return supplyAsync(() -> inBusyLock(busyLock, this::directTableIds), ioExecutor)
- .thenCompose(tableIds -> inBusyLock(busyLock, () -> {
- var tableFuts = new CompletableFuture[tableIds.size()];
-
- var i = 0;
-
- for (int tblId : tableIds) {
- tableFuts[i++] = tableAsyncInternal(tblId, false);
- }
-
- return allOf(tableFuts).thenApply(unused -> inBusyLock(busyLock, () -> {
- var tables = new ArrayList<Table>(tableIds.size());
-
- for (var fut : tableFuts) {
- var table = fut.join();
-
- if (table != null) {
- tables.add((Table) table);
- }
- }
-
- return tables;
- }));
- }));
- }
-
- /**
- * Collects a list of direct table ids.
- *
- * @return A list of direct table ids.
- */
- private List<Integer> directTableIds() {
- return configuredTablesCache.configuredTableIds();
+ return schemaSyncService.waitForMetadataCompleteness(clock.now())
+ .thenApply(ignore -> List.copyOf(latestTablesById().values()));
}
/**
- * Gets direct id of table with {@code tblName}.
+ * Return actual table id by given name or {@code null} if table doesn't exist.
*
- * @param tblName Name of the table.
- * @return Direct id of the table, or {@code null} if the table with the {@code tblName} has not been found.
+ * @param tblName Table name
+ * @return Operation future.
*/
- @Nullable
- private Integer directTableId(String tblName) {
- try {
- TableConfiguration exTblCfg = directProxy(tablesCfg.tables()).get(tblName);
+ private CompletableFuture<Integer> actualTableId(String tblName) {
+ return schemaSyncService.waitForMetadataCompleteness(clock.now())
+ // TODO IGNITE-19499: Use id from Catalog here.
+ .thenApply(ignore -> {
+ try {
+ TableConfiguration exTblCfg = tablesCfg.tables().get(tblName);
- if (exTblCfg == null) {
- return null;
- } else {
- return exTblCfg.id().value();
- }
- } catch (NoSuchElementException e) {
- return null;
- }
+ if (exTblCfg == null) {
+ return null;
+ } else {
+ return exTblCfg.id().value();
+ }
+ } catch (NoSuchElementException e) {
+ return null;
+ }
+ });
}
/**
@@ -2029,14 +2001,14 @@ public class TableManager extends Producer<TableEvent, TableEventParameters> imp
}
try {
- return supplyAsync(() -> inBusyLock(busyLock, () -> directTableId(name)), ioExecutor)
- .thenCompose(tableId -> inBusyLock(busyLock, () -> {
+ return actualTableId(name)
+ .thenComposeAsync(tableId -> inBusyLock(busyLock, () -> {
if (tableId == null) {
return completedFuture(null);
}
return tableAsyncInternal(tableId, false);
- }));
+ }), ioExecutor);
} finally {
busyLock.leaveBusy();
}
@@ -2051,6 +2023,23 @@ public class TableManager extends Producer<TableEvent, TableEventParameters> imp
* @return Future representing pending completion of the operation.
*/
public CompletableFuture<TableImpl> tableAsyncInternal(int id, boolean checkConfiguration) {
+ return schemaSyncService.waitForMetadataCompleteness(clock.now())
+ // TODO IGNITE-19499: Use id from Catalog here.
+ .thenApply(ignore -> {
+ TableImpl table = latestTablesById().get(id);
+
+ if (table != null) {
+ return table;
+ } else if (!checkConfiguration) {
+ return null;
+ }
+
+ throw new IllegalStateException("Table not found: id=" + id);
+ });
+ }
+
+ // TODO IGNITE-19499: Drop prev version of the method
+ private CompletableFuture<TableImpl> __tableAsyncInternal(int id, boolean checkConfiguration) {
CompletableFuture<Boolean> tblCfgFut = checkConfiguration
? supplyAsync(() -> inBusyLock(busyLock, () -> isTableConfigured(id)), ioExecutor)
: completedFuture(true);