Search in sources :

Example 1 with MetricsSnapshot

use of org.apache.hadoop.hbase.master.MetricsSnapshot in project hbase by apache.

the class CloneSnapshotProcedure method executeFromState.

@Override
protected Flow executeFromState(final MasterProcedureEnv env, final CloneSnapshotState state) throws InterruptedException {
    LOG.trace("{} execute state={}", this, state);
    try {
        switch(state) {
            case CLONE_SNAPSHOT_PRE_OPERATION:
                // Verify if we can clone the table
                prepareClone(env);
                preCloneSnapshot(env);
                setNextState(CloneSnapshotState.CLONE_SNAPSHOT_WRITE_FS_LAYOUT);
                break;
            case CLONE_SNAPSHOT_WRITE_FS_LAYOUT:
                updateTableDescriptorWithSFT();
                newRegions = createFilesystemLayout(env, tableDescriptor, newRegions);
                env.getMasterServices().getTableDescriptors().update(tableDescriptor, true);
                setNextState(CloneSnapshotState.CLONE_SNAPSHOT_ADD_TO_META);
                break;
            case CLONE_SNAPSHOT_ADD_TO_META:
                addRegionsToMeta(env);
                setNextState(CloneSnapshotState.CLONE_SNAPSHOT_ASSIGN_REGIONS);
                break;
            case CLONE_SNAPSHOT_ASSIGN_REGIONS:
                CreateTableProcedure.setEnablingState(env, getTableName());
                // Separate newRegions to split regions and regions to assign
                List<RegionInfo> splitRegions = new ArrayList<>();
                List<RegionInfo> regionsToAssign = new ArrayList<>();
                newRegions.forEach(ri -> {
                    if (ri.isOffline() && (ri.isSplit() || ri.isSplitParent())) {
                        splitRegions.add(ri);
                    } else {
                        regionsToAssign.add(ri);
                    }
                });
                // For split regions, add them to RegionStates
                AssignmentManager am = env.getAssignmentManager();
                splitRegions.forEach(ri -> am.getRegionStates().updateRegionState(ri, RegionState.State.SPLIT));
                addChildProcedure(env.getAssignmentManager().createRoundRobinAssignProcedures(regionsToAssign));
                setNextState(CloneSnapshotState.CLONE_SNAPSHOT_UPDATE_DESC_CACHE);
                break;
            case CLONE_SNAPSHOT_UPDATE_DESC_CACHE:
                // XXX: this stage should be named as set table enabled, as now we will cache the
                // descriptor after writing fs layout.
                CreateTableProcedure.setEnabledState(env, getTableName());
                setNextState(CloneSnapshotState.CLONE_SNAPHOST_RESTORE_ACL);
                break;
            case CLONE_SNAPHOST_RESTORE_ACL:
                restoreSnapshotAcl(env);
                setNextState(CloneSnapshotState.CLONE_SNAPSHOT_POST_OPERATION);
                break;
            case CLONE_SNAPSHOT_POST_OPERATION:
                postCloneSnapshot(env);
                MetricsSnapshot metricsSnapshot = new MetricsSnapshot();
                metricsSnapshot.addSnapshotClone(getMonitorStatus().getCompletionTimestamp() - getMonitorStatus().getStartTime());
                getMonitorStatus().markComplete("Clone snapshot '" + snapshot.getName() + "' completed!");
                return Flow.NO_MORE_STATE;
            default:
                throw new UnsupportedOperationException("unhandled state=" + state);
        }
    } catch (IOException e) {
        if (isRollbackSupported(state)) {
            setFailure("master-clone-snapshot", e);
        } else {
            LOG.warn("Retriable error trying to clone snapshot=" + snapshot.getName() + " to table=" + getTableName() + " state=" + state, e);
        }
    }
    return Flow.HAS_MORE_STATE;
}
Also used : MetricsSnapshot(org.apache.hadoop.hbase.master.MetricsSnapshot) ArrayList(java.util.ArrayList) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException)

Example 2 with MetricsSnapshot

use of org.apache.hadoop.hbase.master.MetricsSnapshot in project hbase by apache.

the class RestoreSnapshotProcedure method updateMETA.

/**
 * Apply changes to hbase:meta
 */
private void updateMETA(final MasterProcedureEnv env) throws IOException {
    try {
        Connection conn = env.getMasterServices().getConnection();
        RegionStateStore regionStateStore = env.getAssignmentManager().getRegionStateStore();
        int regionReplication = modifiedTableDescriptor.getRegionReplication();
        // 1. Prepare to restore
        getMonitorStatus().setStatus("Preparing to restore each region");
        // that are not correct after the restore.
        if (regionsToRemove != null) {
            regionStateStore.deleteRegions(regionsToRemove);
            deleteRegionsFromInMemoryStates(regionsToRemove, env, regionReplication);
        }
        // in the snapshot folder.
        if (regionsToAdd != null) {
            MetaTableAccessor.addRegionsToMeta(conn, regionsToAdd, regionReplication);
            addRegionsToInMemoryStates(regionsToAdd, env, regionReplication);
        }
        if (regionsToRestore != null) {
            regionStateStore.overwriteRegions(regionsToRestore, regionReplication);
            deleteRegionsFromInMemoryStates(regionsToRestore, env, regionReplication);
            addRegionsToInMemoryStates(regionsToRestore, env, regionReplication);
        }
        RestoreSnapshotHelper.RestoreMetaChanges metaChanges = new RestoreSnapshotHelper.RestoreMetaChanges(modifiedTableDescriptor, parentsToChildrenPairMap);
        metaChanges.updateMetaParentRegions(conn, regionsToAdd);
        // At this point the restore is complete.
        LOG.info("Restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot) + " on table=" + getTableName() + " completed!");
    } catch (IOException e) {
        final ForeignExceptionDispatcher monitorException = new ForeignExceptionDispatcher();
        String msg = "restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot) + " failed in meta update. Try re-running the restore command.";
        LOG.error(msg, e);
        monitorException.receive(new ForeignException(env.getMasterServices().getServerName().toString(), e));
        throw new IOException(msg, e);
    }
    monitorStatus.markComplete("Restore snapshot '" + snapshot.getName() + "'!");
    MetricsSnapshot metricsSnapshot = new MetricsSnapshot();
    metricsSnapshot.addSnapshotRestore(monitorStatus.getCompletionTimestamp() - monitorStatus.getStartTime());
}
Also used : RegionStateStore(org.apache.hadoop.hbase.master.assignment.RegionStateStore) MetricsSnapshot(org.apache.hadoop.hbase.master.MetricsSnapshot) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) Connection(org.apache.hadoop.hbase.client.Connection) RestoreSnapshotHelper(org.apache.hadoop.hbase.snapshot.RestoreSnapshotHelper) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) ForeignExceptionDispatcher(org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher)

Aggregations

IOException (java.io.IOException)2 MetricsSnapshot (org.apache.hadoop.hbase.master.MetricsSnapshot)2 ArrayList (java.util.ArrayList)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)1 Connection (org.apache.hadoop.hbase.client.Connection)1 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)1 ForeignException (org.apache.hadoop.hbase.errorhandling.ForeignException)1 ForeignExceptionDispatcher (org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher)1 AssignmentManager (org.apache.hadoop.hbase.master.assignment.AssignmentManager)1 RegionStateStore (org.apache.hadoop.hbase.master.assignment.RegionStateStore)1 RestoreSnapshotHelper (org.apache.hadoop.hbase.snapshot.RestoreSnapshotHelper)1