Search in sources :

Example 1 with LeaseRecovery

use of org.apache.hadoop.hbase.procedure2.store.LeaseRecovery in project hbase by apache.

the class RegionProcedureStore method tryMigrate.

@SuppressWarnings("deprecation")
private void tryMigrate(FileSystem fs) throws IOException {
    Configuration conf = server.getConfiguration();
    Path procWALDir = new Path(CommonFSUtils.getWALRootDir(conf), WALProcedureStore.MASTER_PROCEDURE_LOGDIR);
    if (!fs.exists(procWALDir)) {
        return;
    }
    LOG.info("The old WALProcedureStore wal directory {} exists, migrating...", procWALDir);
    WALProcedureStore store = new WALProcedureStore(conf, leaseRecovery);
    store.start(numThreads);
    store.recoverLease();
    MutableLong maxProcIdSet = new MutableLong(-1);
    List<Procedure<?>> procs = new ArrayList<>();
    Map<Class<?>, List<Procedure<?>>> activeProcsByType = new HashMap<>();
    store.load(new ProcedureLoader() {

        @Override
        public void setMaxProcId(long maxProcId) {
            maxProcIdSet.setValue(maxProcId);
        }

        @Override
        public void load(ProcedureIterator procIter) throws IOException {
            while (procIter.hasNext()) {
                Procedure<?> proc = procIter.next();
                procs.add(proc);
                if (!proc.isFinished()) {
                    activeProcsByType.computeIfAbsent(proc.getClass(), k -> new ArrayList<>()).add(proc);
                }
            }
        }

        @Override
        public void handleCorrupted(ProcedureIterator procIter) throws IOException {
            long corruptedCount = 0;
            while (procIter.hasNext()) {
                LOG.error("Corrupted procedure {}", procIter.next());
                corruptedCount++;
            }
            if (corruptedCount > 0) {
                throw new IOException("There are " + corruptedCount + " corrupted procedures when" + " migrating from the old WAL based store to the new region based store, please" + " fix them before upgrading again.");
            }
        }
    });
    // check whether there are unsupported procedures, this could happen when we are migrating from
    // 2.1-. We used to do this in HMaster, after loading all the procedures from procedure store,
    // but here we have to do it before migrating, otherwise, if we find some unsupported
    // procedures, the users can not go back to 2.1 to finish them any more, as all the data are now
    // in the new region based procedure store, which is not supported in 2.1-.
    checkUnsupportedProcedure(activeProcsByType);
    MutableLong maxProcIdFromProcs = new MutableLong(-1);
    for (Procedure<?> proc : procs) {
        update(proc);
        if (proc.getProcId() > maxProcIdFromProcs.longValue()) {
            maxProcIdFromProcs.setValue(proc.getProcId());
        }
    }
    LOG.info("Migrated {} existing procedures from the old storage format.", procs.size());
    LOG.info("The WALProcedureStore max pid is {}, and the max pid of all loaded procedures is {}", maxProcIdSet.longValue(), maxProcIdFromProcs.longValue());
    // anyway, let's do a check here.
    if (maxProcIdSet.longValue() > maxProcIdFromProcs.longValue()) {
        if (maxProcIdSet.longValue() > 0) {
            // let's add a fake row to retain the max proc id
            region.update(r -> r.put(new Put(Bytes.toBytes(maxProcIdSet.longValue())).addColumn(PROC_FAMILY, PROC_QUALIFIER, EMPTY_BYTE_ARRAY)));
        }
    } else if (maxProcIdSet.longValue() < maxProcIdFromProcs.longValue()) {
        LOG.warn("The WALProcedureStore max pid is less than the max pid of all loaded procedures");
    }
    store.stop(false);
    if (!fs.delete(procWALDir, true)) {
        throw new IOException("Failed to delete the WALProcedureStore migrated proc wal directory " + procWALDir);
    }
    LOG.info("Migration of WALProcedureStore finished");
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) Put(org.apache.hadoop.hbase.client.Put) MutableLong(org.apache.commons.lang3.mutable.MutableLong) UnassignProcedure(org.apache.hadoop.hbase.master.assignment.UnassignProcedure) RecoverMetaProcedure(org.apache.hadoop.hbase.master.procedure.RecoverMetaProcedure) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) AssignProcedure(org.apache.hadoop.hbase.master.assignment.AssignProcedure) MoveRegionProcedure(org.apache.hadoop.hbase.master.assignment.MoveRegionProcedure) ServerCrashProcedure(org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure) ArrayList(java.util.ArrayList) List(java.util.List) WALProcedureStore(org.apache.hadoop.hbase.procedure2.store.wal.WALProcedureStore)

Example 2 with LeaseRecovery

use of org.apache.hadoop.hbase.procedure2.store.LeaseRecovery in project hbase by apache.

the class TestWALProcedureStore method testFileNotFoundDuringLeaseRecovery.

@Test
public void testFileNotFoundDuringLeaseRecovery() throws IOException {
    final TestProcedure[] procs = new TestProcedure[3];
    for (int i = 0; i < procs.length; ++i) {
        procs[i] = new TestProcedure(i + 1, 0);
        procStore.insert(procs[i], null);
    }
    procStore.rollWriterForTesting();
    for (int i = 0; i < procs.length; ++i) {
        procStore.update(procs[i]);
        procStore.rollWriterForTesting();
    }
    procStore.stop(false);
    FileStatus[] status = fs.listStatus(logDir);
    assertEquals(procs.length + 1, status.length);
    // simulate another active master removing the wals
    procStore = new WALProcedureStore(htu.getConfiguration(), logDir, null, new LeaseRecovery() {

        private int count = 0;

        @Override
        public void recoverFileLease(FileSystem fs, Path path) throws IOException {
            if (++count <= 2) {
                fs.delete(path, false);
                LOG.debug("Simulate FileNotFound at count=" + count + " for " + path);
                throw new FileNotFoundException("test file not found " + path);
            }
            LOG.debug("Simulate recoverFileLease() at count=" + count + " for " + path);
        }
    });
    final LoadCounter loader = new LoadCounter();
    procStore.start(PROCEDURE_STORE_SLOTS);
    procStore.recoverLease();
    procStore.load(loader);
    assertEquals(procs.length, loader.getMaxProcId());
    assertEquals(1, loader.getRunnableCount());
    assertEquals(0, loader.getCompletedCount());
    assertEquals(0, loader.getCorruptedCount());
}
Also used : Path(org.apache.hadoop.fs.Path) TestProcedure(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure) FileStatus(org.apache.hadoop.fs.FileStatus) LeaseRecovery(org.apache.hadoop.hbase.procedure2.store.LeaseRecovery) LoadCounter(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter) FileSystem(org.apache.hadoop.fs.FileSystem) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Example 3 with LeaseRecovery

use of org.apache.hadoop.hbase.procedure2.store.LeaseRecovery in project hbase by apache.

the class WALProcedureStore method main.

/**
 * Parses a directory of WALs building up ProcedureState.
 * For testing parse and profiling.
 * @param args Include pointer to directory of WAL files for a store instance to parse & load.
 */
public static void main(String[] args) throws IOException {
    Configuration conf = HBaseConfiguration.create();
    if (args == null || args.length != 1) {
        System.out.println("ERROR: Empty arguments list; pass path to MASTERPROCWALS_DIR.");
        System.out.println("Usage: WALProcedureStore MASTERPROCWALS_DIR");
        System.exit(-1);
    }
    WALProcedureStore store = new WALProcedureStore(conf, new Path(args[0]), null, new LeaseRecovery() {

        @Override
        public void recoverFileLease(FileSystem fs, Path path) throws IOException {
        // no-op
        }
    });
    try {
        store.start(16);
        ProcedureExecutor<?> pe = new ProcedureExecutor<>(conf, new Object(), /*Pass anything*/
        store);
        pe.init(1, true);
    } finally {
        store.stop(true);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) ProcedureExecutor(org.apache.hadoop.hbase.procedure2.ProcedureExecutor) LeaseRecovery(org.apache.hadoop.hbase.procedure2.store.LeaseRecovery) FileSystem(org.apache.hadoop.fs.FileSystem) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) IOException(java.io.IOException)

