Search in sources :

Example 1 with WALActionsListener

use of org.apache.hadoop.hbase.regionserver.wal.WALActionsListener in project hbase by apache.

the class HRegionServer method setupWALAndReplication.

/**
   * Setup WAL log and replication if enabled.
   * Replication setup is done in here because it wants to be hooked up to WAL.
   * @return A WAL instance.
   * @throws IOException
   */
private WALFactory setupWALAndReplication() throws IOException {
    // TODO Replication make assumptions here based on the default filesystem impl
    final Path oldLogDir = new Path(walRootDir, HConstants.HREGION_OLDLOGDIR_NAME);
    final String logName = AbstractFSWALProvider.getWALDirectoryName(this.serverName.toString());
    Path logDir = new Path(walRootDir, logName);
    if (LOG.isDebugEnabled())
        LOG.debug("logDir=" + logDir);
    if (this.walFs.exists(logDir)) {
        throw new RegionServerRunningException("Region server has already " + "created directory at " + this.serverName.toString());
    }
    // Instantiate replication manager if replication enabled.  Pass it the
    // log directories.
    createNewReplicationInstance(conf, this, this.walFs, logDir, oldLogDir);
    // listeners the wal factory will add to wals it creates.
    final List<WALActionsListener> listeners = new ArrayList<>();
    listeners.add(new MetricsWAL());
    if (this.replicationSourceHandler != null && this.replicationSourceHandler.getWALActionsListener() != null) {
        // Replication handler is an implementation of WALActionsListener.
        listeners.add(this.replicationSourceHandler.getWALActionsListener());
    }
    return new WALFactory(conf, listeners, serverName.toString());
}
Also used : Path(org.apache.hadoop.fs.Path) MetricsWAL(org.apache.hadoop.hbase.regionserver.wal.MetricsWAL) ArrayList(java.util.ArrayList) WALActionsListener(org.apache.hadoop.hbase.regionserver.wal.WALActionsListener) WALFactory(org.apache.hadoop.hbase.wal.WALFactory)

Example 2 with WALActionsListener

use of org.apache.hadoop.hbase.regionserver.wal.WALActionsListener in project hbase by apache.

the class TestMasterReplication method rollWALAndWait.

private void rollWALAndWait(final HBaseTestingUtility utility, final TableName table, final byte[] row) throws IOException {
    final Admin admin = utility.getAdmin();
    final MiniHBaseCluster cluster = utility.getMiniHBaseCluster();
    // find the region that corresponds to the given row.
    HRegion region = null;
    for (HRegion candidate : cluster.getRegions(table)) {
        if (HRegion.rowIsInRange(candidate.getRegionInfo(), row)) {
            region = candidate;
            break;
        }
    }
    assertNotNull("Couldn't find the region for row '" + Arrays.toString(row) + "'", region);
    final CountDownLatch latch = new CountDownLatch(1);
    // listen for successful log rolls
    final WALActionsListener listener = new WALActionsListener.Base() {

        @Override
        public void postLogRoll(final Path oldPath, final Path newPath) throws IOException {
            latch.countDown();
        }
    };
    region.getWAL().registerWALActionsListener(listener);
    // request a roll
    admin.rollWALWriter(cluster.getServerHoldingRegion(region.getTableDesc().getTableName(), region.getRegionInfo().getRegionName()));
    // wait
    try {
        latch.await();
    } catch (InterruptedException exception) {
        LOG.warn("Interrupted while waiting for the wal of '" + region + "' to roll. If later " + "replication tests fail, it's probably because we should still be waiting.");
        Thread.currentThread().interrupt();
    }
    region.getWAL().unregisterWALActionsListener(listener);
}
Also used : Path(org.apache.hadoop.fs.Path) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) WALActionsListener(org.apache.hadoop.hbase.regionserver.wal.WALActionsListener) Admin(org.apache.hadoop.hbase.client.Admin) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 3 with WALActionsListener

use of org.apache.hadoop.hbase.regionserver.wal.WALActionsListener in project hbase by apache.

the class TestMultiSlaveReplication method rollWALAndWait.

private void rollWALAndWait(final HBaseTestingUtility utility, final TableName table, final byte[] row) throws IOException {
    final Admin admin = utility.getAdmin();
    final MiniHBaseCluster cluster = utility.getMiniHBaseCluster();
    // find the region that corresponds to the given row.
    HRegion region = null;
    for (HRegion candidate : cluster.getRegions(table)) {
        if (HRegion.rowIsInRange(candidate.getRegionInfo(), row)) {
            region = candidate;
            break;
        }
    }
    assertNotNull("Couldn't find the region for row '" + Arrays.toString(row) + "'", region);
    final CountDownLatch latch = new CountDownLatch(1);
    // listen for successful log rolls
    final WALActionsListener listener = new WALActionsListener.Base() {

        @Override
        public void postLogRoll(final Path oldPath, final Path newPath) throws IOException {
            latch.countDown();
        }
    };
    region.getWAL().registerWALActionsListener(listener);
    // request a roll
    admin.rollWALWriter(cluster.getServerHoldingRegion(region.getTableDesc().getTableName(), region.getRegionInfo().getRegionName()));
    // wait
    try {
        latch.await();
    } catch (InterruptedException exception) {
        LOG.warn("Interrupted while waiting for the wal of '" + region + "' to roll. If later " + "replication tests fail, it's probably because we should still be waiting.");
        Thread.currentThread().interrupt();
    }
    region.getWAL().unregisterWALActionsListener(listener);
}
Also used : Path(org.apache.hadoop.fs.Path) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) WALActionsListener(org.apache.hadoop.hbase.regionserver.wal.WALActionsListener) HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) ReplicationAdmin(org.apache.hadoop.hbase.client.replication.ReplicationAdmin) Admin(org.apache.hadoop.hbase.client.Admin) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 4 with WALActionsListener

use of org.apache.hadoop.hbase.regionserver.wal.WALActionsListener in project hbase by apache.

the class TestReplicationSourceManager method testLogRoll.

@Test
public void testLogRoll() throws Exception {
    long baseline = 1000;
    long time = baseline;
    MultiVersionConcurrencyControl mvcc = new MultiVersionConcurrencyControl();
    KeyValue kv = new KeyValue(r1, f1, r1);
    WALEdit edit = new WALEdit();
    edit.add(kv);
    List<WALActionsListener> listeners = new ArrayList<>(1);
    listeners.add(replication);
    final WALFactory wals = new WALFactory(utility.getConfiguration(), listeners, URLEncoder.encode("regionserver:60020", "UTF8"));
    final WAL wal = wals.getWAL(hri.getEncodedNameAsBytes(), hri.getTable().getNamespace());
    manager.init();
    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("tableame"));
    htd.addFamily(new HColumnDescriptor(f1));
    NavigableMap<byte[], Integer> scopes = new TreeMap<>(Bytes.BYTES_COMPARATOR);
    for (byte[] fam : htd.getFamiliesKeys()) {
        scopes.put(fam, 0);
    }
    // Testing normal log rolling every 20
    for (long i = 1; i < 101; i++) {
        if (i > 1 && i % 20 == 0) {
            wal.rollWriter();
        }
        LOG.info(i);
        final long txid = wal.append(hri, new WALKey(hri.getEncodedNameAsBytes(), test, System.currentTimeMillis(), mvcc, scopes), edit, true);
        wal.sync(txid);
    }
    // Simulate a rapid insert that's followed
    // by a report that's still not totally complete (missing last one)
    LOG.info(baseline + " and " + time);
    baseline += 101;
    time = baseline;
    LOG.info(baseline + " and " + time);
    for (int i = 0; i < 3; i++) {
        wal.append(hri, new WALKey(hri.getEncodedNameAsBytes(), test, System.currentTimeMillis(), mvcc, scopes), edit, true);
    }
    wal.sync();
    int logNumber = 0;
    for (Map.Entry<String, SortedSet<String>> entry : manager.getWALs().get(slaveId).entrySet()) {
        logNumber += entry.getValue().size();
    }
    assertEquals(6, logNumber);
    wal.rollWriter();
    manager.logPositionAndCleanOldLogs(manager.getSources().get(0).getCurrentPath(), "1", 0, false, false);
    wal.append(hri, new WALKey(hri.getEncodedNameAsBytes(), test, System.currentTimeMillis(), mvcc, scopes), edit, true);
    wal.sync();
    assertEquals(1, manager.getWALs().size());
// TODO Need a case with only 2 WALs and we only want to delete the first one
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) WAL(org.apache.hadoop.hbase.wal.WAL) MultiVersionConcurrencyControl(org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) ArrayList(java.util.ArrayList) WALActionsListener(org.apache.hadoop.hbase.regionserver.wal.WALActionsListener) TreeMap(java.util.TreeMap) SortedSet(java.util.SortedSet) ReplicationEndpoint(org.apache.hadoop.hbase.replication.ReplicationEndpoint) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) WALKey(org.apache.hadoop.hbase.wal.WALKey) WALEdit(org.apache.hadoop.hbase.regionserver.wal.WALEdit) WALFactory(org.apache.hadoop.hbase.wal.WALFactory) Map(java.util.Map) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 5 with WALActionsListener

use of org.apache.hadoop.hbase.regionserver.wal.WALActionsListener in project hbase by apache.

the class TestWALEntryStream method setUp.

@Before
public void setUp() throws Exception {
    walQueue = new PriorityBlockingQueue<>();
    List<WALActionsListener> listeners = new ArrayList<WALActionsListener>();
    pathWatcher = new PathWatcher();
    listeners.add(pathWatcher);
    final WALFactory wals = new WALFactory(conf, listeners, tn.getMethodName());
    log = wals.getWAL(info.getEncodedNameAsBytes(), info.getTable().getNamespace());
}
Also used : ArrayList(java.util.ArrayList) WALActionsListener(org.apache.hadoop.hbase.regionserver.wal.WALActionsListener) WALFactory(org.apache.hadoop.hbase.wal.WALFactory) Before(org.junit.Before)

Aggregations

WALActionsListener (org.apache.hadoop.hbase.regionserver.wal.WALActionsListener)6 Path (org.apache.hadoop.fs.Path)4 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)3 WALFactory (org.apache.hadoop.hbase.wal.WALFactory)3 MiniHBaseCluster (org.apache.hadoop.hbase.MiniHBaseCluster)2 Admin (org.apache.hadoop.hbase.client.Admin)2 Test (org.junit.Test)2 FileNotFoundException (java.io.FileNotFoundException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1 SortedSet (java.util.SortedSet)1 TreeMap (java.util.TreeMap)1 BlockLocation (org.apache.hadoop.fs.BlockLocation)1 FileStatus (org.apache.hadoop.fs.FileStatus)1 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)1 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)1 KeyValue (org.apache.hadoop.hbase.KeyValue)1