Skip to content

Commit 0885903

Browse files
committed
HBASE-22623 - Add RegionObserver coprocessor hook for preWALAppend
1 parent 0a611d7 commit 0885903

File tree

6 files changed

+8
-10
lines changed

6 files changed

+8
-10
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionObserver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,8 @@ default DeleteTracker postInstantiateDeleteTracker(
11121112
* @param ctx the environment provided by the region server
11131113
* @param key the WALKey associated with a particular append to a WAL
11141114
*/
1115-
default void preWALAppend(ObserverContext<RegionCoprocessorEnvironment> ctx, WALKey key)
1115+
default void preWALAppend(ObserverContext<RegionCoprocessorEnvironment> ctx, WALKey key,
1116+
WALEdit edit)
11161117
throws IOException {
11171118
}
11181119
}

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7952,7 +7952,7 @@ private WriteEntry doWALAppend(WALEdit walEdit, Durability durability, List<UUID
79527952
walKey.setOrigLogSeqNum(origLogSeqNum);
79537953
}
79547954
if (this.coprocessorHost != null) {
7955-
this.coprocessorHost.preWALAppend(walKey);
7955+
this.coprocessorHost.preWALAppend(walKey, walEdit);
79567956
}
79577957
WriteEntry writeEntry = null;
79587958
try {

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,14 +1720,14 @@ public List<Pair<Cell, Cell>> call(RegionObserver observer) throws IOException {
17201720
});
17211721
}
17221722

1723-
public void preWALAppend(WALKey key) throws IOException {
1723+
public void preWALAppend(WALKey key, WALEdit edit) throws IOException {
17241724
if (this.coprocEnvironments.isEmpty()){
17251725
return;
17261726
}
17271727
execOperation(new RegionObserverOperationWithoutResult() {
17281728
@Override
17291729
public void call(RegionObserver observer) throws IOException {
1730-
observer.preWALAppend(this, key);
1730+
observer.preWALAppend(this, key, edit);
17311731
}
17321732
});
17331733
}

hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALEdit.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848
* Used in HBase's transaction log (WAL) to represent a collection of edits (Cell/KeyValue objects)
4949
* that came in as a single transaction. All the edits for a given transaction are written out as a
5050
* single record, in PB format, followed (optionally) by Cells written via the WALCellEncoder.
51-
* <p>This class is LimitedPrivate for CPs to read-only. The {@link #add} methods are
52-
* classified as private methods, not for use by CPs.</p>
5351
* <p>WALEdit will accumulate a Set of all column family names referenced by the Cells
5452
* {@link #add(Cell)}'d. This is an optimization. Usually when loading a WALEdit, we have the
5553
* column family name to-hand.. just shove it into the WALEdit if available. Doing this, we can
@@ -163,13 +161,11 @@ public boolean isReplay() {
163161
return this.replay;
164162
}
165163

166-
@InterfaceAudience.Private
167164
public WALEdit add(Cell cell, byte [] family) {
168165
getOrCreateFamilies().add(family);
169166
return addCell(cell);
170167
}
171168

172-
@InterfaceAudience.Private
173169
public WALEdit add(Cell cell) {
174170
// We clone Family each time we add a Cell. Expensive but safe. For CPU savings, use
175171
// add(Map) or add(Cell, family).

hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/SimpleRegionObserver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ public StoreFileReader postStoreFileReaderOpen(ObserverContext<RegionCoprocessor
638638

639639
@Override
640640
public void preWALAppend(ObserverContext<RegionCoprocessorEnvironment> ctx,
641-
WALKey key) throws IOException {
641+
WALKey key, WALEdit edit) throws IOException {
642642
ctPreWALAppend.incrementAndGet();
643643

644644
key.addExtendedAttribute(Integer.toString(ctPreWALAppend.get()),

hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverInterface.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,8 @@ public void testPreWALAppend() throws Exception {
707707
ObserverContext ctx = Mockito.mock(ObserverContext.class);
708708
WALKey key = new WALKeyImpl(Bytes.toBytes("region"), TEST_TABLE,
709709
EnvironmentEdgeManager.currentTime());
710-
sro.preWALAppend(ctx, key);
710+
WALEdit edit = new WALEdit();
711+
sro.preWALAppend(ctx, key, edit);
711712
Assert.assertEquals(1, key.getExtendedAttributes().size());
712713
Assert.assertArrayEquals(SimpleRegionObserver.WAL_EXTENDED_ATTRIBUTE_BYTES,
713714
key.getExtendedAttribute(Integer.toString(sro.getCtPreWALAppend())));

0 commit comments

Comments
 (0)