View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional information regarding
4    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable
7    * law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
8    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
9    * for the specific language governing permissions and limitations under the License.
10   */
11  package org.apache.hadoop.hbase.regionserver;
12  
13  import java.util.ArrayList;
14  import java.util.List;
15  import org.apache.hadoop.conf.Configuration;
16  import org.apache.hadoop.hbase.HBaseTestingUtility;
17  import org.apache.hadoop.hbase.HTableDescriptor;
18  import org.apache.hadoop.hbase.TableName;
19  import org.apache.hadoop.hbase.client.Delete;
20  import org.apache.hadoop.hbase.client.Mutation;
21  import org.apache.hadoop.hbase.client.Put;
22  import org.apache.hadoop.hbase.client.Result;
23  import org.apache.hadoop.hbase.client.Scan;
24  import org.apache.hadoop.hbase.client.Table;
25  import org.apache.hadoop.hbase.filter.BinaryComparator;
26  import org.apache.hadoop.hbase.filter.CompareFilter;
27  import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
28  import org.apache.hadoop.hbase.testclassification.FilterTests;
29  import org.apache.hadoop.hbase.testclassification.MediumTests;
30  import org.apache.hadoop.hbase.testclassification.RegionServerTests;
31  import org.apache.hadoop.hbase.util.Bytes;
32  import org.junit.AfterClass;
33  import org.junit.BeforeClass;
34  import org.junit.Rule;
35  import org.junit.Test;
36  import org.junit.experimental.categories.Category;
37  import org.junit.rules.TestName;
38  
39  /**
40   * Test failure in ScanDeleteTracker.isDeleted when ROWCOL bloom filter is used during a scan with a
41   * filter.
42   */
43  @Category({ RegionServerTests.class, FilterTests.class, MediumTests.class })
44  public class TestIsDeleteFailure {
45    private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
46  
47    @Rule
48    public TestName name = new TestName();
49  
50    @BeforeClass
51    public static void setUpBeforeClass() throws Exception {
52      TEST_UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", 100);
53      TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 250);
54      TEST_UTIL.getConfiguration().setInt("hbase.client.retries.number", 2);
55      TEST_UTIL.getConfiguration().setBoolean("hbase.master.enabletable.roundrobin", true);
56      TEST_UTIL.startMiniCluster(1);
57    }
58  
59    @AfterClass
60    public static void tearDownAfterClass() throws Exception {
61      TEST_UTIL.shutdownMiniCluster();
62    }
63  
64    @Test
65    public void testIsDeleteFailure() throws Exception {
66      final HTableDescriptor table = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
67      final byte[] family = Bytes.toBytes("0");
68      final byte[] c2 = Bytes.toBytes("C02");
69      final byte[] c3 = Bytes.toBytes("C03");
70      final byte[] c4 = Bytes.toBytes("C04");
71      final byte[] c5 = Bytes.toBytes("C05");
72      final byte[] c6 = Bytes.toBytes("C07");
73      final byte[] c7 = Bytes.toBytes("C07");
74      final byte[] c8 = Bytes.toBytes("C08");
75      final byte[] c9 = Bytes.toBytes("C09");
76      final byte[] c10 = Bytes.toBytes("C10");
77      final byte[] c12 = Bytes.toBytes("C12");
78      final byte[] c13 = Bytes.toBytes("C13");
79      final byte[] c14 = Bytes.toBytes("C14");
80      final byte[] c15 = Bytes.toBytes("C15");
81  
82      final byte[] val = Bytes.toBytes("foo");
83      List<byte[]> fams = new ArrayList<>(1);
84      fams.add(family);
85      Table ht = TEST_UTIL.createTable(table, fams.toArray(new byte[0][]), null, BloomType.ROWCOL,
86        10000, new Configuration(TEST_UTIL.getConfiguration()));
87      List<Mutation> pending = new ArrayList<>();
88      for (int i = 0; i < 1000; i++) {
89        byte[] row = Bytes.toBytes("key" + i);
90        Put put = new Put(row);
91        put.addColumn(family, c3, val);
92        put.addColumn(family, c4, val);
93        put.addColumn(family, c5, val);
94        put.addColumn(family, c6, val);
95        put.addColumn(family, c7, val);
96        put.addColumn(family, c8, val);
97        put.addColumn(family, c12, val);
98        put.addColumn(family, c13, val);
99        put.addColumn(family, c15, val);
100       pending.add(put);
101       Delete del = new Delete(row);
102       del.addColumns(family, c2);
103       del.addColumns(family, c9);
104       del.addColumns(family, c10);
105       del.addColumns(family, c14);
106       pending.add(del);
107     }
108     ht.batch(pending, new Object[pending.size()]);
109     TEST_UTIL.flush();
110     TEST_UTIL.compact(true);
111     for (int i = 20; i < 300; i++) {
112       byte[] row = Bytes.toBytes("key" + i);
113       Put put = new Put(row);
114       put.addColumn(family, c3, val);
115       put.addColumn(family, c4, val);
116       put.addColumn(family, c5, val);
117       put.addColumn(family, c6, val);
118       put.addColumn(family, c7, val);
119       put.addColumn(family, c8, val);
120       put.addColumn(family, c12, val);
121       put.addColumn(family, c13, val);
122       put.addColumn(family, c15, val);
123       pending.add(put);
124       Delete del = new Delete(row);
125       del.addColumns(family, c2);
126       del.addColumns(family, c9);
127       del.addColumns(family, c10);
128       del.addColumns(family, c14);
129       pending.add(del);
130     }
131     ht.batch(pending, new Object[pending.size()]);
132     TEST_UTIL.flush();
133 
134     Scan scan = new Scan();
135     scan.addColumn(family, c9);
136     scan.addColumn(family, c15);
137     SingleColumnValueFilter filter = new SingleColumnValueFilter(family, c15,
138         CompareFilter.CompareOp.EQUAL, new BinaryComparator(c15));
139     scan.setFilter(filter);
140     // Trigger the scan for not existing row, so it will scan over all rows
141     for (Result result : ht.getScanner(scan)) {
142       result.advance();
143     }
144     ht.close();
145   }
146 }