ctubbsii commented on code in PR #5451:
URL: https://github.com/apache/accumulo/pull/5451#discussion_r2049531209
##########
core/src/main/java/org/apache/accumulo/core/util/tables/TableZooHelper.java:
##########
@@ -62,82 +55,81 @@ 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) {
+ final var builder = ImmutableMap.<String,String>builder();
+ for (NamespaceId namespaceId :
context.getNamespaces().getIdToNameMap().keySet()) {
Review Comment:
The looping is mainly just to resolve the fully qualified table names from
their simple table names stored in the maps. We could cache both the fully
qualified and the simple names, but that's hard to do and keep consistent. It's
definitely important to cache the stored map of simple table names, but it's
not clear that a cache of the qualified table names is important. Most of the
time, the user provides the table name, and we just have to break it into two
parts, and then do two direct map lookups (once for the namespace, then once
for the table name inside that namespace's table mapping). I think the only
time we need to loop over the full list of namespaces is when we're just
listing all tables... which is on-demand by a user, and not something that
would normally need to be optimized with an extra cache that we need to worry
about keeping consistent.
Some of these may be able to be further cleaned up after #5414, though,
because it might be easier to maintain a consistent view of the fully qualified
table names on a per-namespace basis.
--
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]