Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A8F9810A3E for ; Tue, 30 Jul 2013 00:10:24 +0000 (UTC) Received: (qmail 28210 invoked by uid 500); 30 Jul 2013 00:10:24 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 28176 invoked by uid 500); 30 Jul 2013 00:10:24 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 28169 invoked by uid 99); 30 Jul 2013 00:10:24 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Jul 2013 00:10:24 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Jul 2013 00:10:22 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 59EB223888E2; Tue, 30 Jul 2013 00:10:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1508254 - in /hbase/branches/0.95/hbase-server/src: main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java test/java/org/apache/hadoop/hbase/replication/TestReplicationSmallTests.java Date: Tue, 30 Jul 2013 00:10:02 -0000 To: commits@hbase.apache.org From: jdcryans@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130730001002.59EB223888E2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jdcryans Date: Tue Jul 30 00:10:01 2013 New Revision: 1508254 URL: http://svn.apache.org/r1508254 Log: HBASE-9038 Compaction WALEdit gives NPEs with Replication enabled Modified: hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSmallTests.java Modified: hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java?rev=1508254&r1=1508253&r2=1508254&view=diff ============================================================================== --- hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java (original) +++ hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java Tue Jul 30 00:10: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 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)) { Modified: hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSmallTests.java URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSmallTests.java?rev=1508254&r1=1508253&r2=1508254&view=diff ============================================================================== --- hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSmallTests.java (original) +++ hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSmallTests.java Tue Jul 30 00:10: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); + } + }