Java Code Examples for org.apache.hadoop.hbase.wal.WAL#registerWALActionsListener()

The following examples show how to use org.apache.hadoop.hbase.wal.WAL#registerWALActionsListener() . 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: TestHRegionServerBulkLoad.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Atomic bulk load.
 */
@Test
public void testAtomicBulkLoad() throws Exception {
  TableName TABLE_NAME = TableName.valueOf("atomicBulkLoad");

  int millisToRun = 30000;
  int numScanners = 50;

  // Set createWALDir to true and use default values for other options.
  UTIL.startMiniCluster(StartMiniClusterOption.builder().createWALDir(true).build());
  try {
    WAL log = UTIL.getHBaseCluster().getRegionServer(0).getWAL(null);
    FindBulkHBaseListener listener = new FindBulkHBaseListener();
    log.registerWALActionsListener(listener);
    runAtomicBulkloadTest(TABLE_NAME, millisToRun, numScanners);
    assertThat(listener.isFound(), is(true));
  } finally {
    UTIL.shutdownMiniCluster();
  }
}
 
Example 2
Source File: AbstractTestLogRollPeriod.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void checkMinLogRolls(final WAL log, final int minRolls)
    throws Exception {
  final List<Path> paths = new ArrayList<>();
  log.registerWALActionsListener(new WALActionsListener() {
    @Override
    public void postLogRoll(Path oldFile, Path newFile) {
      LOG.debug("postLogRoll: oldFile="+oldFile+" newFile="+newFile);
      paths.add(newFile);
    }
  });

  // Sleep until we should get at least min-LogRoll events
  long wtime = System.currentTimeMillis();
  Thread.sleep((minRolls + 1) * LOG_ROLL_PERIOD);
  // Do some extra sleep in case the machine is slow,
  // and the log-roll is not triggered exactly on LOG_ROLL_PERIOD.
  final int NUM_RETRIES = 1 + 8 * (minRolls - paths.size());
  for (int retry = 0; paths.size() < minRolls && retry < NUM_RETRIES; ++retry) {
    Thread.sleep(LOG_ROLL_PERIOD / 4);
  }
  wtime = System.currentTimeMillis() - wtime;
  LOG.info(String.format("got %d rolls after %dms (%dms each) - expected at least %d rolls",
                         paths.size(), wtime, wtime / paths.size(), minRolls));
  assertFalse(paths.size() < minRolls);
}
 
Example 3
Source File: TestWALActionsListener.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Add a bunch of dummy data and roll the logs every two insert. We
 * should end up with 10 rolled files (plus the roll called in
 * the constructor). Also test adding a listener while it's running.
 */
@Test
public void testActionListener() throws Exception {
  DummyWALActionsListener observer = new DummyWALActionsListener();
  final WALFactory wals = new WALFactory(conf, "testActionListener");
  wals.getWALProvider().addWALActionsListener(observer);
  DummyWALActionsListener laterobserver = new DummyWALActionsListener();
  RegionInfo hri = RegionInfoBuilder.newBuilder(TableName.valueOf(SOME_BYTES))
      .setStartKey(SOME_BYTES).setEndKey(SOME_BYTES).build();
  final WAL wal = wals.getWAL(hri);
  MultiVersionConcurrencyControl mvcc = new MultiVersionConcurrencyControl();
  for (int i = 0; i < 20; i++) {
    byte[] b = Bytes.toBytes(i + "");
    KeyValue kv = new KeyValue(b, b, b);
    WALEdit edit = new WALEdit();
    edit.add(kv);
    NavigableMap<byte[], Integer> scopes = new TreeMap<>(Bytes.BYTES_COMPARATOR);
    scopes.put(b, 0);
    long txid = wal.appendData(hri,
      new WALKeyImpl(hri.getEncodedNameAsBytes(), TableName.valueOf(b), 0, mvcc, scopes), edit);
    wal.sync(txid);
    if (i == 10) {
      wal.registerWALActionsListener(laterobserver);
    }
    if (i % 2 == 0) {
      wal.rollWriter();
    }
  }

  wal.close();

  assertEquals(11, observer.preLogRollCounter);
  assertEquals(11, observer.postLogRollCounter);
  assertEquals(5, laterobserver.preLogRollCounter);
  assertEquals(5, laterobserver.postLogRollCounter);
  assertEquals(1, observer.closedCount);
}