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 B9B26DD1B for ; Thu, 16 Aug 2012 00:24:32 +0000 (UTC) Received: (qmail 27574 invoked by uid 500); 16 Aug 2012 00:24:32 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 27538 invoked by uid 500); 16 Aug 2012 00:24:32 -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 27525 invoked by uid 99); 16 Aug 2012 00:24:32 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Aug 2012 00:24:32 +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; Thu, 16 Aug 2012 00:24:29 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 806F62388962 for ; Thu, 16 Aug 2012 00:23:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1373679 - in /hbase/branches/0.94/src: main/java/org/apache/hadoop/hbase/KeyValue.java main/java/org/apache/hadoop/hbase/regionserver/HRegion.java test/java/org/apache/hadoop/hbase/client/TestFakeKeyInFilter.java Date: Thu, 16 Aug 2012 00:23:45 -0000 To: commits@hbase.apache.org From: larsh@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120816002345.806F62388962@eris.apache.org> Author: larsh Date: Thu Aug 16 00:23:44 2012 New Revision: 1373679 URL: http://svn.apache.org/viewvc?rev=1373679&view=rev Log: HBASE-6562 Fake KVs are sometimes passed to filters Added: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestFakeKeyInFilter.java Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/KeyValue.java hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/KeyValue.java URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/KeyValue.java?rev=1373679&r1=1373678&r2=1373679&view=diff ============================================================================== --- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/KeyValue.java (original) +++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/KeyValue.java Thu Aug 16 00:23:44 2012 @@ -955,6 +955,14 @@ public class KeyValue implements Writabl } /** + * @return True if this is a "fake" KV created for internal seeking purposes, + * which should not be seen by user code + */ + public boolean isInternal() { + byte type = getType(); + return type == Type.Minimum.code || type == Type.Maximum.code; + } + /** * @param now Time to set into this IFF timestamp == * {@link HConstants#LATEST_TIMESTAMP} (else, its a noop). * @return True is we modified this. Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?rev=1373679&r1=1373678&r2=1373679&view=diff ============================================================================== --- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java (original) +++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java Thu Aug 16 00:23:44 2012 @@ -3441,7 +3441,8 @@ public class HRegion implements HeapSize rpcCall.throwExceptionIfCallerDisconnected(); } - byte [] currentRow = peekRow(); + KeyValue kv = this.storeHeap.peek(); + byte [] currentRow = kv == null ? null : kv.getRow(); if (isStopRow(currentRow)) { if (filter != null && filter.hasFilterRow()) { filter.filterRow(results); @@ -3451,7 +3452,7 @@ public class HRegion implements HeapSize } return false; - } else if (filterRowKey(currentRow)) { + } else if (kv != null && !kv.isInternal() && filterRowKey(currentRow)) { nextRow(currentRow); } else { byte [] nextRow; Added: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestFakeKeyInFilter.java URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestFakeKeyInFilter.java?rev=1373679&view=auto ============================================================================== --- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestFakeKeyInFilter.java (added) +++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestFakeKeyInFilter.java Thu Aug 16 00:23:44 2012 @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import java.util.ArrayList; + +import org.apache.hadoop.hbase.*; +import org.apache.hadoop.hbase.filter.*; +import org.apache.hadoop.hbase.regionserver.HRegion; +import org.apache.hadoop.hbase.regionserver.RegionScanner; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.FSUtils; +import org.junit.*; +import org.junit.experimental.categories.Category; + +/** + * Make sure the fake KVs created internally are never user visible + * (not even to filters) + */ +@Category(SmallTests.class) +public class TestFakeKeyInFilter extends BinaryComparator { + protected static HBaseTestingUtility UTIL = new HBaseTestingUtility(); + + public TestFakeKeyInFilter() { + super(Bytes.toBytes("foo")); + } + + @Override + public int compareTo(byte[] value, int offset, int length) { + if (value.length == 0) { + throw new RuntimeException("Found mysterious empty row"); + } + return 0; + } + + /** + * Simple way to verify the scenario. + * There are no KVs with an empty row key in the + * table, yet such a KV is presented to the filter. + */ + @Test + public void testForEmptyRowKey() throws Exception { + byte[] table = Bytes.toBytes("testForEmptyRowKey"); + byte[] row = Bytes.toBytes("myRow"); + byte[] cf = Bytes.toBytes("myFamily"); + byte[] cq = Bytes.toBytes("myColumn"); + HTableDescriptor desc = new HTableDescriptor(table); + desc.addFamily(new HColumnDescriptor(cf)); + HRegionInfo hri = new HRegionInfo(desc.getName(), null, null); + HRegion region = HRegion.createHRegion(hri, FSUtils.getRootDir(UTIL.getConfiguration()), UTIL.getConfiguration(), desc); + Put put = new Put(row); + put.add(cf, cq, cq); + region.put(put); + region.flushcache(); + Scan scan = new Scan(); + scan.addColumn(cf, cq); + WritableByteArrayComparable comparable = new TestFakeKeyInFilter(); + Filter filter = new RowFilter(CompareFilter.CompareOp.EQUAL, comparable); + scan.setFilter(filter); + RegionScanner scanner = region.getScanner(scan); + scanner.next(new ArrayList()); + scanner.close(); + region.close(); + } + + @org.junit.Rule + public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu = + new org.apache.hadoop.hbase.ResourceCheckerJUnitRule(); +}