dlmarion commented on code in PR #5451: URL: https://github.com/apache/accumulo/pull/5451#discussion_r2045388797
########## core/src/main/java/org/apache/accumulo/core/util/tables/TableZooHelper.java: ########## @@ -62,82 +55,84 @@ public TableZooHelper(ClientContext context) { * getCause() of NamespaceNotFoundException */ public TableId getTableId(String tableName) throws TableNotFoundException { - for (AccumuloTable systemTable : AccumuloTable.values()) { - if (systemTable.tableName().equals(tableName)) { - return systemTable.tableId(); - } + Pair<String,String> qualified = TableNameUtil.qualify(tableName); + NamespaceId nid = context.getNamespaces().getNameToIdMap().get(qualified.getFirst()); + if (nid == null) { + throw new TableNotFoundException(tableName, new NamespaceNotFoundException(null, + qualified.getFirst(), "No mapping found for namespace")); } - try { - return _getTableIdDetectNamespaceNotFound(EXISTING_TABLE_NAME.validate(tableName)); - } catch (NamespaceNotFoundException e) { - throw new TableNotFoundException(tableName, e); + TableId tid = context.getTableMapping(nid).getNameToIdMap().get(qualified.getSecond()); + if (tid == null) { + throw new TableNotFoundException(null, tableName, + "No entry for this table found in the given namespace mapping"); } + return tid; } - /** - * Lookup table ID in ZK. If not found, clears cache and tries again. - */ - public TableId _getTableIdDetectNamespaceNotFound(String tableName) - throws NamespaceNotFoundException, TableNotFoundException { - TableId tableId = getTableMap().getNameToIdMap().get(tableName); - if (tableId == null) { - // maybe the table exist, but the cache was not updated yet... - // so try to clear the cache and check again - clearTableListCache(); - tableId = getTableMap().getNameToIdMap().get(tableName); - if (tableId == null) { - String namespace = TableNameUtil.qualify(tableName).getFirst(); - if (Namespaces.getNameToIdMap(context).containsKey(namespace)) { - throw new TableNotFoundException(null, tableName, null); - } else { - throw new NamespaceNotFoundException(null, namespace, null); - } + public String getTableName(TableId tableId) throws TableNotFoundException { + Map<NamespaceId,String> namespaceMapping = context.getNamespaces().getIdToNameMap(); + for (NamespaceId namespaceId : namespaceMapping.keySet()) { + var tableIdToNameMap = context.getTableMapping(namespaceId).getIdToNameMap(); + if (tableIdToNameMap.containsKey(tableId)) { + return TableNameUtil.qualified(tableIdToNameMap.get(tableId), + namespaceMapping.get(namespaceId)); } } - return tableId; + throw new TableNotFoundException(tableId.canonical(), null, + "No entry for this table Id found in table mappings"); } - public String getTableName(TableId tableId) throws TableNotFoundException { - for (AccumuloTable systemTable : AccumuloTable.values()) { - if (systemTable.tableId().equals(tableId)) { - return systemTable.tableName(); + private Map<String,String> loadQualifiedTableMapping(boolean reverse) { Review Comment: > I think most callers would use only one of these, so it's not important that they both return the same thing at this level. I wasn't sure if there were methods that were using both of these maps and might end up with different contents in the map due to a race condition. If that case doesn't exist, then I don't have a concern. I did look, and I didn't see that being the case at this time. -- 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: notifications-unsubscr...@accumulo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org