use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.
the class ServerConfigurationFactory method getNamespaceConfigurationForTable.
public NamespaceConfiguration getNamespaceConfigurationForTable(TableId tableId) {
NamespaceConfiguration conf;
synchronized (tableParentConfigs) {
conf = tableParentConfigs.get(instanceID).get(tableId);
}
// which may result in creating multiple objects for the same id, but that's ok.
if (conf == null) {
NamespaceId namespaceId;
try {
namespaceId = context.getNamespaceId(tableId);
} catch (TableNotFoundException e) {
throw new RuntimeException(e);
}
conf = new NamespaceConfiguration(namespaceId, context, getSystemConfiguration());
ConfigCheckUtil.validate(conf);
synchronized (tableParentConfigs) {
tableParentConfigs.get(instanceID).put(tableId, conf);
}
}
return conf;
}
use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.
the class ImportPopulateZookeeper method call.
@Override
public Repo<Manager> call(long tid, Manager env) throws Exception {
// reserve the table name in zookeeper or fail
Utils.getTableNameLock().lock();
try {
// write tableName & tableId to zookeeper
Utils.checkTableDoesNotExist(env.getContext(), tableInfo.tableName, tableInfo.tableId, TableOperation.CREATE);
String namespace = TableNameUtil.qualify(tableInfo.tableName).getFirst();
NamespaceId namespaceId = Namespaces.getNamespaceId(env.getContext(), namespace);
env.getTableManager().addTable(tableInfo.tableId, namespaceId, tableInfo.tableName);
env.getContext().clearTableListCache();
} finally {
Utils.getTableNameLock().unlock();
}
VolumeManager volMan = env.getVolumeManager();
for (Entry<String, String> entry : getExportedProps(volMan).entrySet()) if (!TablePropUtil.setTableProperty(env.getContext(), tableInfo.tableId, entry.getKey(), entry.getValue())) {
throw new AcceptableThriftTableOperationException(tableInfo.tableId.canonical(), tableInfo.tableName, TableOperation.IMPORT, TableOperationExceptionType.OTHER, "Invalid table property " + entry.getKey());
}
return new CreateImportDir(tableInfo);
}
use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.
the class CompactionDriverTest method testCancelId.
@Test
public void testCancelId() throws Exception {
final InstanceId instance = InstanceId.of(UUID.randomUUID());
final long compactId = 123;
final long cancelId = 124;
final NamespaceId namespaceId = NamespaceId.of("13");
final TableId tableId = TableId.of("42");
final byte[] startRow = new byte[0];
final byte[] endRow = new byte[0];
Manager manager = EasyMock.createNiceMock(Manager.class);
ServerContext ctx = EasyMock.createNiceMock(ServerContext.class);
ZooReaderWriter zrw = EasyMock.createNiceMock(ZooReaderWriter.class);
EasyMock.expect(manager.getInstanceID()).andReturn(instance).anyTimes();
EasyMock.expect(manager.getContext()).andReturn(ctx);
EasyMock.expect(ctx.getZooReaderWriter()).andReturn(zrw);
final String zCancelID = CompactionDriver.createCompactionCancellationPath(instance, tableId);
EasyMock.expect(zrw.getData(zCancelID)).andReturn(Long.toString(cancelId).getBytes());
EasyMock.replay(manager, ctx, zrw);
final CompactionDriver driver = new CompactionDriver(compactId, namespaceId, tableId, startRow, endRow);
final long tableIdLong = Long.parseLong(tableId.toString());
var e = assertThrows(AcceptableThriftTableOperationException.class, () -> driver.isReady(tableIdLong, manager));
assertTrue(e.getTableId().equals(tableId.toString()));
assertTrue(e.getOp().equals(TableOperation.COMPACT));
assertTrue(e.getType().equals(TableOperationExceptionType.OTHER));
assertTrue(e.getDescription().equals(TableOperationsImpl.COMPACTION_CANCELED_MSG));
EasyMock.verify(manager, ctx, zrw);
}
use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.
the class DUCommand method execute.
@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws IOException, TableNotFoundException, NamespaceNotFoundException {
final SortedSet<String> tables = new TreeSet<>(Arrays.asList(cl.getArgs()));
if (cl.hasOption(ShellOptions.tableOption)) {
tables.add(cl.getOptionValue(ShellOptions.tableOption));
}
if (cl.hasOption(optNamespace.getOpt())) {
NamespaceId namespaceId = Namespaces.getNamespaceId(shellState.getContext(), cl.getOptionValue(optNamespace.getOpt()));
tables.addAll(Namespaces.getTableNames(shellState.getContext(), namespaceId));
}
boolean prettyPrint = cl.hasOption(optHumanReadble.getOpt());
// Add any patterns
if (cl.hasOption(optTablePattern.getOpt())) {
shellState.getAccumuloClient().tableOperations().list().stream().filter(Pattern.compile(cl.getOptionValue(optTablePattern.getOpt())).asMatchPredicate()).forEach(tables::add);
}
// If we didn't get any tables, and we have a table selected, add the current table
if (tables.isEmpty() && !shellState.getTableName().isEmpty()) {
tables.add(shellState.getTableName());
}
// sanity check...make sure the user-specified tables exist
for (String tableName : tables) {
if (!shellState.getAccumuloClient().tableOperations().exists(tableName)) {
throw new TableNotFoundException(tableName, tableName, "specified table that doesn't exist");
}
}
try {
String valueFormat = prettyPrint ? "%9s" : "%,24d";
for (DiskUsage usage : shellState.getAccumuloClient().tableOperations().getDiskUsage(tables)) {
Object value = prettyPrint ? NumUtil.bigNumberForSize(usage.getUsage()) : usage.getUsage();
shellState.getWriter().println(String.format(valueFormat + " %s", value, usage.getTables()));
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
return 0;
}
use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.
the class CompactionCoordinator method cancel.
@Override
public void cancel(TInfo tinfo, TCredentials credentials, String externalCompactionId) throws TException {
var runningCompaction = RUNNING.get(ExternalCompactionId.of(externalCompactionId));
var extent = KeyExtent.fromThrift(runningCompaction.getJob().getExtent());
try {
NamespaceId nsId = getContext().getNamespaceId(extent.tableId());
if (!security.canCompact(credentials, extent.tableId(), nsId)) {
throw new AccumuloSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED).asThriftException();
}
} catch (TableNotFoundException e) {
throw new ThriftTableOperationException(extent.tableId().canonical(), null, TableOperation.COMPACT_CANCEL, TableOperationExceptionType.NOTFOUND, e.getMessage());
}
HostAndPort address = HostAndPort.fromString(runningCompaction.getCompactorAddress());
ExternalCompactionUtil.cancelCompaction(getContext(), address, externalCompactionId);
}
Aggregations