private Optional<String> getDefaultTabletLocation(String fulltable) { try { String tableId = connector.tableOperations().tableIdMap().get(fulltable); // Create a scanner over the metadata table, fetching the 'loc' column of the default tablet row Scanner scan = connector.createScanner("accumulo.metadata", connector.securityOperations().getUserAuthorizations(username)); scan.fetchColumnFamily(new Text("loc")); scan.setRange(new Range(tableId + '<')); // scan the entry Optional<String> location = Optional.empty(); for (Entry<Key, Value> entry : scan) { if (location.isPresent()) { throw new PrestoException(FUNCTION_IMPLEMENTATION_ERROR, "Scan for default tablet returned more than one entry"); } location = Optional.of(entry.getValue().toString()); } scan.close(); return location; } catch (Exception e) { // Swallow this exception so the query does not fail due to being unable to locate the tablet server for the default tablet. // This is purely an optimization, but we will want to log the error. LOG.error("Failed to get tablet location, returning dummy location", e); return Optional.empty(); } }
String tableId = connector.tableOperations().tableIdMap().get(table);
public static MetadataServicer forTableName(ClientContext context, String tableName) throws AccumuloException, AccumuloSecurityException { checkArgument(tableName != null, "tableName is null"); return forTableId(context, Table.ID.of(context.tableOperations().tableIdMap().get(tableName))); }
Set<String> tables = context.tableOperations().tableIdMap().keySet(); for (String table : tables) { if (table.equals(MetadataTable.NAME))
@SuppressWarnings("unchecked") @Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, IOException, NamespaceNotFoundException { final String namespace = cl.hasOption(OptUtil.namespaceOpt().getOpt()) ? OptUtil.getNamespaceOpt(cl, shellState) : null; Map<String,String> tables = shellState.getAccumuloClient().tableOperations().tableIdMap(); // filter only specified namespace tables = Maps.filterKeys(tables, tableName -> namespace == null || Tables.qualify(tableName).getFirst().equals(namespace)); final boolean sortByTableId = cl.hasOption(sortByTableIdOption.getOpt()); tables = new TreeMap<String,String>((sortByTableId ? MapUtils.invertMap(tables) : tables)); Iterator<String> it = Iterators.transform(tables.entrySet().iterator(), entry -> { String tableName = String.valueOf(sortByTableId ? entry.getValue() : entry.getKey()); String tableId = String.valueOf(sortByTableId ? entry.getKey() : entry.getValue()); if (namespace != null) tableName = Tables.qualify(tableName).getSecond(); if (cl.hasOption(tableIdOption.getOpt())) return String.format(NAME_AND_ID_FORMAT, tableName, tableId); else return tableName; }); shellState.printLines(it, !cl.hasOption(disablePaginationOpt.getOpt())); return 0; }
@Override public long balance(SortedMap<TServerInstance,TabletServerStatus> current, Set<KeyExtent> migrations, List<TabletMigration> migrationsOut) { long minBalanceTime = 5 * 1000; // Iterate over the tables and balance each of them TableOperations t = getTableOperations(); if (t == null) return minBalanceTime; for (String s : t.tableIdMap().values()) { ArrayList<TabletMigration> newMigrations = new ArrayList<>(); long tableBalanceTime = getBalancerForTable(Table.ID.of(s)).balance(current, migrations, newMigrations); if (tableBalanceTime < minBalanceTime) minBalanceTime = tableBalanceTime; migrationsOut.addAll(newMigrations); } return minBalanceTime; } }
for (Entry<String,String> table : t.tableIdMap().entrySet()) { Table.ID tableId = Table.ID.of(table.getValue()); tableIdToTableName.put(tableId, table.getKey());
return minBalanceTime; Map<String,String> tableIdMap = t.tableIdMap(); long now = System.currentTimeMillis();
protected Table.ID getTableId(AccumuloClient client, String tableName) throws TableNotFoundException { TableOperations tops = client.tableOperations(); if (!client.tableOperations().exists(tableName)) { throw new TableNotFoundException(null, tableName, null); } String tableId = null; while (tableId == null) { tableId = tops.tableIdMap().get(tableName); if (tableId == null) { sleepUninterruptibly(200, TimeUnit.MILLISECONDS); } } return Table.ID.of(tableId); }
public static void main(String[] args) throws Exception { ServerUtilOpts opts = new ServerUtilOpts(); opts.parseArgs(MergeStats.class.getName(), args); try (AccumuloClient client = opts.createClient()) { Map<String,String> tableIdMap = client.tableOperations().tableIdMap(); ZooReaderWriter zooReaderWriter = opts.getServerContext().getZooReaderWriter(); for (Entry<String,String> entry : tableIdMap.entrySet()) { final String table = entry.getKey(), tableId = entry.getValue(); String path = ZooUtil.getRoot(client.getInstanceID()) + Constants.ZTABLES + "/" + tableId + "/merge"; MergeInfo info = new MergeInfo(); if (zooReaderWriter.exists(path)) { byte[] data = zooReaderWriter.getData(path, new Stat()); DataInputBuffer in = new DataInputBuffer(); in.reset(data, data.length); info.readFields(in); } System.out.println(String.format("%25s %10s %10s %s", table, info.getState(), info.getOperation(), info.getExtent())); } } } }
TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner); final Text start = new Text( shellState.getAccumuloClient().tableOperations().tableIdMap().get(tableName)); final Text end = new Text(start); end.append(new byte[] {'<'}, 0, 1);
return 1; String tblStr = context.tableOperations().tableIdMap().get(tableName); if (tblStr == null) { log.error("Could not determine the table ID for table {}", tableName);
@Override protected String getTableId(Instance inst, String tableName) throws ThriftTableOperationException { try { return conn.tableOperations().tableIdMap().get(tableName); } catch (Exception e) { throw new RuntimeException(e); } } };
public static MetadataServicer forTableName(ClientContext context, String tableName) throws AccumuloException, AccumuloSecurityException { checkArgument(tableName != null, "tableName is null"); return forTableId(context, context.getConnector().tableOperations().tableIdMap().get(tableName)); }
@Override public Set<String> onlineTables() { HashSet<String> onlineTables = new HashSet<>( getConnector().tableOperations().tableIdMap().values()); return Sets.filter(onlineTables, new Predicate<String>() { @Override public boolean apply(String tableId) { return Tables.getTableState(getConnector().getInstance(), tableId) == TableState.ONLINE; } }); }
boolean isOffline(String tablename, Connector connector) throws TableNotFoundException { String tableId = connector.tableOperations().tableIdMap().get(tablename); Scanner scanner = connector.createScanner(MetadataTable.NAME, Authorizations.EMPTY); scanner.setRange(new Range(new Text(tableId + ";"), new Text(tableId + "<"))); scanner.fetchColumnFamily(TabletsSection.CurrentLocationColumnFamily.NAME); return Iterators.size(scanner.iterator()) == 0; }
@Override public Collection<MergeInfo> merges() { String tableIdToModify = getConnector().tableOperations().tableIdMap().get(t3); return Collections.singletonList( new MergeInfo(new KeyExtent(tableIdToModify, null, null), MergeInfo.Operation.MERGE)); } };
public List<ActiveCompaction> getActiveCompactions(String tserver) throws AccumuloException, AccumuloSecurityException { try { return ThriftHelper.fromThriftActiveCompactions(connector.tableOperations().tableIdMap(), connector.getClient().getActiveCompactions(token, tserver)); } catch (TException e) { throw ExceptionFactory.accumuloException(e); } }
private void addDuplicateLocation(String table, String tableNameToModify) throws TableNotFoundException, MutationsRejectedException { String tableIdToModify = getConnector().tableOperations().tableIdMap().get(tableNameToModify); Mutation m = new Mutation(new KeyExtent(tableIdToModify, null, null).getMetadataEntry()); m.put(MetadataSchema.TabletsSection.CurrentLocationColumnFamily.NAME, new Text("1234567"), new Value("fake:9005".getBytes(UTF_8))); BatchWriter bw = getConnector().createBatchWriter(table, null); bw.addMutation(m); bw.close(); }
private void removeLocation(String table, String tableNameToModify) throws TableNotFoundException, MutationsRejectedException { String tableIdToModify = getConnector().tableOperations().tableIdMap().get(tableNameToModify); BatchDeleter deleter = getConnector().createBatchDeleter(table, Authorizations.EMPTY, 1, new BatchWriterConfig()); deleter.setRanges( Collections.singleton(new KeyExtent(tableIdToModify, null, null).toMetadataRange())); deleter.fetchColumnFamily(MetadataSchema.TabletsSection.CurrentLocationColumnFamily.NAME); deleter.delete(); deleter.close(); }