@@ -46,7 +46,7 @@ public void prepareCase() throws Exception {
46
46
}
47
47
48
48
public static void testTTLImpl (List <String > tableNames ) throws Exception {
49
- closeTTLExecute ();
49
+ disableTTL ();
50
50
// 0. prepare data
51
51
String keys [] = {"putKey1" , "putKey2" , "putKey3" };
52
52
String endKey = "putKey4" ;
@@ -94,7 +94,8 @@ public static void testTTLImpl(List<String> tableNames) throws Exception {
94
94
}
95
95
96
96
// 4. open ttl knob to delete expired hbase data
97
- openTTLExecute ();
97
+ enableTTL ();
98
+ triggerTTL ();
98
99
99
100
// 5. check util expired hbase data is deleted by ttl tasks
100
101
checkUtilTimeout (()-> {
@@ -110,11 +111,11 @@ public static void testTTLImpl(List<String> tableNames) throws Exception {
110
111
}
111
112
112
113
// 6. close ttl knob
113
- closeTTLExecute ();
114
+ disableTTL ();
114
115
}
115
116
116
117
public static void testMultiCFTTLImpl (Map <String , List <String >> group2tableNames ) throws Exception {
117
- closeTTLExecute ();
118
+ disableTTL ();
118
119
List <String > allTableNames = group2tableNames .values ().stream ().flatMap (Collection ::stream ).collect (Collectors .toList ());
119
120
// 0. prepare data
120
121
String keys [] = {"putKey1" , "putKey2" , "putKey3" };
@@ -127,7 +128,6 @@ public static void testMultiCFTTLImpl(Map<String, List<String>> group2tableNames
127
128
OHTableClient hTable = ObHTableTestUtil .newOHTableClient (groupName );
128
129
hTable .init ();
129
130
List <String > tableNames = entry .getValue ();
130
-
131
131
for (String tableName : tableNames ) {
132
132
String family = getColumnFamilyName (tableName );
133
133
for (String key : keys ) {
@@ -168,7 +168,8 @@ public static void testMultiCFTTLImpl(Map<String, List<String>> group2tableNames
168
168
}
169
169
170
170
// 4. open ttl knob to delete expired hbase data
171
- openTTLExecute ();
171
+ enableTTL ();
172
+ triggerTTL ();
172
173
173
174
// 5. check util expired hbase data is deleted by ttl tasks
174
175
checkUtilTimeout (()-> {
@@ -184,7 +185,159 @@ public static void testMultiCFTTLImpl(Map<String, List<String>> group2tableNames
184
185
}
185
186
186
187
// 6. close ttl knob
187
- closeTTLExecute ();
188
+ disableTTL ();
189
+ }
190
+
191
+ void testRowkeyTTL (List <String > tableNames , Boolean useScan , Boolean isReversed ) throws Exception {
192
+ disableTTL ();
193
+ // 0. prepare data
194
+ String keys [] = {"putKey1" , "putKey2" , "putKey3" };
195
+ String endKey = "putKey4" ;
196
+ String columns [] = {"putColumn1" , "putColumn2" };
197
+ String values [] = {"putValue1" , "putValue2" , "putValue3" , "putValue4" };
198
+ for (String tableName : tableNames ) {
199
+ OHTableClient hTable = ObHTableTestUtil .newOHTableClient (getTableName (tableName ));
200
+ hTable .init ();
201
+ String family = getColumnFamilyName (tableName );
202
+ for (String key : keys ) {
203
+ for (String column : columns ) {
204
+ for (int i = 0 ; i < values .length ; i ++) {
205
+ Put put = new Put (toBytes (key ));
206
+ put .add (family .getBytes (), column .getBytes (), values [i ].getBytes ());
207
+ hTable .put (put );
208
+ }
209
+ }
210
+ }
211
+ }
212
+
213
+ // 1. sleep util data expired
214
+ sleep (12000 );
215
+
216
+ // 2. enable kv ttl
217
+ enableTTL ();
218
+
219
+ // 3. SQL can scan expired but not delete yet hbase data
220
+ for (String tableName : tableNames ) {
221
+ Assert .assertEquals (keys .length * columns .length * values .length ,
222
+ getSQLTableRowCnt (tableName ));
223
+ }
224
+
225
+ // 4. use Hbase scan/get expired data to trigger ttl
226
+ for (String tableName : tableNames ) {
227
+ OHTableClient hTable = ObHTableTestUtil .newOHTableClient (getTableName (tableName ));
228
+ hTable .init ();
229
+ String family = getColumnFamilyName (tableName );
230
+ if (useScan ) {
231
+ Scan scan = new Scan (keys [0 ].getBytes (), endKey .getBytes ());
232
+ scan .addFamily (family .getBytes ());
233
+ scan .setReversed (isReversed );
234
+ ResultScanner scanner = hTable .getScanner (scan );
235
+ List <Cell > cells = getCellsFromScanner (scanner );
236
+ assertEquals (0 , cells .size ());
237
+ } else {
238
+ for (String key : keys ) {
239
+ Get get = new Get (key .getBytes ());
240
+ get .addFamily (family .getBytes ());
241
+ Result result = hTable .get (get );
242
+ assertEquals (0 , result .rawCells ().length );
243
+ }
244
+ }
245
+ }
246
+
247
+ // 5. wait to disable
248
+ checkUtilTimeout (()-> {
249
+ try {
250
+ Boolean passed = true ;
251
+ for (int i = 0 ; passed && i < tableNames .size (); i ++) {
252
+ if (getSQLTableRowCnt (tableNames .get (i )) > 0 ) {
253
+ passed = false ;
254
+ }
255
+ }
256
+ return passed ;
257
+ } catch (Exception e ) {
258
+ throw new RuntimeException (e );
259
+ }
260
+ }, 50000 , 3000 );
261
+
262
+ // 6. disable ttl
263
+ disableTTL ();
264
+ }
265
+
266
+ void testMultiCFRowkeyTTL (Map <String , List <String >> group2tableNames , Boolean useScan , Boolean isReversed ) throws Exception {
267
+ disableTTL ();
268
+ List <String > allTableNames = group2tableNames .values ().stream ().flatMap (Collection ::stream ).collect (Collectors .toList ());
269
+ // 0. prepare data
270
+ String keys [] = {"putKey1" , "putKey2" , "putKey3" };
271
+ String endKey = "putKey4" ;
272
+ String columns [] = {"putColumn1" , "putColumn2" };
273
+ String values [] = {"putValue1" , "putValue2" , "putValue3" , "putValue4" };
274
+ for (Map .Entry <String , List <String >> entry : group2tableNames .entrySet ()) {
275
+ String groupName = getTableName (entry .getKey ());
276
+ OHTableClient hTable = ObHTableTestUtil .newOHTableClient (groupName );
277
+ hTable .init ();
278
+ for (String tableName : entry .getValue ()) {
279
+ String family = getColumnFamilyName (tableName );
280
+ for (String key : keys ) {
281
+ for (String column : columns ) {
282
+ for (int i = 0 ; i < values .length ; i ++) {
283
+ Put put = new Put (toBytes (key ));
284
+ put .add (family .getBytes (), column .getBytes (), values [i ].getBytes ());
285
+ hTable .put (put );
286
+ }
287
+ }
288
+ }
289
+ }
290
+ }
291
+
292
+ // 1. sleep util data expired
293
+ sleep (12000 );
294
+
295
+ // 2. enable kv ttl
296
+ enableTTL ();
297
+
298
+ // 3. SQL can scan expired but not delete yet hbase data
299
+ for (String tableName : allTableNames ) {
300
+ Assert .assertEquals (keys .length * columns .length * values .length ,
301
+ getSQLTableRowCnt (tableName ));
302
+ }
303
+
304
+ // 4. use Hbase scan expired data to trigger ttl
305
+ for (Map .Entry <String , List <String >> entry : group2tableNames .entrySet ()) {
306
+ String groupName = getTableName (entry .getKey ());
307
+ OHTableClient hTable = ObHTableTestUtil .newOHTableClient (groupName );
308
+ hTable .init ();
309
+ if (useScan ) {
310
+ Scan scan = new Scan (keys [0 ].getBytes (), endKey .getBytes ());
311
+ scan .setReversed (isReversed );
312
+ ResultScanner scanner = hTable .getScanner (scan );
313
+ List <Cell > cells = getCellsFromScanner (scanner );
314
+ assertEquals (0 , cells .size ());
315
+ } else {
316
+ for (String key : keys ) {
317
+ Get get = new Get (key .getBytes ());
318
+ Result result = hTable .get (get );
319
+ assertEquals (0 , result .rawCells ().length );
320
+ }
321
+ }
322
+ }
323
+
324
+ // 5. wait to disable
325
+ checkUtilTimeout (()-> {
326
+ try {
327
+ Boolean passed = true ;
328
+ for (int i = 0 ; passed && i < allTableNames .size (); i ++) {
329
+ if (getSQLTableRowCnt (allTableNames .get (i )) > 0 ) {
330
+ passed = false ;
331
+ }
332
+ }
333
+ return passed ;
334
+ } catch (Exception e ) {
335
+ throw new RuntimeException (e );
336
+ }
337
+ }, 70000 , 5000 );
338
+
339
+ // 6. disable ttl
340
+ disableTTL ();
188
341
}
189
342
190
343
@@ -197,4 +350,20 @@ public void testTTL() throws Throwable {
197
350
public void testMultiCFTTL () throws Throwable {
198
351
testMultiCFTTLImpl (group2tableNames );
199
352
}
353
+
354
+ @ Test
355
+ public void testRowkeyTTL () throws Exception {
356
+ testRowkeyTTL (tableNames , true , false );
357
+ testRowkeyTTL (tableNames , false , false );
358
+ // TODO: open the test after reverse scan is ok
359
+ // testRowkeyTTL(tableNames, true);
360
+ }
361
+
362
+ @ Test
363
+ public void testMultiCFRowkeyTTL () throws Exception {
364
+ testMultiCFRowkeyTTL (group2tableNames , true , false );
365
+ testMultiCFRowkeyTTL (group2tableNames , false , false );
366
+ // TODO: open the test after reverse scan is ok
367
+ // testMultiCFRowkeyTTL(group2tableNames, true, true);
368
+ }
200
369
}
0 commit comments