Skip to content

Commit

Permalink
HBASE-22623 - Add RegionObserver coprocessor hook for preWALAppend
Browse files Browse the repository at this point in the history
  • Loading branch information
gjacoby126 committed Aug 2, 2019
1 parent 0a611d7 commit 0885903
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,8 @@ default DeleteTracker postInstantiateDeleteTracker(
* @param ctx the environment provided by the region server
* @param key the WALKey associated with a particular append to a WAL
*/
default void preWALAppend(ObserverContext<RegionCoprocessorEnvironment> ctx, WALKey key)
default void preWALAppend(ObserverContext<RegionCoprocessorEnvironment> ctx, WALKey key,
WALEdit edit)
throws IOException {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7952,7 +7952,7 @@ private WriteEntry doWALAppend(WALEdit walEdit, Durability durability, List<UUID
walKey.setOrigLogSeqNum(origLogSeqNum);
}
if (this.coprocessorHost != null) {
this.coprocessorHost.preWALAppend(walKey);
this.coprocessorHost.preWALAppend(walKey, walEdit);
}
WriteEntry writeEntry = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1720,14 +1720,14 @@ public List<Pair<Cell, Cell>> call(RegionObserver observer) throws IOException {
});
}

public void preWALAppend(WALKey key) throws IOException {
public void preWALAppend(WALKey key, WALEdit edit) throws IOException {
if (this.coprocEnvironments.isEmpty()){
return;
}
execOperation(new RegionObserverOperationWithoutResult() {
@Override
public void call(RegionObserver observer) throws IOException {
observer.preWALAppend(this, key);
observer.preWALAppend(this, key, edit);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
* Used in HBase's transaction log (WAL) to represent a collection of edits (Cell/KeyValue objects)
* that came in as a single transaction. All the edits for a given transaction are written out as a
* single record, in PB format, followed (optionally) by Cells written via the WALCellEncoder.
* <p>This class is LimitedPrivate for CPs to read-only. The {@link #add} methods are
* classified as private methods, not for use by CPs.</p>
* <p>WALEdit will accumulate a Set of all column family names referenced by the Cells
* {@link #add(Cell)}'d. This is an optimization. Usually when loading a WALEdit, we have the
* column family name to-hand.. just shove it into the WALEdit if available. Doing this, we can
Expand Down Expand Up @@ -163,13 +161,11 @@ public boolean isReplay() {
return this.replay;
}

@InterfaceAudience.Private
public WALEdit add(Cell cell, byte [] family) {
getOrCreateFamilies().add(family);
return addCell(cell);
}

@InterfaceAudience.Private
public WALEdit add(Cell cell) {
// We clone Family each time we add a Cell. Expensive but safe. For CPU savings, use
// add(Map) or add(Cell, family).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ public StoreFileReader postStoreFileReaderOpen(ObserverContext<RegionCoprocessor

@Override
public void preWALAppend(ObserverContext<RegionCoprocessorEnvironment> ctx,
WALKey key) throws IOException {
WALKey key, WALEdit edit) throws IOException {
ctPreWALAppend.incrementAndGet();

key.addExtendedAttribute(Integer.toString(ctPreWALAppend.get()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,8 @@ public void testPreWALAppend() throws Exception {
ObserverContext ctx = Mockito.mock(ObserverContext.class);
WALKey key = new WALKeyImpl(Bytes.toBytes("region"), TEST_TABLE,
EnvironmentEdgeManager.currentTime());
sro.preWALAppend(ctx, key);
WALEdit edit = new WALEdit();
sro.preWALAppend(ctx, key, edit);
Assert.assertEquals(1, key.getExtendedAttributes().size());
Assert.assertArrayEquals(SimpleRegionObserver.WAL_EXTENDED_ATTRIBUTE_BYTES,
key.getExtendedAttribute(Integer.toString(sro.getCtPreWALAppend())));
Expand Down

0 comments on commit 0885903

Please sign in to comment.