setMetadataReplication(min, "min"); for (Entry<String,String> entry : initialMetadataConf.entrySet()) { if (!TablePropUtil.setTableProperty(zoo, zooKeeperRoot, RootTable.ID, entry.getKey(), entry.getValue())) throw new IOException("Cannot create per-table property " + entry.getKey()); if (!TablePropUtil.setTableProperty(zoo, zooKeeperRoot, MetadataTable.ID, entry.getKey(), entry.getValue())) throw new IOException("Cannot create per-table property " + entry.getKey()); if (!TablePropUtil.setTableProperty(zoo, zooKeeperRoot, MetadataTable.ID, entry.getKey(), entry.getValue())) throw new IOException("Cannot create per-table property " + entry.getKey()); if (!TablePropUtil.setTableProperty(zoo, zooKeeperRoot, ReplicationTable.ID, entry.getKey(), entry.getValue())) throw new IOException("Cannot create per-table property " + entry.getKey());
public static boolean setTableProperty(ServerContext context, Table.ID tableId, String property, String value) throws KeeperException, InterruptedException { return setTableProperty(context.getZooReaderWriter(), context.getZooKeeperRoot(), tableId, property, value); }
public void cloneTable(Table.ID srcTableId, Table.ID tableId, String tableName, Namespace.ID namespaceId, Map<String,String> propertiesToSet, Set<String> propertiesToExclude, NodeExistsPolicy existsPolicy) throws KeeperException, InterruptedException { prepareNewTableState(zoo, instanceID, tableId, namespaceId, tableName, TableState.NEW, existsPolicy); String srcTablePath = Constants.ZROOT + "/" + instanceID + Constants.ZTABLES + "/" + srcTableId + Constants.ZTABLE_CONF; String newTablePath = Constants.ZROOT + "/" + instanceID + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_CONF; zoo.recursiveCopyPersistent(srcTablePath, newTablePath, NodeExistsPolicy.OVERWRITE); for (Entry<String,String> entry : propertiesToSet.entrySet()) TablePropUtil.setTableProperty(context, tableId, entry.getKey(), entry.getValue()); for (String prop : propertiesToExclude) zoo.recursiveDelete(Constants.ZROOT + "/" + instanceID + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_CONF + "/" + prop, NodeMissingPolicy.SKIP); updateTableStateCache(tableId); }
@Override public Repo<Master> call(long tid, Master master) throws Exception { // reserve the table name in zookeeper or fail Utils.getTableNameLock().lock(); try { // write tableName & tableId to zookeeper Utils.checkTableDoesNotExist(master.getContext(), tableInfo.getTableName(), tableInfo.getTableId(), TableOperation.CREATE); master.getTableManager().addTable(tableInfo.getTableId(), tableInfo.getNamespaceId(), tableInfo.getTableName(), NodeExistsPolicy.OVERWRITE); for (Entry<String,String> entry : tableInfo.props.entrySet()) TablePropUtil.setTableProperty(master.getContext(), tableInfo.getTableId(), entry.getKey(), entry.getValue()); Tables.clearCache(master.getContext()); return new ChooseDir(tableInfo); } finally { Utils.getTableNameLock().unlock(); } }
@Override public Repo<Master> call(long tid, Master env) throws Exception { // reserve the table name in zookeeper or fail Utils.getTableNameLock().lock(); try { // write tableName & tableId to zookeeper Utils.checkTableDoesNotExist(env.getContext(), tableInfo.tableName, tableInfo.tableId, TableOperation.CREATE); String namespace = Tables.qualify(tableInfo.tableName).getFirst(); Namespace.ID namespaceId = Namespaces.getNamespaceId(env.getContext(), namespace); env.getTableManager().addTable(tableInfo.tableId, namespaceId, tableInfo.tableName, NodeExistsPolicy.OVERWRITE); Tables.clearCache(env.getContext()); } finally { Utils.getTableNameLock().unlock(); } for (Entry<String,String> entry : getExportedProps(env.getFileSystem()).entrySet()) if (!TablePropUtil.setTableProperty(env.getContext(), 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); }
private void alterTableProperty(TCredentials c, String tableName, String property, String value, TableOperation op) throws ThriftSecurityException, ThriftTableOperationException { final Table.ID tableId = ClientServiceHandler.checkTableId(master.getContext(), tableName, op); Namespace.ID namespaceId = getNamespaceIdFromTableId(op, tableId); if (!master.security.canAlterTable(c, tableId, namespaceId)) throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED); try { if (value == null || value.isEmpty()) { TablePropUtil.removeTableProperty(master.getContext(), tableId, property); } else if (!TablePropUtil.setTableProperty(master.getContext(), tableId, property, value)) { throw new Exception("Invalid table property."); } } catch (KeeperException.NoNodeException e) { // race condition... table no longer exists? This call will throw an exception if the table // was deleted: ClientServiceHandler.checkTableId(master.getContext(), tableName, op); log.info("Error altering table property", e); throw new ThriftTableOperationException(tableId.canonicalID(), tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property"); } catch (Exception e) { log.error("Problem altering table property", e); throw new ThriftTableOperationException(tableId.canonicalID(), tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property"); } }
protected static void initMetadataConfig() throws IOException { try { Configuration conf = CachedConfiguration.getInstance(); int max = conf.getInt("dfs.replication.max", 512); // Hadoop 0.23 switched the min value configuration name int min = Math.max(conf.getInt("dfs.replication.min", 1), conf.getInt("dfs.namenode.replication.min", 1)); if (max < 5) setMetadataReplication(max, "max"); if (min > 5) setMetadataReplication(min, "min"); for (Entry<String,String> entry : initialMetadataConf.entrySet()) if (!TablePropUtil.setTableProperty(Constants.METADATA_TABLE_ID, entry.getKey(), entry.getValue())) throw new IOException("Cannot create per-table property " + entry.getKey()); } catch (Exception e) { log.fatal("error talking to zookeeper", e); throw new IOException(e); } }
setMetadataReplication(min, "min"); for (Entry<String,String> entry : initialMetadataConf.entrySet()) { if (!TablePropUtil.setTableProperty(RootTable.ID, entry.getKey(), entry.getValue())) throw new IOException("Cannot create per-table property " + entry.getKey()); if (!TablePropUtil.setTableProperty(MetadataTable.ID, entry.getKey(), entry.getValue())) throw new IOException("Cannot create per-table property " + entry.getKey()); if (!TablePropUtil.setTableProperty(MetadataTable.ID, entry.getKey(), entry.getValue())) throw new IOException("Cannot create per-table property " + entry.getKey()); if (!TablePropUtil.setTableProperty(ReplicationTable.ID, entry.getKey(), entry.getValue())) throw new IOException("Cannot create per-table property " + entry.getKey());
@Override public Repo<Master> call(long tid, Master master) throws Exception { // reserve the table name in zookeeper or fail Utils.tableNameLock.lock(); try { // write tableName & tableId to zookeeper Instance instance = master.getInstance(); Utils.checkTableDoesNotExist(instance, tableInfo.tableName, tableInfo.tableId, TableOperation.CREATE); TableManager.getInstance().addTable(tableInfo.tableId, tableInfo.tableName, NodeExistsPolicy.OVERWRITE); for (Entry<String,String> entry : tableInfo.props.entrySet()) TablePropUtil.setTableProperty(tableInfo.tableId, entry.getKey(), entry.getValue()); Tables.clearCache(instance); return new CreateDir(tableInfo); } finally { Utils.tableNameLock.unlock(); } }
@Override public Repo<Master> call(long tid, Master master) throws Exception { // reserve the table name in zookeeper or fail Utils.tableNameLock.lock(); try { // write tableName & tableId to zookeeper Instance instance = master.getInstance(); Utils.checkTableDoesNotExist(instance, tableInfo.tableName, tableInfo.tableId, TableOperation.CREATE); TableManager.getInstance().addTable(tableInfo.tableId, tableInfo.namespaceId, tableInfo.tableName, NodeExistsPolicy.OVERWRITE); for (Entry<String,String> entry : tableInfo.props.entrySet()) TablePropUtil.setTableProperty(tableInfo.tableId, entry.getKey(), entry.getValue()); Tables.clearCache(instance); return new ChooseDir(tableInfo); } finally { Utils.tableNameLock.unlock(); } }
@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 = HdfsZooInstance.getInstance(); Utils.checkTableDoesNotExist(instance, tableInfo.tableName, tableInfo.tableId, TableOperation.CREATE); TableManager.getInstance().addTable(tableInfo.tableId, 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 ThriftTableOperationException(tableInfo.tableId, tableInfo.tableName, TableOperation.IMPORT, TableOperationExceptionType.OTHER, "Invalid table property " + entry.getKey()); } return new CreateImportDir(tableInfo); }
private void alterTableProperty(TCredentials c, String tableName, String property, String value, TableOperation op) throws ThriftSecurityException, ThriftTableOperationException { final String tableId = checkTableId(tableName, op); if (!security.canAlterTable(c, tableId)) throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED); try { if (value == null || value.isEmpty()) { TablePropUtil.removeTableProperty(tableId, property); } else if (!TablePropUtil.setTableProperty(tableId, property, value)) { throw new Exception("Invalid table property."); } } catch (KeeperException.NoNodeException e) { // race condition... table no longer exists? This call will throw an exception if the table was deleted: checkTableId(tableName, op); log.info("Error altering table property", e); throw new ThriftTableOperationException(tableId, tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property"); } catch (Exception e) { log.error("Problem altering table property", e); throw new ThriftTableOperationException(tableId, tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property"); } }
public void cloneTable(String srcTable, String tableId, String tableName, Map<String,String> propertiesToSet, Set<String> propertiesToExclude, NodeExistsPolicy existsPolicy) throws KeeperException, InterruptedException { prepareNewTableState(instance.getInstanceID(), tableId, tableName, TableState.NEW, existsPolicy); String srcTablePath = Constants.ZROOT + "/" + instance.getInstanceID() + Constants.ZTABLES + "/" + srcTable + Constants.ZTABLE_CONF; String newTablePath = Constants.ZROOT + "/" + instance.getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_CONF; ZooReaderWriter.getRetryingInstance().recursiveCopyPersistent(srcTablePath, newTablePath, NodeExistsPolicy.OVERWRITE); for (Entry<String,String> entry : propertiesToSet.entrySet()) TablePropUtil.setTableProperty(tableId, entry.getKey(), entry.getValue()); for (String prop : propertiesToExclude) ZooReaderWriter.getRetryingInstance().recursiveDelete( Constants.ZROOT + "/" + instance.getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_CONF + "/" + prop, NodeMissingPolicy.SKIP); updateTableStateCache(tableId); }
@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(); String 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, tableInfo.tableName, TableOperation.IMPORT, TableOperationExceptionType.OTHER, "Invalid table property " + entry.getKey()); } return new CreateImportDir(tableInfo); }
public void cloneTable(String srcTable, String tableId, String tableName, String namespaceId, Map<String,String> propertiesToSet, Set<String> propertiesToExclude, NodeExistsPolicy existsPolicy) throws KeeperException, InterruptedException { prepareNewTableState(instance.getInstanceID(), tableId, namespaceId, tableName, TableState.NEW, existsPolicy); String srcTablePath = Constants.ZROOT + "/" + instance.getInstanceID() + Constants.ZTABLES + "/" + srcTable + Constants.ZTABLE_CONF; String newTablePath = Constants.ZROOT + "/" + instance.getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_CONF; ZooReaderWriter.getInstance().recursiveCopyPersistent(srcTablePath, newTablePath, NodeExistsPolicy.OVERWRITE); for (Entry<String,String> entry : propertiesToSet.entrySet()) TablePropUtil.setTableProperty(tableId, entry.getKey(), entry.getValue()); for (String prop : propertiesToExclude) ZooReaderWriter.getInstance().recursiveDelete(Constants.ZROOT + "/" + instance.getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_CONF + "/" + prop, NodeMissingPolicy.SKIP); updateTableStateCache(tableId); }
private void alterTableProperty(TCredentials c, String tableName, String property, String value, TableOperation op) throws ThriftSecurityException, ThriftTableOperationException { final String tableId = ClientServiceHandler.checkTableId(master.getInstance(), tableName, op); String namespaceId = getNamespaceIdFromTableId(op, tableId); if (!master.security.canAlterTable(c, tableId, namespaceId)) throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED); try { if (value == null || value.isEmpty()) { TablePropUtil.removeTableProperty(tableId, property); } else if (!TablePropUtil.setTableProperty(tableId, property, value)) { throw new Exception("Invalid table property."); } } catch (KeeperException.NoNodeException e) { // race condition... table no longer exists? This call will throw an exception if the table // was deleted: ClientServiceHandler.checkTableId(master.getInstance(), tableName, op); log.info("Error altering table property", e); throw new ThriftTableOperationException(tableId, tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property"); } catch (Exception e) { log.error("Problem altering table property", e); throw new ThriftTableOperationException(tableId, tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property"); } }