use of org.apache.accumulo.core.client.impl.Namespace in project accumulo by apache.
the class Master method upgradeZookeeper.
private void upgradeZookeeper() {
// 1.5.1 and 1.6.0 both do some state checking after obtaining the zoolock for the
// monitor and before starting up. It's not tied to the data version at all (and would
// introduce unnecessary complexity to try to make the master do it), but be aware
// that the master is not the only thing that may alter zookeeper before starting.
final int accumuloPersistentVersion = Accumulo.getAccumuloPersistentVersion(fs);
if (Accumulo.persistentVersionNeedsUpgrade(accumuloPersistentVersion)) {
// Change to Guava's Verify once we use Guava 17.
if (null != fate) {
throw new IllegalStateException("Access to Fate should not have been initialized prior to the Master transitioning to active. Please save all logs and file a bug.");
}
Accumulo.abortIfFateTransactions();
try {
log.info("Upgrading zookeeper");
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
final String zooRoot = ZooUtil.getRoot(getInstance());
log.debug("Handling updates for version {}", accumuloPersistentVersion);
log.debug("Cleaning out remnants of logger role.");
zoo.recursiveDelete(zooRoot + "/loggers", NodeMissingPolicy.SKIP);
zoo.recursiveDelete(zooRoot + "/dead/loggers", NodeMissingPolicy.SKIP);
final byte[] zero = new byte[] { '0' };
log.debug("Initializing recovery area.");
zoo.putPersistentData(zooRoot + Constants.ZRECOVERY, zero, NodeExistsPolicy.SKIP);
for (String id : zoo.getChildren(zooRoot + Constants.ZTABLES)) {
log.debug("Prepping table {} for compaction cancellations.", id);
zoo.putPersistentData(zooRoot + Constants.ZTABLES + "/" + id + Constants.ZTABLE_COMPACT_CANCEL_ID, zero, NodeExistsPolicy.SKIP);
}
@SuppressWarnings("deprecation") String zpath = zooRoot + Constants.ZCONFIG + "/" + Property.TSERV_WAL_SYNC_METHOD.getKey();
// is the entire instance set to use flushing vs sync?
boolean flushDefault = false;
try {
byte[] data = zoo.getData(zpath, null);
if (new String(data, UTF_8).endsWith("flush")) {
flushDefault = true;
}
} catch (KeeperException.NoNodeException ex) {
// skip
}
for (String id : zoo.getChildren(zooRoot + Constants.ZTABLES)) {
log.debug("Converting table {} WALog setting to Durability", id);
try {
@SuppressWarnings("deprecation") String path = zooRoot + Constants.ZTABLES + "/" + id + Constants.ZTABLE_CONF + "/" + Property.TABLE_WALOG_ENABLED.getKey();
byte[] data = zoo.getData(path, null);
boolean useWAL = Boolean.parseBoolean(new String(data, UTF_8));
zoo.recursiveDelete(path, NodeMissingPolicy.FAIL);
path = zooRoot + Constants.ZTABLES + "/" + id + Constants.ZTABLE_CONF + "/" + Property.TABLE_DURABILITY.getKey();
if (useWAL) {
if (flushDefault) {
zoo.putPersistentData(path, "flush".getBytes(), NodeExistsPolicy.SKIP);
} else {
zoo.putPersistentData(path, "sync".getBytes(), NodeExistsPolicy.SKIP);
}
} else {
zoo.putPersistentData(path, "none".getBytes(), NodeExistsPolicy.SKIP);
}
} catch (KeeperException.NoNodeException ex) {
// skip it
}
}
// create initial namespaces
String namespaces = ZooUtil.getRoot(getInstance()) + Constants.ZNAMESPACES;
zoo.putPersistentData(namespaces, new byte[0], NodeExistsPolicy.SKIP);
for (Pair<String, Namespace.ID> namespace : Iterables.concat(Collections.singleton(new Pair<>(Namespace.ACCUMULO, Namespace.ID.ACCUMULO)), Collections.singleton(new Pair<>(Namespace.DEFAULT, Namespace.ID.DEFAULT)))) {
String ns = namespace.getFirst();
Namespace.ID id = namespace.getSecond();
log.debug("Upgrade creating namespace \"{}\" (ID: {})", ns, id);
if (!Namespaces.exists(getInstance(), id))
TableManager.prepareNewNamespaceState(getInstance().getInstanceID(), id, ns, NodeExistsPolicy.SKIP);
}
// create replication table in zk
log.debug("Upgrade creating table {} (ID: {})", ReplicationTable.NAME, ReplicationTable.ID);
TableManager.prepareNewTableState(getInstance().getInstanceID(), ReplicationTable.ID, Namespace.ID.ACCUMULO, ReplicationTable.NAME, TableState.OFFLINE, NodeExistsPolicy.SKIP);
// create root table
log.debug("Upgrade creating table {} (ID: {})", RootTable.NAME, RootTable.ID);
TableManager.prepareNewTableState(getInstance().getInstanceID(), RootTable.ID, Namespace.ID.ACCUMULO, RootTable.NAME, TableState.ONLINE, NodeExistsPolicy.SKIP);
Initialize.initSystemTablesConfig();
// ensure root user can flush root table
security.grantTablePermission(rpcCreds(), security.getRootUsername(), RootTable.ID, TablePermission.ALTER_TABLE, Namespace.ID.ACCUMULO);
// put existing tables in the correct namespaces
String tables = ZooUtil.getRoot(getInstance()) + Constants.ZTABLES;
for (String tableId : zoo.getChildren(tables)) {
Namespace.ID targetNamespace = (MetadataTable.ID.canonicalID().equals(tableId) || RootTable.ID.canonicalID().equals(tableId)) ? Namespace.ID.ACCUMULO : Namespace.ID.DEFAULT;
log.debug("Upgrade moving table {} (ID: {}) into namespace with ID {}", new String(zoo.getData(tables + "/" + tableId + Constants.ZTABLE_NAME, null), UTF_8), tableId, targetNamespace);
zoo.putPersistentData(tables + "/" + tableId + Constants.ZTABLE_NAMESPACE, targetNamespace.getUtf8(), NodeExistsPolicy.SKIP);
}
// rename metadata table
log.debug("Upgrade renaming table {} (ID: {}) to {}", MetadataTable.OLD_NAME, MetadataTable.ID, MetadataTable.NAME);
zoo.putPersistentData(tables + "/" + MetadataTable.ID + Constants.ZTABLE_NAME, Tables.qualify(MetadataTable.NAME).getSecond().getBytes(UTF_8), NodeExistsPolicy.OVERWRITE);
moveRootTabletToRootTable(zoo);
// add system namespace permissions to existing users
ZKPermHandler perm = new ZKPermHandler();
perm.initialize(getInstance().getInstanceID(), true);
String users = ZooUtil.getRoot(getInstance()) + "/users";
for (String user : zoo.getChildren(users)) {
zoo.putPersistentData(users + "/" + user + "/Namespaces", new byte[0], NodeExistsPolicy.SKIP);
perm.grantNamespacePermission(user, Namespace.ID.ACCUMULO, NamespacePermission.READ);
}
perm.grantNamespacePermission("root", Namespace.ID.ACCUMULO, NamespacePermission.ALTER_TABLE);
// add the currlog location for root tablet current logs
zoo.putPersistentData(ZooUtil.getRoot(getInstance()) + RootTable.ZROOT_TABLET_CURRENT_LOGS, new byte[0], NodeExistsPolicy.SKIP);
// create tablet server wal logs node in ZK
zoo.putPersistentData(ZooUtil.getRoot(getInstance()) + WalStateManager.ZWALS, new byte[0], NodeExistsPolicy.SKIP);
haveUpgradedZooKeeper = true;
} catch (Exception ex) {
// ACCUMULO-3651 Changed level to error and added FATAL to message for slf4j compatibility
log.error("FATAL: Error performing upgrade", ex);
System.exit(1);
}
}
}
use of org.apache.accumulo.core.client.impl.Namespace in project accumulo by apache.
the class MasterClientServiceHandler method alterNamespaceProperty.
private void alterNamespaceProperty(TCredentials c, String namespace, String property, String value, TableOperation op) throws ThriftSecurityException, ThriftTableOperationException {
Namespace.ID namespaceId = null;
namespaceId = ClientServiceHandler.checkNamespaceId(master.getInstance(), namespace, op);
if (!master.security.canAlterNamespace(c, namespaceId))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
try {
if (value == null) {
NamespacePropUtil.removeNamespaceProperty(namespaceId, property);
} else {
NamespacePropUtil.setNamespaceProperty(namespaceId, property, value);
}
} catch (KeeperException.NoNodeException e) {
// race condition... namespace no longer exists? This call will throw an exception if the namespace was deleted:
ClientServiceHandler.checkNamespaceId(master.getInstance(), namespace, op);
log.info("Error altering namespace property", e);
throw new ThriftTableOperationException(namespaceId.canonicalID(), namespace, op, TableOperationExceptionType.OTHER, "Problem altering namespaceproperty");
} catch (Exception e) {
log.error("Problem altering namespace property", e);
throw new ThriftTableOperationException(namespaceId.canonicalID(), namespace, op, TableOperationExceptionType.OTHER, "Problem altering namespace property");
}
}
use of org.apache.accumulo.core.client.impl.Namespace in project accumulo by apache.
the class ClientServiceHandler method checkNamespaceId.
public static Namespace.ID checkNamespaceId(Instance instance, String namespaceName, TableOperation operation) throws ThriftTableOperationException {
Namespace.ID namespaceId = Namespaces.lookupNamespaceId(instance, namespaceName);
if (namespaceId == null) {
// maybe the namespace exists, but the cache was not updated yet... so try to clear the cache and check again
Tables.clearCache(instance);
namespaceId = Namespaces.lookupNamespaceId(instance, namespaceName);
if (namespaceId == null)
throw new ThriftTableOperationException(null, namespaceName, operation, TableOperationExceptionType.NAMESPACE_NOTFOUND, null);
}
return namespaceId;
}
use of org.apache.accumulo.core.client.impl.Namespace in project accumulo by apache.
the class ClientServiceHandler method getNamespaceConfiguration.
@Override
public Map<String, String> getNamespaceConfiguration(TInfo tinfo, TCredentials credentials, String ns) throws ThriftTableOperationException, TException {
Namespace.ID namespaceId;
try {
namespaceId = Namespaces.getNamespaceId(instance, ns);
} catch (NamespaceNotFoundException e) {
String why = "Could not find namespace while getting configuration.";
throw new ThriftTableOperationException(null, ns, null, TableOperationExceptionType.NAMESPACE_NOTFOUND, why);
}
AccumuloConfiguration config = context.getServerConfigurationFactory().getNamespaceConfiguration(namespaceId);
return conf(credentials, config);
}
use of org.apache.accumulo.core.client.impl.Namespace in project accumulo by apache.
the class ImportPopulateZookeeper method call.
@Override
public Repo<Master> call(long tid, Master env) throws Exception {
// reserve the table name in zookeeper or fail
Utils.tableNameLock.lock();
try {
// write tableName & tableId to zookeeper
Instance instance = env.getInstance();
Utils.checkTableDoesNotExist(instance, tableInfo.tableName, tableInfo.tableId, TableOperation.CREATE);
String namespace = Tables.qualify(tableInfo.tableName).getFirst();
Namespace.ID namespaceId = Namespaces.getNamespaceId(instance, namespace);
TableManager.getInstance().addTable(tableInfo.tableId, namespaceId, tableInfo.tableName, NodeExistsPolicy.OVERWRITE);
Tables.clearCache(instance);
} finally {
Utils.tableNameLock.unlock();
}
for (Entry<String, String> entry : getExportedProps(env.getFileSystem()).entrySet()) if (!TablePropUtil.setTableProperty(tableInfo.tableId, entry.getKey(), entry.getValue())) {
throw new AcceptableThriftTableOperationException(tableInfo.tableId.canonicalID(), tableInfo.tableName, TableOperation.IMPORT, TableOperationExceptionType.OTHER, "Invalid table property " + entry.getKey());
}
return new CreateImportDir(tableInfo);
}
Aggregations