@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 Path getFullPath(Table.ID tableId, String path) { if (path.contains(":")) return new Path(path); if (path.startsWith("../")) path = path.substring(2); else if (path.startsWith("/")) path = "/" + tableId.canonicalID() + path; else throw new IllegalArgumentException("Unexpected path prefix " + path); return getFullPath(FileType.TABLE, path); }
private String getZPath(String zkRoot) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.writeUTF(getTableId().canonicalID()); dos.writeUTF(getProblemType().name()); dos.writeUTF(getResource()); dos.close(); baos.close(); return zkRoot + Constants.ZPROBLEMS + "/" + Encoding.encodeAsBase64FileName(new Text(baos.toByteArray())); }
@Override public String getTableId() { return extent.getTableId().canonicalID(); }
public static Range getRange(Table.ID tableId) { return new Range(new Key(tableId.canonicalID() + ';'), true, new Key(tableId.canonicalID() + '<').followingKey(PartialKey.ROW), false); }
@Override public String getReturn() { return tableInfo.tableId.canonicalID(); }
public static String getPrintableTableInfoFromId(ClientContext context, Table.ID tableId) { String tableName = null; try { tableName = getTableName(context, tableId); } catch (TableNotFoundException e) { // handled in the string formatting } return tableName == null ? String.format("?(ID:%s)", tableId.canonicalID()) : String.format("%s(ID:%s)", tableName, tableId.canonicalID()); }
@Override public boolean test(Table.ID tableId) { return tableId != null && (RootTable.ID.equals(tableId) || MetadataTable.ID.equals(tableId) || ReplicationTable.ID.equals(tableId) || tableId.canonicalID().matches(VALID_ID_REGEX)); }
public BatchInputSplit(String table, Table.ID tableId, Collection<Range> ranges, String[] locations) { super(table, tableId.canonicalID(), new Range(), locations); this.ranges = ranges; }
public static String getPrintableTableInfoFromName(ClientContext context, String tableName) { Table.ID tableId = null; try { tableId = getTableId(context, tableName); } catch (TableNotFoundException e) { // handled in the string formatting } return tableId == null ? String.format("%s(?)", tableName) : String.format("%s(ID:%s)", tableName, tableId.canonicalID()); }
public static String getTableName(ClientContext context, Table.ID tableId) throws TableNotFoundException { String tableName = getIdToNameMap(context).get(tableId); if (tableName == null) throw new TableNotFoundException(tableId.canonicalID(), null, null); return tableName; }
public static String getTableOfflineMsg(ClientContext context, Table.ID tableId) { if (tableId == null) return "Table <unknown table> is offline"; try { String tableName = Tables.getTableName(context, tableId); return "Table " + tableName + " (" + tableId.canonicalID() + ") is offline"; } catch (TableNotFoundException e) { return "Table <unknown table> (" + tableId.canonicalID() + ") is offline"; } }
public void mustBeOnline(final Table.ID tableId) throws ThriftTableOperationException { Tables.clearCache(context); if (!Tables.getTableState(context, tableId).equals(TableState.ONLINE)) throw new ThriftTableOperationException(tableId.canonicalID(), null, TableOperation.MERGE, TableOperationExceptionType.OFFLINE, "table is not online"); }
public void flush(ZooLock lock, Table.ID tableId, byte[] startRow, byte[] endRow) throws TException { TabletClientService.Client client = ThriftUtil .getClient(new TabletClientService.Client.Factory(), address, context); try { client.flush(Tracer.traceInfo(), context.rpcCreds(), lockString(lock), tableId.canonicalID(), startRow == null ? null : ByteBuffer.wrap(startRow), endRow == null ? null : ByteBuffer.wrap(endRow)); } finally { ThriftUtil.returnClient(client); } }
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 boolean exists(ClientContext context, Table.ID tableId) { ZooCache zc = getZooCache(context); List<String> tableIds = zc.getChildren(context.getZooKeeperRoot() + Constants.ZTABLES); return tableIds.contains(tableId.canonicalID()); }
private Map<String,String> getExportedProps(VolumeManager fs) throws Exception { Path path = new Path(tableInfo.exportDir, Constants.EXPORT_FILE); try { FileSystem ns = fs.getVolumeByPath(path).getFileSystem(); return TableOperationsImpl.getExportedProps(ns, path); } catch (IOException ioe) { throw new AcceptableThriftTableOperationException(tableInfo.tableId.canonicalID(), tableInfo.tableName, TableOperation.IMPORT, TableOperationExceptionType.OTHER, "Error reading table props from " + path + " " + ioe.getMessage()); } }
private Namespace.ID getNamespaceIdFromTableId(TableOperation tableOp, Table.ID tableId) throws ThriftTableOperationException { Namespace.ID namespaceId; try { namespaceId = Tables.getNamespaceId(master.getContext(), tableId); } catch (TableNotFoundException e) { throw new ThriftTableOperationException(tableId.canonicalID(), null, tableOp, TableOperationExceptionType.NOTFOUND, e.getMessage()); } return namespaceId; }
private void checkForMerge(final Master master) throws Exception { VolumeManager fs = master.getFileSystem(); final Path bulkDir = new Path(bulkInfo.sourceDir); try (LoadMappingIterator lmi = BulkSerialize.readLoadMapping(bulkDir.toString(), bulkInfo.tableId, p -> fs.open(p))) { TabletIterFactory tabletIterFactory = startRow -> TabletsMetadata.builder() .forTable(bulkInfo.tableId).overlapping(startRow, null).checkConsistency().fetchPrev() .build(master.getContext()).stream().map(TabletMetadata::getExtent).iterator(); checkForMerge(bulkInfo.tableId.canonicalID(), Iterators.transform(lmi, entry -> entry.getKey()), tabletIterFactory); } }
private Namespace.ID getNamespaceIdFromTableId(TableOperation tableOp, Table.ID tableId) throws ThriftTableOperationException { Namespace.ID namespaceId; try { namespaceId = Tables.getNamespaceId(master.getContext(), tableId); } catch (TableNotFoundException e) { throw new ThriftTableOperationException(tableId.canonicalID(), null, tableOp, TableOperationExceptionType.NOTFOUND, e.getMessage()); } return namespaceId; }