org.apache.hadoop.hbase.regionserver.wal.WALActionsListener Java Examples

The following examples show how to use org.apache.hadoop.hbase.regionserver.wal.WALActionsListener. 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: AbstractWALRoller.java    From hbase with Apache License 2.0 6 votes vote down vote up
public void addWAL(WAL wal) {
  // check without lock first
  if (walNeedsRoll.containsKey(wal)) {
    return;
  }
  // this is to avoid race between addWAL and requestRollAll.
  synchronized (this) {
    if (walNeedsRoll.putIfAbsent(wal, Boolean.FALSE) == null) {
      wal.registerWALActionsListener(new WALActionsListener() {
        @Override
        public void logRollRequested(WALActionsListener.RollRequestReason reason) {
          // TODO logs will contend with each other here, replace with e.g. DelayedQueue
          synchronized (AbstractWALRoller.this) {
            walNeedsRoll.put(wal, Boolean.TRUE);
            AbstractWALRoller.this.notifyAll();
          }
        }
      });
    }
  }
}
 
Example #2
Source File: RegionGroupingProvider.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void addWALActionsListener(WALActionsListener listener) {
  // Notice that there is an assumption that this method must be called before the getWAL above,
  // so we can make sure there is no sub WALProvider yet, so we only add the listener to our
  // listeners list without calling addWALActionListener for each WALProvider. Although it is no
  // hurt to execute an extra loop to call addWALActionListener for each WALProvider, but if the
  // extra code actually works, then we will have other big problems. So leave it as is.
  listeners.add(listener);
}
 
Example #3
Source File: TestAsyncFSWALCorruptionDueToDanglingByteBuffer.java    From hbase with Apache License 2.0 5 votes vote down vote up
public PauseWAL(FileSystem fs, Path rootDir, String logDir, String archiveDir,
  Configuration conf, List<WALActionsListener> listeners, boolean failIfWALExists,
  String prefix, String suffix, EventLoopGroup eventLoopGroup,
  Class<? extends Channel> channelClass) throws FailedLogCloseException, IOException {
  super(fs, rootDir, logDir, archiveDir, conf, listeners, failIfWALExists, prefix, suffix,
    eventLoopGroup, channelClass);
}
 
Example #4
Source File: DisabledWALProvider.java    From hbase with Apache License 2.0 5 votes vote down vote up
public DisabledWAL(final Path path, final Configuration conf,
    final List<WALActionsListener> listeners) {
  this.coprocessorHost = new WALCoprocessorHost(this, conf);
  this.path = path;
  if (null != listeners) {
    for(WALActionsListener listener : listeners) {
      registerWALActionsListener(listener);
    }
  }
}
 
Example #5
Source File: TestMultiSlaveReplication.java    From hbase with Apache License 2.0 5 votes vote down vote up
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() {
        @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.getTableDescriptor().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);
}
 
Example #6
Source File: TestMasterReplication.java    From hbase with Apache License 2.0 5 votes vote down vote up
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() {
        @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.getTableDescriptor().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);
}
 
Example #7
Source File: DisabledWALProvider.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void shutdown() {
  if(closed.compareAndSet(false, true)) {
    if (!this.listeners.isEmpty()) {
      for (WALActionsListener listener : this.listeners) {
        listener.logCloseRequested();
      }
    }
  }
}
 
Example #8
Source File: DisabledWALProvider.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void sync() {
  if (!this.listeners.isEmpty()) {
    for (WALActionsListener listener : this.listeners) {
      listener.postSync(0L, 0);
    }
  }
}
 
Example #9
Source File: DualAsyncFSWALForTest.java    From hbase with Apache License 2.0 5 votes vote down vote up
public DualAsyncFSWALForTest(FileSystem fs, FileSystem remoteFs, Path rootDir, Path remoteWALDir,
    String logDir, String archiveDir, Configuration conf, List<WALActionsListener> listeners,
    boolean failIfWALExists, String prefix, String suffix, EventLoopGroup eventLoopGroup,
    Class<? extends Channel> channelClass) throws FailedLogCloseException, IOException {
  super(fs, remoteFs, rootDir, remoteWALDir, logDir, archiveDir, conf, listeners, failIfWALExists,
    prefix, suffix, eventLoopGroup, channelClass);
}
 
