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