Example 4 with LeaseRecovery

use of org.apache.hadoop.hbase.procedure2.store.LeaseRecovery in project hbase by apache.

the class RegionProcedureStoreTestHelper method createStore.

static RegionProcedureStore createStore(Server server, MasterRegion region, ProcedureLoader loader) throws IOException {
    RegionProcedureStore store = new RegionProcedureStore(server, region, new LeaseRecovery() {

        @Override
        public void recoverFileLease(FileSystem fs, Path path) throws IOException {
        }
    });
    store.start(1);
    store.recoverLease();
    store.load(loader);
    return store;
}
Also used : Path(org.apache.hadoop.fs.Path) LeaseRecovery(org.apache.hadoop.hbase.procedure2.store.LeaseRecovery) FileSystem(org.apache.hadoop.fs.FileSystem) IOException(java.io.IOException)

Example 5 with LeaseRecovery

use of org.apache.hadoop.hbase.procedure2.store.LeaseRecovery in project hbase by apache.

the class TestRegionProcedureStoreMigration method setUp.

@Before
public void setUp() throws IOException {
    htu = new HBaseCommonTestingUtil();
    Configuration conf = htu.getConfiguration();
    conf.setBoolean(MemStoreLAB.USEMSLAB_KEY, false);
    // Runs on local filesystem. Test does not need sync. Turn off checks.
    conf.setBoolean(CommonFSUtils.UNSAFE_STREAM_CAPABILITY_ENFORCE, false);
    Path testDir = htu.getDataTestDir();
    CommonFSUtils.setRootDir(conf, testDir);
    walStore = new WALProcedureStore(conf, new LeaseRecovery() {

        @Override
        public void recoverFileLease(FileSystem fs, Path path) throws IOException {
        }
    });
    walStore.start(1);
    walStore.recoverLease();
    walStore.load(new LoadCounter());
    server = RegionProcedureStoreTestHelper.mockServer(conf);
    region = MasterRegionFactory.create(server);
}
Also used : Path(org.apache.hadoop.fs.Path) HBaseCommonTestingUtil(org.apache.hadoop.hbase.HBaseCommonTestingUtil) Configuration(org.apache.hadoop.conf.Configuration) LeaseRecovery(org.apache.hadoop.hbase.procedure2.store.LeaseRecovery) LoadCounter(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter) FileSystem(org.apache.hadoop.fs.FileSystem) WALProcedureStore(org.apache.hadoop.hbase.procedure2.store.wal.WALProcedureStore) Before(org.junit.Before)

Aggregations

Path (org.apache.hadoop.fs.Path)5 FileSystem (org.apache.hadoop.fs.FileSystem)4 LeaseRecovery (org.apache.hadoop.hbase.procedure2.store.LeaseRecovery)4 IOException (java.io.IOException)3 Configuration (org.apache.hadoop.conf.Configuration)3 LoadCounter (org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter)2 WALProcedureStore (org.apache.hadoop.hbase.procedure2.store.wal.WALProcedureStore)2 FileNotFoundException (java.io.FileNotFoundException)1 UncheckedIOException (java.io.UncheckedIOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 MutableLong (org.apache.commons.lang3.mutable.MutableLong)1 FileStatus (org.apache.hadoop.fs.FileStatus)1 HBaseCommonTestingUtil (org.apache.hadoop.hbase.HBaseCommonTestingUtil)1 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)1 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)1 Put (org.apache.hadoop.hbase.client.Put)1 AssignProcedure (org.apache.hadoop.hbase.master.assignment.AssignProcedure)1 MoveRegionProcedure (org.apache.hadoop.hbase.master.assignment.MoveRegionProcedure)1