private void enableMeta(TableName metaTableName) { if (!this.assignmentManager.getTableStateManager().isTableState(metaTableName, ZooKeeperProtos.Table.State.ENABLED)) { this.assignmentManager.setEnabledTable(metaTableName); } }
static void removeEnablingTable(final AssignmentManager assignmentManager, final TableName tableName) { // Try deleting the enabling node in case of error // If this does not happen then if the client tries to create the table // again with the same Active master // It will block the creation saying TableAlreadyExists. try { assignmentManager.getTableStateManager().checkAndRemoveTableState(tableName, ZooKeeperProtos.Table.State.ENABLING, false); } catch (CoordinatedStateException e) { // Keeper exception should not happen here LOG.error("Got a keeper exception while removing the ENABLING table znode " + tableName, e); } }
/** * Mark table state to Disabling * @param env MasterProcedureEnv * @throws IOException */ protected static void setTableStateToDisabling( final MasterProcedureEnv env, final TableName tableName) throws HBaseException, IOException { // Set table disabling flag up in zk. env.getMasterServices().getAssignmentManager().getTableStateManager().setTableState( tableName, ZooKeeperProtos.Table.State.DISABLING); }
protected static void assignRegions(final MasterProcedureEnv env, final TableName tableName, final List<HRegionInfo> regions) throws HBaseException, IOException { ProcedureSyncWait.waitRegionServers(env); final AssignmentManager assignmentManager = env.getMasterServices().getAssignmentManager(); // Mark the table as Enabling assignmentManager.getTableStateManager().setTableState(tableName, ZooKeeperProtos.Table.State.ENABLING); // Trigger immediate assignment of the regions in round-robin fashion ModifyRegionUtils.assignRegions(assignmentManager, regions); // Enable table assignmentManager.getTableStateManager() .setTableState(tableName, ZooKeeperProtos.Table.State.ENABLED); }
/** * Rollback of table state change in prepareDisable() * @param env MasterProcedureEnv */ @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="REC_CATCH_EXCEPTION", justification="Intended") private void undoTableStateChange(final MasterProcedureEnv env) { if (!skipTableStateCheck) { try { // If the state was changed, undo it. if (env.getMasterServices().getAssignmentManager().getTableStateManager().isTableState( tableName, ZooKeeperProtos.Table.State.DISABLING)) { EnableTableProcedure.setTableStateToEnabled(env, tableName); } } catch (Exception e) { // Ignore exception. LOG.trace(e.getMessage()); } } }
/** * Mark table state to Enabled * @param env MasterProcedureEnv * @throws IOException */ protected static void setTableStateToEnabled( final MasterProcedureEnv env, final TableName tableName) throws HBaseException, IOException { // Flip the table to Enabled env.getMasterServices().getAssignmentManager().getTableStateManager().setTableState( tableName, ZooKeeperProtos.Table.State.ENABLED); LOG.info("Table '" + tableName + "' was successfully enabled."); }
/** * Mark table state to Disabled * @param env MasterProcedureEnv * @throws IOException */ protected static void setTableStateToDisabled( final MasterProcedureEnv env, final TableName tableName) throws HBaseException, IOException { // Flip the table to disabled env.getMasterServices().getAssignmentManager().getTableStateManager().setTableState( tableName, ZooKeeperProtos.Table.State.DISABLED); LOG.info("Disabled table, " + tableName + ", is completed."); }
/** * Mark table state to Enabling * @param env MasterProcedureEnv * @param tableName the target table * @throws IOException */ protected static void setTableStateToEnabling( final MasterProcedureEnv env, final TableName tableName) throws HBaseException, IOException { // Set table disabling flag up in zk. LOG.info("Attempting to enable the table " + tableName); env.getMasterServices().getAssignmentManager().getTableStateManager().setTableState( tableName, ZooKeeperProtos.Table.State.ENABLING); }
private void onRegionClosed(final HRegionInfo hri) { if (getTableStateManager().isTableState(hri.getTable(), ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING) || replicasToClose.contains(hri)) { offlineDisabledRegion(hri); return; } regionStates.updateRegionState(hri, RegionState.State.CLOSED); sendRegionClosedNotification(hri); // This below has to do w/ online enable/disable of a table removeClosedRegion(hri); invokeAssign(hri, false); }
@Override public void checkTableModifiable(final TableName tableName) throws IOException, TableNotFoundException, TableNotDisabledException { if (isCatalogTable(tableName)) { throw new IOException("Can't modify catalog tables"); } if (!MetaTableAccessor.tableExists(getConnection(), tableName)) { throw new TableNotFoundException(tableName); } if (!getAssignmentManager().getTableStateManager(). isTableState(tableName, ZooKeeperProtos.Table.State.DISABLED)) { throw new TableNotDisabledException(tableName); } }
private void onRegionOpen(final HRegionInfo hri, final ServerName sn, long openSeqNum) { regionOnline(hri, sn, openSeqNum); if (useZKForAssignment) { try { // Delete the ZNode if exists ZKAssign.deleteNodeFailSilent(watcher, hri); } catch (KeeperException ke) { server.abort("Unexpected ZK exception deleting node " + hri, ke); } } // reset the count, if any failedOpenTracker.remove(hri.getEncodedName()); if (getTableStateManager().isTableState(hri.getTable(), ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING)) { invokeUnAssign(hri); } }
protected static void deleteAssignmentState(final MasterProcedureEnv env, final TableName tableName) throws HBaseException, IOException { AssignmentManager am = env.getMasterServices().getAssignmentManager(); // Clean up regions of the table in RegionStates. LOG.debug("Removing '" + tableName + "' from region states."); am.getRegionStates().tableDeleted(tableName); // If entry for this table states, remove it. LOG.debug("Marking '" + tableName + "' as deleted."); am.getTableStateManager().setDeletedTable(tableName); }
@Override public void process() { LOG.debug("Handling CLOSED event for " + regionInfo.getEncodedName()); // Check if this table is being disabled or not if (this.assignmentManager.getTableStateManager().isTableState(this.regionInfo.getTable(), ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING) || assignmentManager.getReplicasToClose().contains(regionInfo)) { assignmentManager.offlineDisabledRegion(regionInfo); return; } // ZK Node is in CLOSED state, assign it. assignmentManager.getRegionStates().updateRegionState( regionInfo, RegionState.State.CLOSED); // This below has to do w/ online enable/disable of a table assignmentManager.removeClosedRegion(regionInfo); assignmentManager.assign(regionInfo, true); } }
private String onRegionSplitReverted(ServerName sn, final HRegionInfo p, final HRegionInfo a, final HRegionInfo b) { String s = checkInStateForSplit(sn, p, a, b); if (!com.facebook.presto.hbase.$internal.org.apache.commons.lang.StringUtils.isEmpty(s)) { return s; } regionOnline(p, sn); regionOffline(a); regionOffline(b); if (getTableStateManager().isTableState(p.getTable(), ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING)) { invokeUnAssign(p); } return null; }
/** * Check whether a table is modifiable - exists and either offline or online with config set * @param env MasterProcedureEnv * @param tableName name of the table * @throws IOException */ public static void checkTableModifiable(final MasterProcedureEnv env, final TableName tableName) throws IOException { // Checks whether the table exists if (!MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), tableName)) { throw new TableNotFoundException(tableName); } // We only execute this procedure with table online if online schema change config is set. if (!env.getMasterServices().getAssignmentManager().getTableStateManager() .isTableState(tableName, ZooKeeperProtos.Table.State.DISABLED) && !MasterDDLOperationHelper.isOnlineSchemaChangeAllowed(env)) { throw new TableNotDisabledException(tableName); } }
/** * Last action from the procedure - executed when online schema change is supported. * @param env MasterProcedureEnv * @throws IOException */ private void reOpenAllRegionsIfTableIsOnline(final MasterProcedureEnv env) throws IOException { // This operation only run when the table is enabled. if (!env.getMasterServices().getAssignmentManager().getTableStateManager() .isTableState(getTableName(), ZooKeeperProtos.Table.State.ENABLED)) { return; } if (MasterDDLOperationHelper.reOpenAllRegions(env, getTableName(), getRegionInfoList(env))) { LOG.info("Completed delete column family operation on table " + getTableName()); } else { LOG.warn("Error on reopening the regions on table " + getTableName()); } }
/** * Last action from the procedure - executed when online schema change is supported. * @param env MasterProcedureEnv * @throws IOException */ private void reOpenAllRegionsIfTableIsOnline(final MasterProcedureEnv env) throws IOException { // This operation only run when the table is enabled. if (!env.getMasterServices().getAssignmentManager().getTableStateManager() .isTableState(getTableName(), ZooKeeperProtos.Table.State.ENABLED)) { return; } if (MasterDDLOperationHelper.reOpenAllRegions(env, getTableName(), getRegionInfoList(env))) { LOG.info("Completed modify table operation on table " + getTableName()); } else { LOG.warn("Error on reopening the regions on table " + getTableName()); } }
/** * Last action from the procedure - executed when online schema change is supported. * @param env MasterProcedureEnv * @throws IOException */ private void reOpenAllRegionsIfTableIsOnline(final MasterProcedureEnv env) throws IOException { // This operation only run when the table is enabled. if (!env.getMasterServices().getAssignmentManager().getTableStateManager() .isTableState(getTableName(), ZooKeeperProtos.Table.State.ENABLED)) { return; } if (MasterDDLOperationHelper.reOpenAllRegions(env, getTableName(), getRegionInfoList(env))) { LOG.info("Completed add column family operation on table " + getTableName()); } else { LOG.warn("Error on reopening the regions on table " + getTableName()); } }
/** * Last action from the procedure - executed when online schema change is supported. * @param env MasterProcedureEnv * @throws IOException */ private void reOpenAllRegionsIfTableIsOnline(final MasterProcedureEnv env) throws IOException { // This operation only run when the table is enabled. if (!env.getMasterServices().getAssignmentManager().getTableStateManager() .isTableState(getTableName(), ZooKeeperProtos.Table.State.ENABLED)) { return; } List<HRegionInfo> regionInfoList = ProcedureSyncWait.getRegionsFromMeta(env, getTableName()); if (MasterDDLOperationHelper.reOpenAllRegions(env, getTableName(), regionInfoList)) { LOG.info("Completed add column family operation on table " + getTableName()); } else { LOG.warn("Error on reopening the regions on table " + getTableName()); } }
private boolean prepareCreate(final MasterProcedureEnv env) throws IOException { final TableName tableName = getTableName(); if (MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), tableName)) { setFailure("master-create-table", new TableExistsException(getTableName())); return false; } // During master initialization, the ZK state could be inconsistent from failed DDL // in the past. If we fail here, it would prevent master to start. We should force // setting the system table state regardless the table state. boolean skipTableStateCheck = !(env.getMasterServices().isInitialized()) && tableName.isSystemTable(); if (!skipTableStateCheck) { TableStateManager tsm = env.getMasterServices().getAssignmentManager().getTableStateManager(); if (tsm.isTableState(tableName, true, ZooKeeperProtos.Table.State.ENABLING, ZooKeeperProtos.Table.State.ENABLED)) { LOG.warn("The table " + tableName + " does not exist in meta but has a znode. " + "run hbck to fix inconsistencies."); setFailure("master-create-table", new TableExistsException(getTableName())); return false; } } return true; }