Search in sources :

Example 11 with MasterProcedureEnv

use of org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv in project hbase by apache.

the class TestDirectStoreSplitsMerges method testCommitDaughterRegionNoFiles.

@Test
public void testCommitDaughterRegionNoFiles() throws Exception {
    TableName table = TableName.valueOf(name.getMethodName());
    TEST_UTIL.createTable(table, FAMILY_NAME);
    HRegion region = TEST_UTIL.getHBaseCluster().getRegions(table).get(0);
    HRegionFileSystem regionFS = region.getStores().get(0).getRegionFileSystem();
    RegionInfo daughterA = RegionInfoBuilder.newBuilder(table).setStartKey(region.getRegionInfo().getStartKey()).setEndKey(Bytes.toBytes("002")).setSplit(false).setRegionId(region.getRegionInfo().getRegionId() + EnvironmentEdgeManager.currentTime()).build();
    Path splitDir = regionFS.getSplitsDir(daughterA);
    MasterProcedureEnv env = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getEnvironment();
    Path result = regionFS.commitDaughterRegion(daughterA, new ArrayList<>(), env);
    assertEquals(splitDir, result);
}
Also used : Path(org.apache.hadoop.fs.Path) TableName(org.apache.hadoop.hbase.TableName) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) Test(org.junit.Test)

Example 12 with MasterProcedureEnv

use of org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv in project hbase by apache.

the class TestMetaFixer method testOverlap.

