Search in sources :

Example 1 with Namespace

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);
        }
    }
}
Also used : ZKPermHandler(org.apache.accumulo.server.security.handler.ZKPermHandler) Namespace(org.apache.accumulo.core.client.impl.Namespace) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NoAuthException(org.apache.zookeeper.KeeperException.NoAuthException) WalMarkerException(org.apache.accumulo.server.log.WalStateManager.WalMarkerException) TException(org.apache.thrift.TException) IOException(java.io.IOException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) TTransportException(org.apache.thrift.transport.TTransportException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) KeeperException(org.apache.zookeeper.KeeperException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) KeeperException(org.apache.zookeeper.KeeperException) Pair(org.apache.accumulo.core.util.Pair)

Example 2 with Namespace

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");
    }
}
Also used : NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) Namespace(org.apache.accumulo.core.client.impl.Namespace) KeeperException(org.apache.zookeeper.KeeperException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TabletDeletedException(org.apache.accumulo.server.util.TabletIterator.TabletDeletedException) KeeperException(org.apache.zookeeper.KeeperException) TException(org.apache.thrift.TException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException)

Example 3 with Namespace

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;
}
Also used : ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) Namespace(org.apache.accumulo.core.client.impl.Namespace)

Example 4 with Namespace

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);
}
Also used : ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) Namespace(org.apache.accumulo.core.client.impl.Namespace) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Example 5 with Namespace

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);
}
Also used : Instance(org.apache.accumulo.core.client.Instance) Namespace(org.apache.accumulo.core.client.impl.Namespace) AcceptableThriftTableOperationException(org.apache.accumulo.core.client.impl.AcceptableThriftTableOperationException)

Aggregations

Namespace (org.apache.accumulo.core.client.impl.Namespace)5 ThriftTableOperationException (org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException)4 AccumuloException (org.apache.accumulo.core.client.AccumuloException)2 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)2 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)2 TException (org.apache.thrift.TException)2 KeeperException (org.apache.zookeeper.KeeperException)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 IOException (java.io.IOException)1 Instance (org.apache.accumulo.core.client.Instance)1 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)1 AcceptableThriftTableOperationException (org.apache.accumulo.core.client.impl.AcceptableThriftTableOperationException)1 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)1 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)1 Pair (org.apache.accumulo.core.util.Pair)1 IZooReaderWriter (org.apache.accumulo.fate.zookeeper.IZooReaderWriter)1 WalMarkerException (org.apache.accumulo.server.log.WalStateManager.WalMarkerException)1 ZKPermHandler (org.apache.accumulo.server.security.handler.ZKPermHandler)1 TabletDeletedException (org.apache.accumulo.server.util.TabletIterator.TabletDeletedException)1 TTransportException (org.apache.thrift.transport.TTransportException)1