001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 * http://www.apache.org/licenses/LICENSE-2.0
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.apache.hadoop.hbase.regionserver;
017
018import java.util.ArrayList;
019import java.util.List;
020import org.apache.hadoop.conf.Configuration;
021import org.apache.hadoop.hbase.CompareOperator;
022import org.apache.hadoop.hbase.HBaseClassTestRule;
023import org.apache.hadoop.hbase.HBaseTestingUtility;
024import org.apache.hadoop.hbase.HTableDescriptor;
025import org.apache.hadoop.hbase.TableName;
026import org.apache.hadoop.hbase.client.Delete;
027import org.apache.hadoop.hbase.client.Mutation;
028import org.apache.hadoop.hbase.client.Put;
029import org.apache.hadoop.hbase.client.Result;
030import org.apache.hadoop.hbase.client.Scan;
031import org.apache.hadoop.hbase.client.Table;
032import org.apache.hadoop.hbase.filter.BinaryComparator;
033import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
034import org.apache.hadoop.hbase.testclassification.FilterTests;
035import org.apache.hadoop.hbase.testclassification.MediumTests;
036import org.apache.hadoop.hbase.testclassification.RegionServerTests;
037import org.apache.hadoop.hbase.util.Bytes;
038import org.junit.AfterClass;
039import org.junit.BeforeClass;
040import org.junit.ClassRule;
041import org.junit.Rule;
042import org.junit.Test;
043import org.junit.experimental.categories.Category;
044import org.junit.rules.TestName;
045
046/**
047 * Test failure in ScanDeleteTracker.isDeleted when ROWCOL bloom filter
048 * is used during a scan with a filter.
049 */
050@Category({ RegionServerTests.class, FilterTests.class, MediumTests.class })
051public class TestIsDeleteFailure {
052  private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
053
054  @ClassRule
055  public static final HBaseClassTestRule CLASS_RULE =
056      HBaseClassTestRule.forClass(TestIsDeleteFailure.class);
057
058  @Rule public TestName name = new TestName();
059
060  @BeforeClass
061  public static void setUpBeforeClass() throws Exception {
062    TEST_UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", 100);
063    TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 250);
064    TEST_UTIL.getConfiguration().setInt("hbase.client.retries.number", 2);
065    TEST_UTIL.getConfiguration().setBoolean("hbase.master.enabletable.roundrobin", true);
066    TEST_UTIL.startMiniCluster(1);
067  }
068
069  @AfterClass
070  public static void tearDownAfterClass() throws Exception {
071    TEST_UTIL.shutdownMiniCluster();
072  }
073
074  @Test
075  public void testIsDeleteFailure() throws Exception {
076    final HTableDescriptor table = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
077    final byte[] family = Bytes.toBytes("0");
078    final byte[] c1 = Bytes.toBytes("C01");
079    final byte[] c2 = Bytes.toBytes("C02");
080    final byte[] c3 = Bytes.toBytes("C03");
081    final byte[] c4 = Bytes.toBytes("C04");
082    final byte[] c5 = Bytes.toBytes("C05");
083    final byte[] c6 = Bytes.toBytes("C07");
084    final byte[] c7 = Bytes.toBytes("C07");
085    final byte[] c8 = Bytes.toBytes("C08");
086    final byte[] c9 = Bytes.toBytes("C09");
087    final byte[] c10 = Bytes.toBytes("C10");
088    final byte[] c11 = Bytes.toBytes("C11");
089    final byte[] c12 = Bytes.toBytes("C12");
090    final byte[] c13 = Bytes.toBytes("C13");
091    final byte[] c14 = Bytes.toBytes("C14");
092    final byte[] c15 = Bytes.toBytes("C15");
093
094    final byte[] val = Bytes.toBytes("foo");
095    List<byte[]> fams = new ArrayList<>(1);
096    fams.add(family);
097    Table ht = TEST_UTIL
098        .createTable(table, fams.toArray(new byte[0][]), null, BloomType.ROWCOL, 10000,
099            new Configuration(TEST_UTIL.getConfiguration()));
100    List<Mutation> pending = new ArrayList<Mutation>();
101    for (int i = 0; i < 1000; i++) {
102      byte[] row = Bytes.toBytes("key" + Integer.toString(i));
103      Put put = new Put(row);
104      put.addColumn(family, c3, val);
105      put.addColumn(family, c4, val);
106      put.addColumn(family, c5, val);
107      put.addColumn(family, c6, val);
108      put.addColumn(family, c7, val);
109      put.addColumn(family, c8, val);
110      put.addColumn(family, c12, val);
111      put.addColumn(family, c13, val);
112      put.addColumn(family, c15, val);
113      pending.add(put);
114      Delete del = new Delete(row);
115      del.addColumns(family, c2);
116      del.addColumns(family, c9);
117      del.addColumns(family, c10);
118      del.addColumns(family, c14);
119      pending.add(del);
120    }
121    ht.batch(pending, new Object[pending.size()]);
122    TEST_UTIL.flush();
123    TEST_UTIL.compact(true);
124    for (int i = 20; i < 300; i++) {
125      byte[] row = Bytes.toBytes("key" + Integer.toString(i));
126      Put put = new Put(row);
127      put.addColumn(family, c3, val);
128      put.addColumn(family, c4, val);
129      put.addColumn(family, c5, val);
130      put.addColumn(family, c6, val);
131      put.addColumn(family, c7, val);
132      put.addColumn(family, c8, val);
133      put.addColumn(family, c12, val);
134      put.addColumn(family, c13, val);
135      put.addColumn(family, c15, val);
136      pending.add(put);
137      Delete del = new Delete(row);
138      del.addColumns(family, c2);
139      del.addColumns(family, c9);
140      del.addColumns(family, c10);
141      del.addColumns(family, c14);
142      pending.add(del);
143    }
144    ht.batch(pending, new Object[pending.size()]);
145    TEST_UTIL.flush();
146
147    Scan scan = new Scan();
148    scan.addColumn(family, c9);
149    scan.addColumn(family, c15);
150    SingleColumnValueFilter filter =
151        new SingleColumnValueFilter(family, c15, CompareOperator.EQUAL,
152            new BinaryComparator(c15));
153    scan.setFilter(filter);
154    //Trigger the scan for not existing row, so it will scan over all rows
155    for (Result result : ht.getScanner(scan)) {
156      result.advance();
157    }
158    ht.close();
159  }
160}