@Test
public void testOverlap() throws Exception {
    TableName tn = TableName.valueOf(this.name.getMethodName());
    testOverlapCommon(tn);
    HMaster services = TEST_UTIL.getHBaseCluster().getMaster();
    HbckChore hbckChore = services.getHbckChore();
    CatalogJanitor cj = services.getCatalogJanitor();
    cj.scan();
    Report report = cj.getLastReport();
    assertEquals(6, report.getOverlaps().size());
    assertEquals(1, MetaFixer.calculateMerges(10, report.getOverlaps()).size());
    MetaFixer fixer = new MetaFixer(services);
    fixer.fixOverlaps(report);
    HBaseTestingUtil.await(10, () -> {
        try {
            if (cj.scan() > 0) {
                // It submits GC once, then it will immediately kick off another GC to test if
                // GCMultipleMergedRegionsProcedure is idempotent. If it is not, it will create
                // a hole.
                Map<RegionInfo, Result> mergedRegions = cj.getLastReport().mergedRegions;
                for (Map.Entry<RegionInfo, Result> e : mergedRegions.entrySet()) {
                    List<RegionInfo> parents = CatalogFamilyFormat.getMergeRegions(e.getValue().rawCells());
                    if (parents != null) {
                        ProcedureExecutor<MasterProcedureEnv> pe = services.getMasterProcedureExecutor();
                        pe.submitProcedure(new GCMultipleMergedRegionsProcedure(pe.getEnvironment(), e.getKey(), parents));
                    }
                }
                return true;
            }
            return false;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    // Wait until all GCs settled down
    HBaseTestingUtil.await(10, () -> {
        return services.getMasterProcedureExecutor().getActiveProcIds().isEmpty();
    });
    // No orphan regions on FS
    hbckChore.choreForTesting();
    assertEquals(0, hbckChore.getOrphanRegionsOnFS().size());
    // No holes reported.
    cj.scan();
    final Report postReport = cj.getLastReport();
    assertTrue(postReport.isEmpty());
}
Also used : HbckChore(org.apache.hadoop.hbase.master.HbckChore) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result) TableName(org.apache.hadoop.hbase.TableName) GCMultipleMergedRegionsProcedure(org.apache.hadoop.hbase.master.assignment.GCMultipleMergedRegionsProcedure) HMaster(org.apache.hadoop.hbase.master.HMaster) Map(java.util.Map) Test(org.junit.Test)

Example 13 with MasterProcedureEnv

use of org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv in project hbase by apache.

the class TestRegisterPeerWorkerWhenRestarting method testRestart.

@Test
public void testRestart() throws Exception {
    UTIL2.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID, SyncReplicationState.STANDBY);
    UTIL1.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID, SyncReplicationState.ACTIVE);
    UTIL1.getAdmin().disableReplicationPeer(PEER_ID);
    write(UTIL1, 0, 100);
    Thread.sleep(2000);
    // peer is disabled so no data have been replicated
    verifyNotReplicatedThroughRegion(UTIL2, 0, 100);
    // transit the A to DA first to avoid too many error logs.
    UTIL1.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID, SyncReplicationState.DOWNGRADE_ACTIVE);
    HMaster master = UTIL2.getHBaseCluster().getMaster();
    // make sure the transiting can not succeed
    FAIL = true;
    ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                UTIL2.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID, SyncReplicationState.DOWNGRADE_ACTIVE);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }
    };
    t.start();
    // wait until we are in the states where we need to register peer worker when restarting
    UTIL2.waitFor(60000, () -> procExec.getProcedures().stream().filter(p -> p instanceof RecoverStandbyProcedure).map(p -> (RecoverStandbyProcedure) p).anyMatch(p -> p.getCurrentStateId() == DISPATCH_WALS_VALUE || p.getCurrentStateId() == UNREGISTER_PEER_FROM_WORKER_STORAGE_VALUE));
    // failover to another master
    MasterThread mt = UTIL2.getMiniHBaseCluster().getMasterThread();
    mt.getMaster().abort("for testing");
    mt.join();
    FAIL = false;
    t.join();
    // make sure the new master can finish the transition
    UTIL2.waitFor(60000, () -> UTIL2.getAdmin().getReplicationPeerSyncReplicationState(PEER_ID) == SyncReplicationState.DOWNGRADE_ACTIVE);
    verify(UTIL2, 0, 100);
}
Also used : BeforeClass(org.junit.BeforeClass) UNREGISTER_PEER_FROM_WORKER_STORAGE_VALUE(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RecoverStandbyState.UNREGISTER_PEER_FROM_WORKER_STORAGE_VALUE) SyncReplicationState(org.apache.hadoop.hbase.replication.SyncReplicationState) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) LargeTests(org.apache.hadoop.hbase.testclassification.LargeTests) IOException(java.io.IOException) Test(org.junit.Test) DISPATCH_WALS_VALUE(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RecoverStandbyState.DISPATCH_WALS_VALUE) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) Category(org.junit.experimental.categories.Category) MasterThread(org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread) UncheckedIOException(java.io.UncheckedIOException) HConstants(org.apache.hadoop.hbase.HConstants) SyncReplicationTestBase(org.apache.hadoop.hbase.replication.SyncReplicationTestBase) ProcedureExecutor(org.apache.hadoop.hbase.procedure2.ProcedureExecutor) Configuration(org.apache.hadoop.conf.Configuration) MasterTests(org.apache.hadoop.hbase.testclassification.MasterTests) ClassRule(org.junit.ClassRule) HMaster(org.apache.hadoop.hbase.master.HMaster) MasterThread(org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread) HMaster(org.apache.hadoop.hbase.master.HMaster) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) MasterThread(org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread) Test(org.junit.Test)

Example 14 with MasterProcedureEnv

use of org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv in project hbase by apache.

the class TestSyncReplicationReplayWALManager method setUp.

