41
41
import org .apache .hadoop .hbase .Tag ;
42
42
import org .apache .hadoop .hbase .client .Admin ;
43
43
import org .apache .hadoop .hbase .client .Append ;
44
+ import org .apache .hadoop .hbase .client .ColumnFamilyDescriptorBuilder ;
44
45
import org .apache .hadoop .hbase .client .CompactionState ;
46
+ import org .apache .hadoop .hbase .client .Connection ;
47
+ import org .apache .hadoop .hbase .client .ConnectionFactory ;
45
48
import org .apache .hadoop .hbase .client .Durability ;
46
49
import org .apache .hadoop .hbase .client .Increment ;
47
50
import org .apache .hadoop .hbase .client .Mutation ;
50
53
import org .apache .hadoop .hbase .client .ResultScanner ;
51
54
import org .apache .hadoop .hbase .client .Scan ;
52
55
import org .apache .hadoop .hbase .client .Table ;
56
+ import org .apache .hadoop .hbase .client .TableDescriptorBuilder ;
53
57
import org .apache .hadoop .hbase .coprocessor .CoprocessorHost ;
54
58
import org .apache .hadoop .hbase .coprocessor .ObserverContext ;
55
59
import org .apache .hadoop .hbase .coprocessor .RegionCoprocessor ;
68
72
import org .junit .Test ;
69
73
import org .junit .experimental .categories .Category ;
70
74
import org .junit .rules .TestName ;
75
+ import org .slf4j .Logger ;
76
+ import org .slf4j .LoggerFactory ;
71
77
72
78
/**
73
79
* Class that test tags
@@ -78,6 +84,8 @@ public class TestTags {
78
84
@ ClassRule
79
85
public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule .forClass (TestTags .class );
80
86
87
+ private static final Logger LOG = LoggerFactory .getLogger (TestTags .class );
88
+
81
89
static boolean useFilter = false ;
82
90
83
91
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility ();
@@ -104,6 +112,71 @@ public void tearDown() {
104
112
useFilter = false ;
105
113
}
106
114
115
+ /**
116
+ * Test that we can do reverse scans when writing tags and using DataBlockEncoding. Fails with an
117
+ * exception for PREFIX, DIFF, and FAST_DIFF prior to HBASE-27580
118
+ */
119
+ @ Test
120
+ public void testReverseScanWithDBE () throws IOException {
121
+ byte [] family = Bytes .toBytes ("0" );
122
+
123
+ Configuration conf = new Configuration (TEST_UTIL .getConfiguration ());
124
+ conf .setInt (HConstants .HBASE_CLIENT_RETRIES_NUMBER , 1 );
125
+
126
+ try (Connection connection = ConnectionFactory .createConnection (conf )) {
127
+ for (DataBlockEncoding encoding : DataBlockEncoding .values ()) {
128
+ testReverseScanWithDBE (connection , encoding , family );
129
+ }
130
+ }
131
+ }
132
+
133
+ private void testReverseScanWithDBE (Connection conn , DataBlockEncoding encoding , byte [] family )
134
+ throws IOException {
135
+ LOG .info ("Running test with DBE={}" , encoding );
136
+ TableName tableName = TableName .valueOf (TEST_NAME .getMethodName () + "-" + encoding );
137
+ TEST_UTIL .createTable (TableDescriptorBuilder .newBuilder (tableName )
138
+ .setColumnFamily (
139
+ ColumnFamilyDescriptorBuilder .newBuilder (family ).setDataBlockEncoding (encoding ).build ())
140
+ .build (), null );
141
+
142
+ Table table = conn .getTable (tableName );
143
+
144
+ int maxRows = 10 ;
145
+ byte [] val1 = new byte [10 ];
146
+ byte [] val2 = new byte [10 ];
147
+ Bytes .random (val1 );
148
+ Bytes .random (val2 );
149
+
150
+ for (int i = 0 ; i < maxRows ; i ++) {
151
+ if (i == maxRows / 2 ) {
152
+ TEST_UTIL .flush (tableName );
153
+ }
154
+ table .put (new Put (Bytes .toBytes (i )).addColumn (family , Bytes .toBytes (1 ), val1 )
155
+ .addColumn (family , Bytes .toBytes (2 ), val2 ).setTTL (600_000 ));
156
+ }
157
+
158
+ TEST_UTIL .flush (table .getName ());
159
+
160
+ Scan scan = new Scan ();
161
+ scan .setReversed (true );
162
+
163
+ try (ResultScanner scanner = table .getScanner (scan )) {
164
+ for (int i = maxRows - 1 ; i >= 0 ; i --) {
165
+ Result row = scanner .next ();
166
+ assertEquals (2 , row .size ());
167
+
168
+ Cell cell1 = row .getColumnLatestCell (family , Bytes .toBytes (1 ));
169
+ assertTrue (CellUtil .matchingRows (cell1 , Bytes .toBytes (i )));
170
+ assertTrue (CellUtil .matchingValue (cell1 , val1 ));
171
+
172
+ Cell cell2 = row .getColumnLatestCell (family , Bytes .toBytes (2 ));
173
+ assertTrue (CellUtil .matchingRows (cell2 , Bytes .toBytes (i )));
174
+ assertTrue (CellUtil .matchingValue (cell2 , val2 ));
175
+ }
176
+ }
177
+
178
+ }
179
+
107
180
@ Test
108
181
public void testTags () throws Exception {
109
182
Table table = null ;
0 commit comments