public static boolean setTableProperty(ZooReaderWriter zoo, String zkRoot, Table.ID tableId, String property, String value) throws KeeperException, InterruptedException { if (!isPropertyValid(property, value)) return false; // create the zk node for per-table properties for this table if it doesn't already exist String zkTablePath = getTablePath(zkRoot, tableId); zoo.putPersistentData(zkTablePath, new byte[0], NodeExistsPolicy.SKIP); // create the zk node for this property and set it's data to the specified value String zPath = zkTablePath + "/" + property; zoo.putPersistentData(zPath, value.getBytes(UTF_8), NodeExistsPolicy.OVERWRITE); return true; }
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());
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"); } }
if (!TablePropUtil.isPropertyValid(entry.getKey(), entry.getValue())) { throw new ThriftTableOperationException(null, tableName, tableOp, TableOperationExceptionType.OTHER,
public static void removeTableProperty(ServerContext context, Table.ID tableId, String property) throws InterruptedException, KeeperException { String zPath = getTablePath(context.getZooKeeperRoot(), tableId) + "/" + property; context.getZooReaderWriter().recursiveDelete(zPath, NodeMissingPolicy.SKIP); }
if (!TablePropUtil.isPropertyValid(entry.getKey(), entry.getValue())) { throw new ThriftTableOperationException(null, tableName, TableOperation.CLONE, TableOperationExceptionType.OTHER, "Property or value not valid " + entry.getKey() + "=" + entry.getValue());
public static void removeTableProperty(String tableId, String property) throws InterruptedException, KeeperException { String zPath = getTablePath(tableId) + "/" + property; ZooReaderWriter.getInstance().recursiveDelete(zPath, NodeMissingPolicy.SKIP); }
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 static boolean setTableProperty(String tableId, String property, String value) throws KeeperException, InterruptedException { if (!isPropertyValid(property, value)) return false; // create the zk node for per-table properties for this table if it doesn't already exist String zkTablePath = getTablePath(tableId); ZooReaderWriter.getInstance().putPersistentData(zkTablePath, new byte[0], NodeExistsPolicy.SKIP); // create the zk node for this property and set it's data to the specified value String zPath = zkTablePath + "/" + property; ZooReaderWriter.getInstance().putPersistentData(zPath, value.getBytes(UTF_8), NodeExistsPolicy.OVERWRITE); return true; }
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"); } }
if (!TablePropUtil.isPropertyValid(entry.getKey(), entry.getValue())) { throw new ThriftTableOperationException(null, tableName, tableOp, TableOperationExceptionType.OTHER,
public static void removeTableProperty(String tableId, String property) throws InterruptedException, KeeperException { String zPath = getTablePath(tableId) + "/" + property; ZooReaderWriter.getInstance().recursiveDelete(zPath, NodeMissingPolicy.SKIP); }
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); }
public static boolean setTableProperty(String tableId, String property, String value) throws KeeperException, InterruptedException { if (!isPropertyValid(property, value)) return false; // create the zk node for per-table properties for this table if it doesn't already exist String zkTablePath = getTablePath(tableId); ZooReaderWriter.getInstance().putPersistentData(zkTablePath, new byte[0], NodeExistsPolicy.SKIP); // create the zk node for this property and set it's data to the specified value String zPath = zkTablePath + "/" + property; ZooReaderWriter.getInstance().putPersistentData(zPath, value.getBytes(UTF_8), NodeExistsPolicy.OVERWRITE); return true; }
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"); } }
@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); }
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(); } }