@Before
public void setUp() throws IOException, ReplicationException {
    wokenProcedures = new ArrayDeque<>();
    onlineServers = new HashSet<>();
    listeners = new ArrayList<>();
    ServerManager serverManager = mock(ServerManager.class);
    doAnswer(inv -> listeners.add(inv.getArgument(0))).when(serverManager).registerListener(any(ServerListener.class));
    ServerMetrics serverMetrics = mock(ServerMetrics.class);
    doAnswer(inv -> onlineServers.stream().collect(Collectors.toMap(Function.identity(), k -> serverMetrics))).when(serverManager).getOnlineServers();
    MasterFileSystem mfs = mock(MasterFileSystem.class);
    when(mfs.getFileSystem()).thenReturn(UTIL.getTestFileSystem());
    when(mfs.getWALRootDir()).thenReturn(new Path("/"));
    scheduler = mock(MasterProcedureScheduler.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            ProcedureEvent<?> event = ((ProcedureEvent<?>[]) invocation.getArgument(0))[0];
            event.wakeInternal(new MasterProcedureScheduler(pid -> null) {

                @Override
                public void addFront(Iterator<Procedure> procedureIterator) {
                    procedureIterator.forEachRemaining(wokenProcedures::add);
                }
            });
            return null;
        }
    }).when(scheduler).wakeEvents(any(ProcedureEvent[].class));
    MasterProcedureEnv env = mock(MasterProcedureEnv.class);
    when(env.getProcedureScheduler()).thenReturn(scheduler);
    ProcedureExecutor<MasterProcedureEnv> procExec = mock(ProcedureExecutor.class);
    when(procExec.getEnvironment()).thenReturn(env);
    MasterServices services = mock(MasterServices.class);
    when(services.getServerManager()).thenReturn(serverManager);
    when(services.getMasterFileSystem()).thenReturn(mfs);
    when(services.getMasterProcedureExecutor()).thenReturn(procExec);
    manager = new SyncReplicationReplayWALManager(services);
    assertEquals(1, listeners.size());
}
Also used : ServerManager(org.apache.hadoop.hbase.master.ServerManager) MasterFileSystem(org.apache.hadoop.hbase.master.MasterFileSystem) Path(org.apache.hadoop.fs.Path) ProcedureEvent(org.apache.hadoop.hbase.procedure2.ProcedureEvent) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) MasterProcedureScheduler(org.apache.hadoop.hbase.master.procedure.MasterProcedureScheduler) MasterServices(org.apache.hadoop.hbase.master.MasterServices) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Iterator(java.util.Iterator) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) ServerListener(org.apache.hadoop.hbase.master.ServerListener) Before(org.junit.Before)

Example 15 with MasterProcedureEnv

use of org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv in project hbase by apache.

the class TestHStoreFile method splitStoreFile.

private Path splitStoreFile(final HRegionFileSystem regionFs, final RegionInfo hri, final String family, final HStoreFile sf, final byte[] splitKey, boolean isTopRef) throws IOException {
    Path path = regionFs.splitStoreFile(hri, family, sf, splitKey, isTopRef, null);
    if (null == path) {
        return null;
    }
    List<Path> splitFiles = new ArrayList<>();
    splitFiles.add(path);
    MasterProcedureEnv mockEnv = mock(MasterProcedureEnv.class);
    MasterServices mockServices = mock(MasterServices.class);
    when(mockEnv.getMasterServices()).thenReturn(mockServices);
    when(mockEnv.getMasterConfiguration()).thenReturn(new Configuration());
    TableDescriptors mockTblDescs = mock(TableDescriptors.class);
    when(mockServices.getTableDescriptors()).thenReturn(mockTblDescs);
    TableDescriptor mockTblDesc = TableDescriptorBuilder.newBuilder(hri.getTable()).setColumnFamily(ColumnFamilyDescriptorBuilder.of(family)).build();
    when(mockTblDescs.get(any())).thenReturn(mockTblDesc);
    Path regionDir = regionFs.commitDaughterRegion(hri, splitFiles, mockEnv);
    return new Path(new Path(regionDir, family), path.getName());
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) TableDescriptors(org.apache.hadoop.hbase.TableDescriptors) ArrayList(java.util.ArrayList) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) MasterServices(org.apache.hadoop.hbase.master.MasterServices) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Aggregations

MasterProcedureEnv (org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv)65 Test (org.junit.Test)48 TableName (org.apache.hadoop.hbase.TableName)42 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)39 IOException (java.io.IOException)16 ProcedureExecutor (org.apache.hadoop.hbase.procedure2.ProcedureExecutor)16 ArrayList (java.util.ArrayList)13 Path (org.apache.hadoop.fs.Path)13 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)13 MasterTests (org.apache.hadoop.hbase.testclassification.MasterTests)13 Bytes (org.apache.hadoop.hbase.util.Bytes)13 ClassRule (org.junit.ClassRule)13 Category (org.junit.experimental.categories.Category)13 BeforeClass (org.junit.BeforeClass)12 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)11 ServerName (org.apache.hadoop.hbase.ServerName)10 Procedure (org.apache.hadoop.hbase.procedure2.Procedure)10 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)10 MediumTests (org.apache.hadoop.hbase.testclassification.MediumTests)10 AfterClass (org.junit.AfterClass)10