sanpwc commented on a change in pull request #149:
URL: https://github.com/apache/ignite-3/pull/149#discussion_r642505453
##########
File path:
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java
##########
@@ -397,6 +387,74 @@ private void listenForTableChange() {
/** {@inheritDoc} */
@Override public Table table(String name) {
- return tables.get(name);
+ if (!isTableConfigured(name))
+ throw new IgniteException("Table wasn't found [name=" + name +
']');
+
+ Table tbl = tables.get(name);
+
+ if (tbl != null)
+ return tbl;
+
+ CompletableFuture<Table> getTblFut = new CompletableFuture<>();
+
+ BiPredicate<TableEventParameters, Throwable> clo = (params, e) -> {
+ String tableName = params.tableName();
+
+ if (!name.equals(tableName))
+ return false;
+
+ if (e == null)
+ getTblFut.complete(params.table());
+ else
+ getTblFut.completeExceptionally(e);
+
+ return true;
+ };
+
+ listen(TableEvent.CREATE, clo);
+
+ tbl = tables.get(name);
+
+ if (tbl != null && getTblFut.complete(tbl) ||
+ !isTableConfigured(name) && getTblFut.completeExceptionally(new
IgniteException("Table was removed [name=" + name + ']')))
+ removeListener(TableEvent.CREATE, clo);
+
+ return getTblFut.join();
+ }
+
+ /**
+ * Checks that the table is configured.
+ *
+ * @param name Table name.
+ * @return True if table configured, false otherwise.
+ */
+ private boolean isTableConfigured(String name) {
+ IgniteBiTuple<ByteArray, ByteArray> rabge = toRange(new
ByteArray(PUBLIC_PREFIX + ConfigurationUtil.escape(name) + '.'));
Review comment:
On the other hand instead of simple get with one round trip, range
produces three round trips one for cursor creation, one for hasNext and one for
cursor close. What's the point to eliminate specific key dependence? Seems that
name key is always present.
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]