HBASE-9038 Compaction WALEdit gives NPEs with Replication enabled
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1508255 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fd991fe908
commit
45968ad1b9
|
@ -222,11 +222,25 @@ public class Replication implements WALActionsListener,
|
|||
@Override
|
||||
public void visitLogEntryBeforeWrite(HTableDescriptor htd, HLogKey logKey,
|
||||
WALEdit logEdit) {
|
||||
scopeWALEdits(htd, logKey, logEdit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method used to set the correct scopes on each log key. Doesn't set a scope on keys
|
||||
* from compaction WAL edits and if the scope is local.
|
||||
* @param htd Descriptor used to find the scope to use
|
||||
* @param logKey Key that may get scoped according to its edits
|
||||
* @param logEdit Edits used to lookup the scopes
|
||||
*/
|
||||
public static void scopeWALEdits(HTableDescriptor htd, HLogKey logKey,
|
||||
WALEdit logEdit) {
|
||||
NavigableMap<byte[], Integer> scopes =
|
||||
new TreeMap<byte[], Integer>(Bytes.BYTES_COMPARATOR);
|
||||
byte[] family;
|
||||
for (KeyValue kv : logEdit.getKeyValues()) {
|
||||
family = kv.getFamily();
|
||||
if (kv.matchingFamily(WALEdit.METAFAMILY)) continue;
|
||||
|
||||
int scope = htd.getFamily(family).getScope();
|
||||
if (scope != REPLICATION_SCOPE_LOCAL &&
|
||||
!scopes.containsKey(family)) {
|
||||
|
|
|
@ -24,6 +24,10 @@ import org.apache.hadoop.hbase.KeyValue;
|
|||
import org.apache.hadoop.hbase.LargeTests;
|
||||
import org.apache.hadoop.hbase.client.*;
|
||||
import org.apache.hadoop.hbase.mapreduce.replication.VerifyReplication;
|
||||
import org.apache.hadoop.hbase.protobuf.generated.WALProtos;
|
||||
import org.apache.hadoop.hbase.regionserver.wal.HLogKey;
|
||||
import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
|
||||
import org.apache.hadoop.hbase.replication.regionserver.Replication;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
|
||||
import org.apache.hadoop.hbase.util.JVMClusterUtil;
|
||||
|
@ -461,4 +465,17 @@ public class TestReplicationSmallTests extends TestReplicationBase {
|
|||
findCounter(VerifyReplication.Verifier.Counters.BADROWS).getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for HBASE-9038, Replication.scopeWALEdits would NPE if it wasn't filtering out
|
||||
* the compaction WALEdit
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test(timeout=300000)
|
||||
public void testCompactionWALEdits() throws Exception {
|
||||
WALProtos.CompactionDescriptor compactionDescriptor =
|
||||
WALProtos.CompactionDescriptor.getDefaultInstance();
|
||||
WALEdit edit = WALEdit.createCompaction(compactionDescriptor);
|
||||
Replication.scopeWALEdits(htable1.getTableDescriptor(), new HLogKey(), edit);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue