public static String getPrintableTableInfoFromName(Instance instance, String tableName) { String tableId = null; try { tableId = getTableId(instance, tableName); } catch (TableNotFoundException e) { // handled in the string formatting } return tableId == null ? String.format("%s(?)", tableName) : String.format("%s(ID:%s)", tableName, tableId); }
@Override public void cancelCompaction(String tableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException { String tableId = Tables.getTableId(context.getInstance(), tableName); List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getBytes(UTF_8))); Map<String,String> opts = new HashMap<>(); try { doTableFateOperation(tableName, TableNotFoundException.class, FateOperation.TABLE_CANCEL_COMPACT, args, opts); } catch (TableExistsException e) { // should not happen throw new AssertionError(e); } }
/** * Returns the table ID for the given table name. * * @param tableName * The name of the table which to find the ID for * @return The table ID, or null if the table name doesn't exist */ private String getId(String tableName) throws TableNotFoundException { try { return Tables.getTableId(context.inst, tableName); } catch (UncheckedExecutionException e) { Throwable cause = e.getCause(); log.error("Unexpected exception when fetching table id for " + tableName); if (null == cause) { throw new RuntimeException(e); } else if (cause instanceof TableNotFoundException) { throw (TableNotFoundException) cause; } else if (cause instanceof TableOfflineException) { throw (TableOfflineException) cause; } throw e; } }
@Override public void flush(String tableName, Text start, Text end, boolean wait) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { checkArgument(tableName != null, "tableName is null"); String tableId = Tables.getTableId(context.getInstance(), tableName); _flush(tableId, start, end, wait); }
@Override public void importDirectory(String tableName, String dir, String failureDir, boolean setTime) throws IOException, AccumuloSecurityException, TableNotFoundException, AccumuloException { checkArgument(tableName != null, "tableName is null"); checkArgument(dir != null, "dir is null"); checkArgument(failureDir != null, "failureDir is null"); // check for table existance Tables.getTableId(context.getInstance(), tableName); Path dirPath = checkPath(dir, "Bulk", ""); Path failPath = checkPath(failureDir, "Bulk", "failure"); List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(UTF_8)), ByteBuffer.wrap(dirPath.toString().getBytes(UTF_8)), ByteBuffer.wrap(failPath.toString().getBytes(UTF_8)), ByteBuffer.wrap((setTime + "").getBytes(UTF_8))); Map<String,String> opts = new HashMap<>(); try { doTableFateOperation(tableName, TableNotFoundException.class, FateOperation.TABLE_BULK_IMPORT, args, opts); } catch (TableExistsException e) { // should not happen throw new AssertionError(e); } }
@Override public void offline(String tableName, boolean wait) throws AccumuloSecurityException, AccumuloException, TableNotFoundException { checkArgument(tableName != null, "tableName is null"); String tableId = Tables.getTableId(context.getInstance(), tableName); List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getBytes(UTF_8))); Map<String,String> opts = new HashMap<>(); try { doTableFateOperation(tableName, TableNotFoundException.class, FateOperation.TABLE_OFFLINE, args, opts); } catch (TableExistsException e) { // should not happen throw new AssertionError(e); } if (wait) waitForTableStateTransition(tableId, TableState.OFFLINE); }
@Override public void clone(String srcTableName, String newTableName, boolean flush, Map<String,String> propertiesToSet, Set<String> propertiesToExclude) throws AccumuloSecurityException, TableNotFoundException, AccumuloException, TableExistsException { checkArgument(srcTableName != null, "srcTableName is null"); checkArgument(newTableName != null, "newTableName is null"); String srcTableId = Tables.getTableId(context.getInstance(), srcTableName); if (flush) _flush(srcTableId, null, null, true); if (propertiesToExclude == null) propertiesToExclude = Collections.emptySet(); if (propertiesToSet == null) propertiesToSet = Collections.emptyMap(); List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(srcTableId.getBytes(UTF_8)), ByteBuffer.wrap(newTableName.getBytes(UTF_8))); Map<String,String> opts = new HashMap<>(); for (Entry<String,String> entry : propertiesToSet.entrySet()) { if (entry.getKey().startsWith(CLONE_EXCLUDE_PREFIX)) throw new IllegalArgumentException("Property can not start with " + CLONE_EXCLUDE_PREFIX); opts.put(entry.getKey(), entry.getValue()); } for (String prop : propertiesToExclude) { opts.put(CLONE_EXCLUDE_PREFIX + prop, ""); } doTableFateOperation(newTableName, AccumuloException.class, FateOperation.TABLE_CLONE, args, opts); }
@Override public void clearLocatorCache(String tableName) throws TableNotFoundException { checkArgument(tableName != null, "tableName is null"); TabletLocator tabLocator = TabletLocator.getLocator(context, Tables.getTableId(context.getInstance(), tableName)); tabLocator.invalidateCache(); }
/** * Returns the current table state (ONLINE, OFFLINE,...) of named table. * * @param tableName * the table name * @return the current table state * @throws TableNotFoundException * if table does not exist */ private TableState getTableState(String tableName) throws TableNotFoundException { String tableId = Tables.getTableId(connector.getInstance(), tableName); TableState tstate = Tables.getTableState(connector.getInstance(), tableId); log.trace("tableName: '{}': tableId {}, current state: {}", tableName, tableId, tstate); return tstate; }
static int checkTable(ClientContext context, String tableName, boolean fix) throws Exception { if (tableName.equals(RootTable.NAME)) { throw new IllegalArgumentException("Can not check root table"); } else if (tableName.equals(MetadataTable.NAME)) { return checkTable(context, RootTable.NAME, MetadataSchema.TabletsSection.getRange(), fix); } else { String tableId = Tables.getTableId(context.getInstance(), tableName); Range range = new KeyExtent(tableId, null, null).toMetadataRange(); return checkTable(context, MetadataTable.NAME, range, fix); } }
/** * Initializes an Accumulo {@link TabletLocator} based on the configuration. * * @param implementingClass * the class whose name will be used as a prefix for the property configuration key * @param conf * the Hadoop configuration object to configure * @return an Accumulo tablet locator * @throws TableNotFoundException * if the table name set on the configuration doesn't exist * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat. * @since 1.5.0 */ @Deprecated public static TabletLocator getTabletLocator(Class<?> implementingClass, Configuration conf) throws TableNotFoundException { return org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.getTabletLocator( implementingClass, conf, Tables.getTableId(getInstance(implementingClass, conf), getInputTableName(implementingClass, conf))); }
@Override public void online(String tableName, boolean wait) throws AccumuloSecurityException, AccumuloException, TableNotFoundException { checkArgument(tableName != null, "tableName is null"); String tableId = Tables.getTableId(context.getInstance(), tableName); /** * ACCUMULO-4574 if table is already online return without executing fate operation. */ TableState expectedState = Tables.getTableState(context.getInstance(), tableId, true); if (expectedState == TableState.ONLINE) { if (wait) waitForTableStateTransition(tableId, TableState.ONLINE); return; } List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getBytes(UTF_8))); 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); }
public String locateTablet(String tableName, String splitName) { String tabletName = null; try { //${accumulo.VERSION.1.6}TabletLocator tc = TabletLocator.getLocator(instance, new Text(Tables.getTableId(instance, tableName))); // 1.6 change to getLocator for 1.6 ClientContext cc = new ClientContext(instance, new Credentials(principal, token), instance.getConfiguration()); // 1.7 // Change in API in 1.7 and 1.8 -- second parameter is String instead of Text String str = Tables.getTableId(instance, tableName); TabletLocator tc = getTabletLocator(cc, str); // use dynamic invocation to cross the API change org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation loc = //${accumulo.VERSION.1.6}tc.locateTablet(new Credentials(principal, token), new Text(splitName), false, false); // 1.6 tc.locateTablet(cc, new Text(splitName), false, false); // 1.7 tabletName = loc.tablet_location; log.debug("TableName="+tableName+", TABLET_NAME = "+tabletName); } catch (TableNotFoundException | AccumuloException | AccumuloSecurityException e) { log.warn("",e); e.printStackTrace(); } return tabletName; }
String tableId = Tables.getTableId(context.getInstance(), tableName);
private String getTableId(String tableName) throws TableNotFoundException { String tableId = Tables.getTableId(context.getInstance(), tableName); if (Tables.getTableState(context.getInstance(), tableId) == TableState.OFFLINE) throw new TableOfflineException(context.getInstance(), tableId); return tableId; }
@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; String currentTableId = ""; if (!(shellState.getTableName() == null) && !shellState.getTableName().isEmpty()) { String namespaceId = Namespaces.getNamespaceId(shellState.getInstance(), old); List<String> tableIds = Namespaces.getTableIds(shellState.getInstance(), namespaceId); currentTableId = Tables.getTableId(shellState.getInstance(), shellState.getTableName()); resetContext = tableIds.contains(currentTableId); } shellState.getConnector().namespaceOperations().rename(old, newer); if (resetContext) { shellState.setTableName(Tables.getTableName(shellState.getInstance(), currentTableId)); } return 0; }
requireNonNull(ranges, "ranges must be non null"); String tableId = Tables.getTableId(context.getInstance(), tableName); TabletLocator locator = TabletLocator.getLocator(context, tableId);
/** * Checks fates in zookeeper looking for transaction associated with a compaction as a double * check that the test will be valid because the running compaction does have a fate transaction * lock. * * @return true if corresponding fate transaction found, false otherwise */ private boolean findFate(final String tableName) { Instance instance = connector.getInstance(); AdminUtil<String> admin = new AdminUtil<>(false); try { String tableId = Tables.getTableId(instance, tableName); log.trace("tid: {}", tableId); String secret = cluster.getSiteConfiguration().get(Property.INSTANCE_SECRET); IZooReaderWriter zk = new ZooReaderWriterFactory().getZooReaderWriter( instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut(), secret); ZooStore<String> zs = new ZooStore<>(ZooUtil.getRoot(instance) + Constants.ZFATE, zk); AdminUtil.FateStatus fateStatus = admin.getStatus(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS + "/" + tableId, null, null); for (AdminUtil.TransactionStatus tx : fateStatus.getTransactions()) { if (tx.getTop().contains("CompactionDriver") && tx.getDebug().contains("CompactRange")) { return true; } } } catch (KeeperException | TableNotFoundException | InterruptedException ex) { throw new IllegalStateException(ex); } // did not find appropriate fate transaction for compaction. return Boolean.FALSE; }
/** * Initializes an Accumulo {@link TabletLocator} based on the configuration. * * @param conf * the Hadoop configuration object * @return an accumulo tablet locator * @throws TableNotFoundException * if the table name set on the configuration doesn't exist * @throws IOException * if the input format is unable to read the password file from the FileSystem */ protected static TabletLocator getTabletLocator(Configuration conf) throws TableNotFoundException, IOException { if (conf.getBoolean(MOCK, false)) return new InMemoryTabletLocator(); Instance instance = getInstance(conf); String tableName = getTablename(conf); Credentials credentials = new Credentials(getUsername(conf), new PasswordToken(getPassword(conf))); return TabletLocator.getLocator(new ClientContext(instance, credentials, AccumuloConfiguration.getDefaultConfiguration()), Tables.getTableId(instance, tableName)); }
String tableId = Tables.getTableId(zki, opts.tableName);