@Override public Map<String,String> tableIdMap() { return Tables.getNameToIdMap(context).entrySet().stream() .collect(Collectors.toMap(Entry::getKey, e -> e.getValue().canonicalID(), (v1, v2) -> { throw new RuntimeException(String.format("Duplicate key for values %s and %s", v1, v2)); }, TreeMap::new)); }
public static List<Table.ID> getTableIds(ClientContext context, Namespace.ID namespaceId) throws NamespaceNotFoundException { String namespace = getNamespaceName(context, namespaceId); List<Table.ID> tableIds = new LinkedList<>(); for (Entry<String,Table.ID> nameToId : Tables.getNameToIdMap(context).entrySet()) if (namespace.equals(Tables.qualify(nameToId.getKey()).getFirst())) tableIds.add(nameToId.getValue()); return tableIds; }
public static List<String> getTableNames(ClientContext context, Namespace.ID namespaceId) throws NamespaceNotFoundException { String namespace = getNamespaceName(context, namespaceId); List<String> names = new LinkedList<>(); for (String name : Tables.getNameToIdMap(context).keySet()) if (namespace.equals(Tables.qualify(name).getFirst())) names.add(name); return names; }
public static void checkTableDoesNotExist(ServerContext context, String tableName, Table.ID tableId, TableOperation operation) throws AcceptableThriftTableOperationException { Table.ID id = Tables.getNameToIdMap(context).get(tableName); if (id != null && !id.equals(tableId)) throw new AcceptableThriftTableOperationException(null, tableName, operation, TableOperationExceptionType.EXISTS, null); }
@Override public SortedSet<String> list() { OpTimer timer = null; if (log.isTraceEnabled()) { log.trace("tid={} Fetching list of tables...", Thread.currentThread().getId()); timer = new OpTimer().start(); } TreeSet<String> tableNames = new TreeSet<>(Tables.getNameToIdMap(context).keySet()); if (timer != null) { timer.stop(); log.trace("tid={} Fetched {} table names in {}", Thread.currentThread().getId(), tableNames.size(), String.format("%.3f secs", timer.scale(TimeUnit.SECONDS))); } return tableNames; }
@Override public boolean exists(String tableName) { checkArgument(tableName != null, "tableName is null"); if (tableName.equals(MetadataTable.NAME) || tableName.equals(RootTable.NAME)) return true; OpTimer timer = null; if (log.isTraceEnabled()) { log.trace("tid={} Checking if table {} exists...", Thread.currentThread().getId(), tableName); timer = new OpTimer().start(); } boolean exists = Tables.getNameToIdMap(context).containsKey(tableName); if (timer != null) { timer.stop(); log.trace("tid={} Checked existance of {} in {}", Thread.currentThread().getId(), exists, String.format("%.3f secs", timer.scale(TimeUnit.SECONDS))); } return exists; }
public Set<ReplicationTarget> getReplicationTargets() { // The total set of configured targets final Set<ReplicationTarget> allConfiguredTargets = new HashSet<>(); final Map<String,Table.ID> tableNameToId = Tables.getNameToIdMap(context); for (String table : tableNameToId.keySet()) { if (MetadataTable.NAME.equals(table) || RootTable.NAME.equals(table)) { continue; } Table.ID localId = tableNameToId.get(table); if (localId == null) { log.trace("Could not determine ID for {}", table); continue; } TableConfiguration tableConf = context.getServerConfFactory().getTableConfiguration(localId); if (tableConf == null) { log.trace("Could not get configuration for table {} (it no longer exists)", table); continue; } for (Entry<String,String> prop : tableConf .getAllPropertiesWithPrefix(Property.TABLE_REPLICATION_TARGET).entrySet()) { String peerName = prop.getKey() .substring(Property.TABLE_REPLICATION_TARGET.getKey().length()); String remoteIdentifier = prop.getValue(); ReplicationTarget target = new ReplicationTarget(peerName, remoteIdentifier, localId); allConfiguredTargets.add(target); } } return allConfiguredTargets; }
Table.ID tableId = Tables.getNameToIdMap(context).get(tableName); MetadataServicer.forTableId(context, tableId).getTabletLocations(tabletLocations);
/** * Lookup table ID in ZK. If not found, clears cache and tries again. */ public static Table.ID _getTableId(ClientContext context, String tableName) throws NamespaceNotFoundException, TableNotFoundException { Table.ID tableId = getNameToIdMap(context).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 clearCache(context); tableId = getNameToIdMap(context).get(tableName); if (tableId == null) { String namespace = qualify(tableName).getFirst(); if (Namespaces.getNameToIdMap(context).containsKey(namespace)) throw new TableNotFoundException(null, tableName, null); else throw new NamespaceNotFoundException(null, namespace, null); } } return tableId; }
Map<String,Table.ID> tableNameToId = Tables.getNameToIdMap(Monitor.getContext()); Map<Table.ID,String> tableIdToName = invert(tableNameToId);
for (Map.Entry<String,Table.ID> entry : Tables.getNameToIdMap(Monitor.getContext()) .entrySet()) { String tableName = entry.getKey();