sanpwc commented on a change in pull request #149:
URL: https://github.com/apache/ignite-3/pull/149#discussion_r642268016
##########
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) + '.'));
+
+ try (Cursor<Entry> cursor = metaStorageMgr.range(rabge.get1(),
rabge.get2())) {
+ return cursor.hasNext();
+ }
+ catch (Exception e) {
Review comment:
I'll fix it to handle InterruptedException within node.stop issue.
--
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]