Author: jdcryans
Date: Tue Jul 30 00:11:01 2013
New Revision: 1508255
URL: http://svn.apache.org/r1508255
Log:
HBASE-9038 Compaction WALEdit gives NPEs with Replication enabled
Modified:
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java
hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSmallTests.java
Modified:
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java
URL:
http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java?rev=1508255&r1=1508254&r2=1508255&view=diff
==============================================================================
---
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java
(original)
+++
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java
Tue Jul 30 00:11:01 2013
@@ -222,11 +222,25 @@ public class Replication implements WALA
@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)) {
Modified:
hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSmallTests.java
URL:
http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSmallTests.java?rev=1508255&r1=1508254&r2=1508255&view=diff
==============================================================================
---
hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSmallTests.java
(original)
+++
hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSmallTests.java
Tue Jul 30 00:11:01 2013
@@ -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 e
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);
+ }
+
}