Java Code Examples for org.apache.hadoop.hbase.Stoppable#stop()

The following examples show how to use org.apache.hadoop.hbase.Stoppable#stop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestSnapshotCleanerChore.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testSnapshotCleanerWithNoTtlExpired() throws IOException {
  snapshotManager = Mockito.mock(SnapshotManager.class);
  Stoppable stopper = new StoppableImplementation();
  Configuration conf = getSnapshotCleanerConf();
  SnapshotCleanerChore snapshotCleanerChore =
          new SnapshotCleanerChore(stopper, conf, snapshotManager);
  List<SnapshotProtos.SnapshotDescription> snapshotDescriptionList = new ArrayList<>();
  snapshotDescriptionList.add(getSnapshotDescription(-2, "snapshot01", "table01",
          EnvironmentEdgeManager.currentTime() - 100000));
  snapshotDescriptionList.add(getSnapshotDescription(10, "snapshot02", "table02",
          EnvironmentEdgeManager.currentTime()));
  Mockito.when(snapshotManager.getCompletedSnapshots()).thenReturn(snapshotDescriptionList);
  try {
    LOG.info("2 Snapshots are completed but TTL is not expired for any of them");
    snapshotCleanerChore.chore();
  } finally {
    stopper.stop("Stopping Test Stopper");
  }
  Mockito.verify(snapshotManager, Mockito.times(0)).deleteSnapshot(Mockito.any());
}
 
Example 2
Source File: TestSnapshotCleanerChore.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testSnapshotCleanerWithSomeTtlExpired() throws IOException {
  snapshotManager = Mockito.mock(SnapshotManager.class);
  Stoppable stopper = new StoppableImplementation();
  Configuration conf = getSnapshotCleanerConf();
  SnapshotCleanerChore snapshotCleanerChore =
          new SnapshotCleanerChore(stopper, conf, snapshotManager);
  List<SnapshotProtos.SnapshotDescription> snapshotDescriptionList = new ArrayList<>();
  snapshotDescriptionList.add(getSnapshotDescription(10, "snapshot01", "table01", 1));
  snapshotDescriptionList.add(getSnapshotDescription(5, "snapshot02", "table02", 2));
  snapshotDescriptionList.add(getSnapshotDescription(30, "snapshot01", "table01",
          EnvironmentEdgeManager.currentTime()));
  snapshotDescriptionList.add(getSnapshotDescription(0, "snapshot02", "table02",
          EnvironmentEdgeManager.currentTime()));
  snapshotDescriptionList.add(getSnapshotDescription(40, "snapshot03", "table03",
          EnvironmentEdgeManager.currentTime()));
  Mockito.when(snapshotManager.getCompletedSnapshots()).thenReturn(snapshotDescriptionList);
  try {
    LOG.info("5 Snapshots are completed. TTL is expired for 2 them. Going to delete them");
    snapshotCleanerChore.chore();
  } finally {
    stopper.stop("Stopping Test Stopper");
  }
  Mockito.verify(snapshotManager, Mockito.times(2)).deleteSnapshot(Mockito.any());
}
 
Example 3
Source File: TestSnapshotCleanerChore.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testSnapshotCleanerWithReadIOE() throws IOException {
  snapshotManager = Mockito.mock(SnapshotManager.class);
  Stoppable stopper = new StoppableImplementation();
  Configuration conf = new HBaseTestingUtility().getConfiguration();
  SnapshotCleanerChore snapshotCleanerChore =
          new SnapshotCleanerChore(stopper, conf, snapshotManager);
  Mockito.when(snapshotManager.getCompletedSnapshots()).thenThrow(IOException.class);
  try {
    LOG.info("While getting completed Snapshots, IOException would occur. Hence, No Snapshot"
            + " should be deleted");
    snapshotCleanerChore.chore();
  } finally {
    stopper.stop("Stopping Test Stopper");
  }
  Mockito.verify(snapshotManager, Mockito.times(0)).deleteSnapshot(Mockito.any());
}
 
Example 4
Source File: TestSnapshotCleanerChore.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testSnapshotChoreWithTtlOutOfRange() throws IOException {
  snapshotManager = Mockito.mock(SnapshotManager.class);
  Stoppable stopper = new StoppableImplementation();
  Configuration conf = getSnapshotCleanerConf();
  List<SnapshotProtos.SnapshotDescription> snapshotDescriptionList = new ArrayList<>();
  snapshotDescriptionList.add(getSnapshotDescription(Long.MAX_VALUE, "snapshot01", "table01", 1));
  snapshotDescriptionList.add(getSnapshotDescription(5, "snapshot02", "table02", 2));
  Mockito.when(snapshotManager.getCompletedSnapshots()).thenReturn(snapshotDescriptionList);
  SnapshotCleanerChore snapshotCleanerChore =
          new SnapshotCleanerChore(stopper, conf, snapshotManager);
  try {
    LOG.info("Snapshot Chore is disabled. No cleanup performed for Expired Snapshots");
    snapshotCleanerChore.chore();
  } finally {
    stopper.stop("Stopping Test Stopper");
  }
  Mockito.verify(snapshotManager, Mockito.times(1)).getCompletedSnapshots();
}
 
Example 5
Source File: TestCleanerChore.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testStoppedCleanerDoesNotDeleteFiles() throws Exception {
  Stoppable stop = new StoppableImplementation();
  Configuration conf = UTIL.getConfiguration();
  Path testDir = UTIL.getDataTestDir();
  FileSystem fs = UTIL.getTestFileSystem();
  String confKey = "hbase.test.cleaner.delegates";
  conf.set(confKey, AlwaysDelete.class.getName());

  AllValidPaths chore =
    new AllValidPaths("test-file-cleaner", stop, conf, fs, testDir, confKey, POOL);

  // also create a file in the top level directory
  Path topFile = new Path(testDir, "topFile");
  fs.create(topFile).close();
  assertTrue("Test file didn't get created.", fs.exists(topFile));

  // stop the chore
  stop.stop("testing stop");

  // run the chore
  chore.chore();

  // test that the file still exists
  assertTrue("File got deleted while chore was stopped", fs.exists(topFile));
}
 
Example 6
Source File: TestSnapshotCleanerChore.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testSnapshotCleanerWithoutAnyCompletedSnapshot() throws IOException {
  snapshotManager = Mockito.mock(SnapshotManager.class);
  Stoppable stopper = new StoppableImplementation();
  Configuration conf = getSnapshotCleanerConf();
  SnapshotCleanerChore snapshotCleanerChore =
          new SnapshotCleanerChore(stopper, conf, snapshotManager);
  try {
    snapshotCleanerChore.chore();
  } finally {
    stopper.stop("Stopping Test Stopper");
  }
  Mockito.verify(snapshotManager, Mockito.times(0)).deleteSnapshot(Mockito.any());
}
 
Example 7
Source File: TestZooKeeperTableArchiveClient.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * @param cleaner the cleaner to use
 */
private void runCleaner(HFileCleaner cleaner, CountDownLatch finished, Stoppable stop)
    throws InterruptedException {
  final ChoreService choreService = new ChoreService("CLEANER_SERVER_NAME");
  // run the cleaner
  choreService.scheduleChore(cleaner);
  // wait for the cleaner to check all the files
  finished.await();
  // stop the cleaner
  stop.stop("");
}
 
Example 8
Source File: TestEndToEndSplitTransaction.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that the client sees meta table changes as atomic during splits
 */
@Test
public void testFromClientSideWhileSplitting() throws Throwable {
  LOG.info("Starting testFromClientSideWhileSplitting");
  final TableName tableName = TableName.valueOf(name.getMethodName());
  final byte[] FAMILY = Bytes.toBytes("family");

  // SplitTransaction will update the meta table by offlining the parent region, and adding info
  // for daughters.
  Table table = TEST_UTIL.createTable(tableName, FAMILY);

  Stoppable stopper = new StoppableImplementation();
  RegionSplitter regionSplitter = new RegionSplitter(table);
  RegionChecker regionChecker = new RegionChecker(CONF, stopper, tableName);
  final ChoreService choreService = new ChoreService("TEST_SERVER");

  choreService.scheduleChore(regionChecker);
  regionSplitter.start();

  // wait until the splitter is finished
  regionSplitter.join();
  stopper.stop(null);

  if (regionChecker.ex != null) {
    throw new AssertionError("regionChecker", regionChecker.ex);
  }

  if (regionSplitter.ex != null) {
    throw new AssertionError("regionSplitter", regionSplitter.ex);
  }

  // one final check
  regionChecker.verify();
}
 
Example 9
Source File: TestHFileArchiving.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Test HFileArchiver.resolveAndArchive() race condition HBASE-7643
 */
@Test
public void testCleaningRace() throws Exception {
  final long TEST_TIME = 20 * 1000;
  final ChoreService choreService = new ChoreService("TEST_SERVER_NAME");

  Configuration conf = UTIL.getMiniHBaseCluster().getMaster().getConfiguration();
  Path rootDir = UTIL.getDataTestDirOnTestFS("testCleaningRace");
  FileSystem fs = UTIL.getTestFileSystem();

  Path archiveDir = new Path(rootDir, HConstants.HFILE_ARCHIVE_DIRECTORY);
  Path regionDir = new Path(CommonFSUtils.getTableDir(new Path("./"),
      TableName.valueOf(name.getMethodName())), "abcdef");
  Path familyDir = new Path(regionDir, "cf");

  Path sourceRegionDir = new Path(rootDir, regionDir);
  fs.mkdirs(sourceRegionDir);

  Stoppable stoppable = new StoppableImplementation();

  // The cleaner should be looping without long pauses to reproduce the race condition.
  HFileCleaner cleaner = getHFileCleaner(stoppable, conf, fs, archiveDir);
  assertNotNull("cleaner should not be null", cleaner);
  try {
    choreService.scheduleChore(cleaner);
    // Keep creating/archiving new files while the cleaner is running in the other thread
    long startTime = System.currentTimeMillis();
    for (long fid = 0; (System.currentTimeMillis() - startTime) < TEST_TIME; ++fid) {
      Path file = new Path(familyDir,  String.valueOf(fid));
      Path sourceFile = new Path(rootDir, file);
      Path archiveFile = new Path(archiveDir, file);

      fs.createNewFile(sourceFile);

      try {
        // Try to archive the file
        HFileArchiver.archiveRegion(fs, rootDir,
            sourceRegionDir.getParent(), sourceRegionDir);

        // The archiver succeded, the file is no longer in the original location
        // but it's in the archive location.
        LOG.debug("hfile=" + fid + " should be in the archive");
        assertTrue(fs.exists(archiveFile));
        assertFalse(fs.exists(sourceFile));
      } catch (IOException e) {
        // The archiver is unable to archive the file. Probably HBASE-7643 race condition.
        // in this case, the file should not be archived, and we should have the file
        // in the original location.
        LOG.debug("hfile=" + fid + " should be in the source location");
        assertFalse(fs.exists(archiveFile));
        assertTrue(fs.exists(sourceFile));

        // Avoid to have this file in the next run
        fs.delete(sourceFile, false);
      }
    }
  } finally {
    stoppable.stop("test end");
    cleaner.cancel(true);
    choreService.shutdown();
    fs.delete(rootDir, true);
  }
}