Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import org.apache.accumulo.core.client.admin.TableOperations;
import org.apache.accumulo.core.clientImpl.thrift.SecurityErrorCode;
import org.apache.accumulo.core.clientImpl.thrift.TVersionedProperties;
import org.apache.accumulo.core.clientImpl.thrift.TableOperationExceptionType;
import org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException;
import org.apache.accumulo.core.data.NamespaceId;
import org.apache.accumulo.core.data.constraints.Constraint;
import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
Expand Down Expand Up @@ -150,10 +152,6 @@ public void delete(String namespace) throws AccumuloException, AccumuloSecurityE
SecurityErrorCode.UNSUPPORTED_OPERATION);
}

if (!context.getTableMapping(namespaceId).getIdToNameMap().isEmpty()) {
throw new NamespaceNotEmptyException(namespaceId.canonical(), namespace, null);
}

List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(namespace.getBytes(UTF_8)));
Map<String,String> opts = new HashMap<>();

Expand All @@ -162,6 +160,13 @@ public void delete(String namespace) throws AccumuloException, AccumuloSecurityE
} catch (NamespaceExistsException e) {
// should not happen
throw new AssertionError(e);
} catch (AccumuloException e) {
if (e.getCause() instanceof ThriftTableOperationException ttoe
&& ttoe.getType() == TableOperationExceptionType.NAMESPACE_NOTEMPTY) {
throw new NamespaceNotEmptyException(ttoe.getTableId(), namespace, ttoe.getDescription(),
ttoe);
}
throw e;
}

}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/src/main/thrift/client.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ enum TableOperationExceptionType {
INVALID_NAME
OBSOLETE_BULK_BAD_LOAD_MAPPING
BULK_CONCURRENT_MERGE
NAMESPACE_NOTEMPTY
}

enum ConfigurationType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
*/
package org.apache.accumulo.manager.tableOps.namespace.delete;

import static org.apache.accumulo.core.clientImpl.NamespaceMapping.deserializeMap;
import static org.apache.accumulo.core.util.LazySingletons.GSON;

import org.apache.accumulo.core.clientImpl.AcceptableThriftTableOperationException;
import org.apache.accumulo.core.clientImpl.thrift.TableOperation;
import org.apache.accumulo.core.clientImpl.thrift.TableOperationExceptionType;
import org.apache.accumulo.core.data.NamespaceId;
import org.apache.accumulo.core.fate.FateId;
import org.apache.accumulo.core.fate.Repo;
import org.apache.accumulo.core.fate.zookeeper.DistributedReadWriteLock.LockType;
import org.apache.accumulo.core.util.tables.TableMapping;
import org.apache.accumulo.manager.tableOps.AbstractFateOperation;
import org.apache.accumulo.manager.tableOps.FateEnv;
import org.apache.accumulo.manager.tableOps.Utils;
Expand All @@ -48,7 +52,16 @@ public long isReady(FateId fateId, FateEnv environment) throws Exception {
}

@Override
public Repo<FateEnv> call(FateId fateId, FateEnv environment) {
public Repo<FateEnv> call(FateId fateId, FateEnv environment) throws Exception {
// skip the cache to avoid a race when deleting a namespace
final String tableMapPath = TableMapping.getZTableMapPath(namespaceId);
final byte[] tableMapBytes =
environment.getContext().getZooSession().asReader().getData(tableMapPath);
if (!deserializeMap(tableMapBytes).isEmpty()) {
throw new AcceptableThriftTableOperationException(namespaceId.canonical(), null,
TableOperation.DELETE, TableOperationExceptionType.NAMESPACE_NOTEMPTY,
"Namespace is not empty");
}
environment.getEventPublisher().event("deleting namespace %s ", namespaceId);
return new NamespaceCleanUp(namespaceId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.accumulo.test.harness.AccumuloITBase.MINI_CLUSTER_ONLY;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand All @@ -39,6 +42,7 @@
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.UUID;

import org.apache.accumulo.cluster.ClusterUser;
import org.apache.accumulo.core.client.Accumulo;
Expand All @@ -60,6 +64,7 @@
import org.apache.accumulo.core.client.admin.TableOperations;
import org.apache.accumulo.core.client.security.SecurityErrorCode;
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
import org.apache.accumulo.core.clientImpl.AcceptableThriftTableOperationException;
import org.apache.accumulo.core.clientImpl.Namespace;
import org.apache.accumulo.core.clientImpl.thrift.TableOperation;
import org.apache.accumulo.core.clientImpl.thrift.TableOperationExceptionType;
Expand All @@ -70,6 +75,8 @@
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.RowRange;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.fate.FateId;
import org.apache.accumulo.core.fate.FateInstanceType;
import org.apache.accumulo.core.iterators.Filter;
import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
Expand All @@ -79,6 +86,8 @@
import org.apache.accumulo.core.security.SystemPermission;
import org.apache.accumulo.core.security.TablePermission;
import org.apache.accumulo.core.util.tables.TableNameUtil;
import org.apache.accumulo.manager.tableOps.FateEnv;
import org.apache.accumulo.manager.tableOps.namespace.delete.DeleteNamespace;
import org.apache.accumulo.test.constraints.NumericValueConstraint;
import org.apache.accumulo.test.harness.SharedMiniClusterBase;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -268,6 +277,23 @@ public void deleteNonEmptyNamespace() throws Exception {
assertThrows(NamespaceNotEmptyException.class, () -> c.namespaceOperations().delete(namespace));
}

@Test
public void deleteNamespaceFateOpRejectsNonEmptyNamespace() throws Exception {
String tableName = namespace + ".1";
c.namespaceOperations().create(namespace);
c.tableOperations().create(tableName);

var context = getCluster().getServerContext();
FateEnv env = createMock(FateEnv.class);
expect(env.getContext()).andReturn(context).anyTimes();
replay(env);

var e = assertThrows(AcceptableThriftTableOperationException.class,
() -> new DeleteNamespace(context.getNamespaceId(namespace))
.call(FateId.from(FateInstanceType.USER, UUID.randomUUID()), env));
assertEquals(TableOperationExceptionType.NAMESPACE_NOTEMPTY, e.getType());
}

@Test
public void setProperties() throws Exception {
c.namespaceOperations().create(namespace);
Expand Down