Skip to content

Fixes race condition in deleting namespaces #5443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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 @@ -136,6 +136,11 @@ public void create(String namespace)
}
}

// This constant is used to pass information between server and client. When changing this
// consider the implication of the client and server processes running slightly different versions
// of software. This could cause the server processes to have different values for this constant.
public static final String TABLES_EXISTS_IN_NAMESPACE_INDICATOR = "TABLES_PRESENT_IN_NAMESPACE";

@Override
public void delete(String namespace) throws AccumuloException, AccumuloSecurityException,
NamespaceNotFoundException, NamespaceNotEmptyException {
Expand All @@ -158,6 +163,12 @@ public void delete(String namespace) throws AccumuloException, AccumuloSecurityE

try {
doNamespaceFateOperation(FateOperation.NAMESPACE_DELETE, args, opts, namespace);
} catch (AccumuloException ae) {
if (ae.getMessage().contains(TABLES_EXISTS_IN_NAMESPACE_INDICATOR)) {
throw new NamespaceNotEmptyException(namespaceId.canonical(), namespace, null, ae);
} else {
throw ae;
}
} catch (NamespaceExistsException e) {
// should not happen
throw new AssertionError(e);
Comment on lines 172 to 174
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of relying on the special String to detect this situation, you could instead use this existing NamespaceExistsException as a special case with the semantics of "namespace still exists (because it wasn't empty and couldn't be deleted)".

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@
*/
package org.apache.accumulo.manager.tableOps.namespace.delete;

import java.util.List;

import org.apache.accumulo.core.client.NamespaceNotFoundException;
import org.apache.accumulo.core.clientImpl.AcceptableThriftTableOperationException;
import org.apache.accumulo.core.clientImpl.NamespaceOperationsImpl;
import org.apache.accumulo.core.clientImpl.Namespaces;
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.data.TableId;
import org.apache.accumulo.core.fate.Repo;
import org.apache.accumulo.manager.Manager;
import org.apache.accumulo.manager.tableOps.ManagerRepo;
Expand All @@ -41,7 +49,26 @@ public long isReady(long id, Manager environment) throws Exception {
}

@Override
public Repo<Manager> call(long tid, Manager environment) {
public Repo<Manager> call(long tid, Manager environment)
throws AcceptableThriftTableOperationException {
try {
// Namespaces.getTableIds(..) uses the following cache, clear the cache to force
// Namespaces.getTableIds(..) to read from zookeeper.
environment.getContext().clearTableListCache();
// Since we have a write lock on the namespace id and all fate table operations get a read
// lock on the namespace id there is no need to worry about a fate operation concurrently
// changing table ids in this namespace.
List<TableId> tableIdsInNamespace =
Namespaces.getTableIds(environment.getContext(), namespaceId);
if (!tableIdsInNamespace.isEmpty()) {
throw new AcceptableThriftTableOperationException(null, null, TableOperation.DELETE,
TableOperationExceptionType.OTHER,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a different TableOperationExceptionType instead of relying on OTHER?

NamespaceOperationsImpl.TABLES_EXISTS_IN_NAMESPACE_INDICATOR);
}
} catch (NamespaceNotFoundException e) {
// not expected to happen since we have a write lock on the namespace
throw new IllegalStateException(e);
}
environment.getEventCoordinator().event("deleting namespace %s ", namespaceId);
return new NamespaceCleanUp(namespaceId);
}
Expand All @@ -50,5 +77,4 @@ public Repo<Manager> call(long tid, Manager environment) {
public void undo(long id, Manager environment) {
Utils.unreserveNamespace(environment, namespaceId, id, true);
}

}