Index: hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java (revision 1508208) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java (working copy) @@ -222,11 +222,25 @@ @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 scopes = new TreeMap(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)) { Index: hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSmallTests.java =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSmallTests.java (revision 1508208) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSmallTests.java (working copy) @@ -24,6 +24,10 @@ 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 @@ 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); + } + }