Example #10
Source File: THLog.java    From hbase-secondary-index with GNU General Public License v3.0 4 votes vote down vote up
public THLog(final FileSystem fs, final Path dir, final Path oldLogDir,
		final Configuration conf, final List<WALActionsListener> listeners)
		throws IOException {
	super(fs, dir, oldLogDir, conf, listeners, false, null);
}
 
Example #11
Source File: IOTestProvider.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public void addWALActionsListener(WALActionsListener listener) {
  // TODO Implement WALProvider.addWALActionLister

}
 
Example #12
Source File: TestFSHLogCorruptionDueToDanglingByteBuffer.java    From hbase with Apache License 2.0 4 votes vote down vote up
public PauseWAL(FileSystem fs, Path rootDir, String logDir, String archiveDir,
  Configuration conf, List<WALActionsListener> listeners, boolean failIfWALExists,
  String prefix, String suffix) throws IOException {
  super(fs, rootDir, logDir, archiveDir, conf, listeners, failIfWALExists, prefix, suffix);
}
 
Example #13
Source File: SyncReplicationWALProvider.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public void addWALActionsListener(WALActionsListener listener) {
  listeners.add(listener);
  provider.addWALActionsListener(listener);
}
 
Example #14
Source File: DisabledWALProvider.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public void addWALActionsListener(WALActionsListener listener) {
  disabled.registerWALActionsListener(listener);
}
 
Example #15
Source File: DisabledWALProvider.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public boolean unregisterWALActionsListener(final WALActionsListener listener) {
  return listeners.remove(listener);
}
 
Example #16
Source File: DisabledWALProvider.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public void registerWALActionsListener(final WALActionsListener listener) {
  listeners.add(listener);
}
 
Example #17
Source File: AbstractFSWALProvider.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public void addWALActionsListener(WALActionsListener listener) {
  listeners.add(listener);
}
 
Example #18
Source File: IOTestProvider.java    From hbase with Apache License 2.0 3 votes vote down vote up
/**
 * Create an edit log at the given <code>dir</code> location.
 *
 * You should never have to load an existing log. If there is a log at
 * startup, it should have already been processed and deleted by the time the
 * WAL object is started up.
 *
 * @param fs filesystem handle
 * @param rootDir path to where logs and oldlogs
 * @param logDir dir where wals are stored
 * @param archiveDir dir where wals are archived
 * @param conf configuration to use
 * @param listeners Listeners on WAL events. Listeners passed here will
 * be registered before we do anything else; e.g. the
 * Constructor {@link #rollWriter()}.
 * @param failIfWALExists If true IOException will be thrown if files related to this wal
 *        already exist.
 * @param prefix should always be hostname and port in distributed env and
 *        it will be URL encoded before being used.
 *        If prefix is null, "wal" will be used
 * @param suffix will be url encoded. null is treated as empty. non-empty must start with
 *        {@link AbstractFSWALProvider#WAL_FILE_NAME_DELIMITER}
 * @throws IOException
 */
public IOTestWAL(final FileSystem fs, final Path rootDir, final String logDir,
    final String archiveDir, final Configuration conf,
    final List<WALActionsListener> listeners,
    final boolean failIfWALExists, final String prefix, final String suffix)
    throws IOException {
  super(fs, rootDir, logDir, archiveDir, conf, listeners, failIfWALExists, prefix, suffix);
  Collection<String> operations = conf.getStringCollection(ALLOWED_OPERATIONS);
  doFileRolls = operations.isEmpty() || operations.contains(AllowedOperations.all.name()) ||
      operations.contains(AllowedOperations.fileroll.name());
  initialized = true;
  LOG.info("Initialized with file rolling " + (doFileRolls ? "enabled" : "disabled"));
}
 
Example #19
Source File: WALProvider.java    From hbase with Apache License 2.0 2 votes vote down vote up
/**
 * Add a {@link WALActionsListener}.
 * <p>
 * Notice that you must call this method before calling {@link #getWAL(RegionInfo)} as this method
 * will not effect the {@link WAL} which has already been created. And as long as we can only it
 * when initialization, it is not thread safe.
 */
void addWALActionsListener(WALActionsListener listener);
 
Example #20
Source File: WAL.java    From hbase with Apache License 2.0 2 votes vote down vote up
/**
 * Unregisters WALActionsListener
 */
boolean unregisterWALActionsListener(final WALActionsListener listener);
 
Example #21
Source File: WAL.java    From hbase with Apache License 2.0 2 votes vote down vote up
/**
 * Registers WALActionsListener
 */
void registerWALActionsListener(final WALActionsListener listener);