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