private String getTableName(Table.ID tableId) { try { return Tables.getTableName(context, tableId); } catch (TableNotFoundException e) { return "Unknown Table with ID " + tableId; } }
/** * 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; }
private void queue(List<QCMutation> mutations) { List<QCMutation> failures = new ArrayList<>(); Map<String,TabletServerMutations<QCMutation>> binnedMutations = new HashMap<>(); try { locator.binMutations(context, mutations, binnedMutations, failures); if (failures.size() == mutations.size()) if (!Tables.exists(context, tableId)) throw new TableDeletedException(tableId.canonicalID()); else if (Tables.getTableState(context, tableId) == TableState.OFFLINE) throw new TableOfflineException(Tables.getTableOfflineMsg(context, tableId)); } catch (Exception e) { for (QCMutation qcm : mutations) qcm.queueResult(new Result(e, qcm, null)); // do not want to queue anything that was put in before binMutations() failed failures.clear(); binnedMutations.clear(); } if (failures.size() > 0) queueRetry(failures, null); for (Entry<String,TabletServerMutations<QCMutation>> entry : binnedMutations.entrySet()) { queue(entry.getKey(), entry.getValue()); } }
Table.ID getTableId(String tableName) throws TableNotFoundException { Table.ID tableId = Tables.getTableId(this, tableName); if (Tables.getTableState(this, tableId) == TableState.OFFLINE) throw new TableOfflineException(Tables.getTableOfflineMsg(this, tableId)); return tableId; }
private void checkOffline(ClientContext context) throws Exception { if (Tables.getTableState(context, tableInfo.tableID) != TableState.OFFLINE) { Tables.clearCache(context); if (Tables.getTableState(context, tableInfo.tableID) != TableState.OFFLINE) { throw new AcceptableThriftTableOperationException(tableInfo.tableID.canonicalID(), tableInfo.tableName, TableOperation.EXPORT, TableOperationExceptionType.OTHER, "Table is not offline"); } } }
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; }
Table.ID tableId = Tables.getTableId(context, tableName); TabletLocator tl = TabletLocator.getLocator(context, tableId); if (!Tables.exists(context, tableId)) throw new TableDeletedException(tableId.canonicalID()); if (Tables.getTableState(context, tableId) == TableState.OFFLINE) throw new TableOfflineException(Tables.getTableOfflineMsg(context, tableId));
if (!Tables.exists(context, scanState.tableId)) throw new TableDeletedException(scanState.tableId.canonicalID()); else if (Tables.getTableState(context, scanState.tableId) == TableState.OFFLINE) throw new TableOfflineException( Tables.getTableOfflineMsg(context, scanState.tableId)); results = scan(loc, scanState, context); } catch (AccumuloSecurityException e) { Tables.clearCache(context); if (!Tables.exists(context, scanState.tableId)) throw new TableDeletedException(scanState.tableId.canonicalID()); e.setTableInfo(Tables.getPrintableTableInfoFromId(context, scanState.tableId)); throw e; } catch (TApplicationException tae) { throw new AccumuloServerException(loc.tablet_location, tae); } catch (TSampleNotPresentException tsnpe) { String message = "Table " + Tables.getPrintableTableInfoFromId(context, scanState.tableId) + " does not have sampling configured or built"; throw new SampleNotPresentException(message, tsnpe);
if (Tables.getTableState(context, tableId) != expectedState) { Tables.clearCache(context); TableState currentState = Tables.getTableState(context, tableId); if (currentState != expectedState) { if (!Tables.exists(context, tableId)) throw new TableDeletedException(tableId.canonicalID()); if (currentState == TableState.DELETING) throw new TableNotFoundException(tableId.canonicalID(), "", "Table is being deleted."); throw new AccumuloException("Unexpected table state " + tableId + " " + Tables.getTableState(context, tableId) + " != " + expectedState);
@Override public long isReady(long tid, Master master) throws Exception { if (!Utils.getReadLock(master, bulkInfo.tableId, tid).tryLock()) return 100; if (master.onlineTabletServers().size() == 0) return 500; Tables.clearCache(master.getContext()); return Utils.reserveHdfsDirectory(master, bulkInfo.sourceDir, tid); }
@Override public void flush(String tableName, Text start, Text end, boolean wait) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { checkArgument(tableName != null, "tableName is null"); Table.ID tableId = Tables.getTableId(context, tableName); _flush(tableId, start, end, wait); }
private void updateAuthorizationFailures(Map<KeyExtent,SecurityErrorCode> authorizationFailures) { if (authorizationFailures.size() > 0) { // was a table deleted? HashSet<Table.ID> tableIds = new HashSet<>(); for (KeyExtent ke : authorizationFailures.keySet()) tableIds.add(ke.getTableId()); Tables.clearCache(context); for (Table.ID tableId : tableIds) if (!Tables.exists(context, tableId)) throw new TableDeletedException(tableId.canonicalID()); synchronized (this) { somethingFailed = true; mergeAuthorizationFailures(this.authorizationFailures, authorizationFailures); this.notifyAll(); } } }
@Override public Repo<Master> call(long tid, Master master) throws Exception { Pair<String,String> qualifiedOldTableName = Tables.qualify(oldTableName); Pair<String,String> qualifiedNewTableName = Tables.qualify(newTableName); Tables.clearCache(master.getContext()); } finally { Utils.getTableNameLock().unlock();
public static Pair<String,String> qualify(String tableName) { return qualify(tableName, Namespace.DEFAULT); }
private Namespace.ID getNamespaceId(TCredentials credentials, Table.ID tableId) throws ThriftSecurityException { try { return Tables.getNamespaceId(context, tableId); } catch (TableNotFoundException e1) { throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.TABLE_DOESNT_EXIST); } }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, NamespaceNotFoundException, NamespaceExistsException { String old = cl.getArgs()[0]; String newer = cl.getArgs()[1]; boolean resetContext = false; Table.ID currentTableId = null; if (!(shellState.getTableName() == null) && !shellState.getTableName().isEmpty()) { Namespace.ID namespaceId = Namespaces.getNamespaceId(shellState.getContext(), old); List<Table.ID> tableIds = Namespaces.getTableIds(shellState.getContext(), namespaceId); currentTableId = Tables.getTableId(shellState.getContext(), shellState.getTableName()); resetContext = tableIds.contains(currentTableId); } shellState.getAccumuloClient().namespaceOperations().rename(old, newer); if (resetContext) { shellState.setTableName(Tables.getTableName(shellState.getContext(), currentTableId)); } return 0; }
@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)); }
@Override public void online(String tableName, boolean wait) throws AccumuloSecurityException, AccumuloException, TableNotFoundException { checkArgument(tableName != null, "tableName is null"); Table.ID tableId = Tables.getTableId(context, tableName); /** * ACCUMULO-4574 if table is already online return without executing fate operation. */ TableState expectedState = Tables.getTableState(context, tableId, true); if (expectedState == TableState.ONLINE) { if (wait) waitForTableStateTransition(tableId, TableState.ONLINE); return; } List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getUtf8())); Map<String,String> opts = new HashMap<>(); try { doTableFateOperation(tableName, TableNotFoundException.class, FateOperation.TABLE_ONLINE, args, opts); } catch (TableExistsException e) { // should not happen throw new AssertionError(e); } if (wait) waitForTableStateTransition(tableId, TableState.ONLINE); }
Tables.qualify(tableName).getFirst()); } catch (NamespaceNotFoundException e) { throw new ThriftTableOperationException(null, tableName, tableOp, try { namespaceId = Namespaces.getNamespaceId(master.getContext(), Tables.qualify(tableName).getFirst()); } catch (NamespaceNotFoundException e) { try { namespaceId = Namespaces.getNamespaceId(master.getContext(), Tables.qualify(tableName).getFirst()); } catch (NamespaceNotFoundException e) { throw new ThriftTableOperationException(null, tableName, tableOp, String tableName = Tables.getTableName(master.getContext(), tableId); canBulkImport = master.security.canBulkImport(c, tableId, tableName, dir, null, namespaceId);
Table.ID tableId = Tables.getTableId(context, tableName); throw ase; } catch (Exception e) { if (!Tables.exists(context, tableId)) { throw new TableNotFoundException(tableId.canonicalID(), tableName, null);