HBASE-10161 [AccessController] Tolerate regions in recovery
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1552748 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
25b72708a2
commit
f9cb3d74c8
|
@ -153,6 +153,8 @@ public class AccessController extends BaseRegionObserver
|
||||||
// flags if we are able to support cell ACLs
|
// flags if we are able to support cell ACLs
|
||||||
boolean canPersistCellACLs;
|
boolean canPersistCellACLs;
|
||||||
|
|
||||||
|
private volatile boolean initialized = false;
|
||||||
|
|
||||||
void initialize(RegionCoprocessorEnvironment e) throws IOException {
|
void initialize(RegionCoprocessorEnvironment e) throws IOException {
|
||||||
final HRegion region = e.getRegion();
|
final HRegion region = e.getRegion();
|
||||||
Map<byte[], ListMultimap<String,TablePermission>> tables =
|
Map<byte[], ListMultimap<String,TablePermission>> tables =
|
||||||
|
@ -166,6 +168,7 @@ public class AccessController extends BaseRegionObserver
|
||||||
byte[] serialized = AccessControlLists.writePermissionsAsBytes(perms, e.getConfiguration());
|
byte[] serialized = AccessControlLists.writePermissionsAsBytes(perms, e.getConfiguration());
|
||||||
this.authManager.getZKPermissionWatcher().writeToZookeeper(entry, serialized);
|
this.authManager.getZKPermissionWatcher().writeToZookeeper(entry, serialized);
|
||||||
}
|
}
|
||||||
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1043,8 +1046,26 @@ public class AccessController extends BaseRegionObserver
|
||||||
}
|
}
|
||||||
if (AccessControlLists.isAclRegion(region)) {
|
if (AccessControlLists.isAclRegion(region)) {
|
||||||
aclRegion = true;
|
aclRegion = true;
|
||||||
|
// When this region is under recovering state, initialize will be handled by postLogReplay
|
||||||
|
if (!region.isRecovering()) {
|
||||||
|
try {
|
||||||
|
initialize(env);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
// if we can't obtain permissions, it's better to fail
|
||||||
|
// than perform checks incorrectly
|
||||||
|
throw new RuntimeException("Failed to initialize permissions cache", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postLogReplay(ObserverContext<RegionCoprocessorEnvironment> c) {
|
||||||
|
if (aclRegion) {
|
||||||
try {
|
try {
|
||||||
initialize(env);
|
initialize(c.getEnvironment());
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
// if we can't obtain permissions, it's better to fail
|
// if we can't obtain permissions, it's better to fail
|
||||||
// than perform checks incorrectly
|
// than perform checks incorrectly
|
||||||
|
@ -1456,6 +1477,9 @@ public class AccessController extends BaseRegionObserver
|
||||||
try {
|
try {
|
||||||
// verify it's only running at .acl.
|
// verify it's only running at .acl.
|
||||||
if (aclRegion) {
|
if (aclRegion) {
|
||||||
|
if (!initialized) {
|
||||||
|
throw new CoprocessorException("AccessController not yet initialized");
|
||||||
|
}
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("Received request to grant access permission " + perm.toString());
|
LOG.debug("Received request to grant access permission " + perm.toString());
|
||||||
}
|
}
|
||||||
|
@ -1496,6 +1520,9 @@ public class AccessController extends BaseRegionObserver
|
||||||
try {
|
try {
|
||||||
// only allowed to be called on _acl_ region
|
// only allowed to be called on _acl_ region
|
||||||
if (aclRegion) {
|
if (aclRegion) {
|
||||||
|
if (!initialized) {
|
||||||
|
throw new CoprocessorException("AccessController not yet initialized");
|
||||||
|
}
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("Received request to revoke access permission " + perm.toString());
|
LOG.debug("Received request to revoke access permission " + perm.toString());
|
||||||
}
|
}
|
||||||
|
@ -1535,6 +1562,9 @@ public class AccessController extends BaseRegionObserver
|
||||||
try {
|
try {
|
||||||
// only allowed to be called on _acl_ region
|
// only allowed to be called on _acl_ region
|
||||||
if (aclRegion) {
|
if (aclRegion) {
|
||||||
|
if (!initialized) {
|
||||||
|
throw new CoprocessorException("AccessController not yet initialized");
|
||||||
|
}
|
||||||
List<UserPermission> perms = null;
|
List<UserPermission> perms = null;
|
||||||
if(request.getType() == AccessControlProtos.Permission.Type.Table) {
|
if(request.getType() == AccessControlProtos.Permission.Type.Table) {
|
||||||
TableName table = null;
|
TableName table = null;
|
||||||
|
|
Loading…
Reference in New Issue