@@ -405,59 +405,84 @@ private void writeStoreFile(boolean useTags) throws IOException {
405
405
storeFilePath = sfw .getPath ();
406
406
}
407
407
408
- private void testNotCachingDataBlocksDuringCompactionInternals (boolean useTags )
409
- throws IOException , InterruptedException {
410
- // TODO: need to change this test if we add a cache size threshold for
411
- // compactions, or if we implement some other kind of intelligent logic for
412
- // deciding what blocks to cache-on-write on compaction.
413
- final String table = "CompactionCacheOnWrite" ;
414
- final String cf = "myCF" ;
415
- final byte [] cfBytes = Bytes .toBytes (cf );
416
- final int maxVersions = 3 ;
417
- ColumnFamilyDescriptor cfd =
418
- ColumnFamilyDescriptorBuilder .newBuilder (cfBytes ).setCompressionType (compress )
419
- .setBloomFilterType (BLOOM_TYPE ).setMaxVersions (maxVersions )
420
- .setDataBlockEncoding (NoOpDataBlockEncoder .INSTANCE .getDataBlockEncoding ()).build ();
421
- HRegion region = TEST_UTIL .createTestRegion (table , cfd , blockCache );
422
- int rowIdx = 0 ;
423
- long ts = EnvironmentEdgeManager .currentTime ();
424
- for (int iFile = 0 ; iFile < 5 ; ++iFile ) {
425
- for (int iRow = 0 ; iRow < 500 ; ++iRow ) {
426
- String rowStr = "" + (rowIdx * rowIdx * rowIdx ) + "row" + iFile + "_" +
427
- iRow ;
428
- Put p = new Put (Bytes .toBytes (rowStr ));
429
- ++rowIdx ;
430
- for (int iCol = 0 ; iCol < 10 ; ++iCol ) {
431
- String qualStr = "col" + iCol ;
432
- String valueStr = "value_" + rowStr + "_" + qualStr ;
433
- for (int iTS = 0 ; iTS < 5 ; ++iTS ) {
434
- if (useTags ) {
435
- Tag t = new ArrayBackedTag ((byte ) 1 , "visibility" );
436
- Tag [] tags = new Tag [1 ];
437
- tags [0 ] = t ;
438
- KeyValue kv = new KeyValue (Bytes .toBytes (rowStr ), cfBytes , Bytes .toBytes (qualStr ),
439
- HConstants .LATEST_TIMESTAMP , Bytes .toBytes (valueStr ), tags );
440
- p .add (kv );
441
- } else {
442
- p .addColumn (cfBytes , Bytes .toBytes (qualStr ), ts ++, Bytes .toBytes (valueStr ));
408
+ private void testCachingDataBlocksDuringCompactionInternals (boolean useTags ,
409
+ boolean cacheBlocksOnCompaction ) throws IOException , InterruptedException {
410
+ // create a localConf
411
+ boolean localValue = conf .getBoolean (CacheConfig .CACHE_COMPACTED_BLOCKS_ON_WRITE_KEY ,
412
+ false );
413
+ try {
414
+ // Set the conf if testing caching compacted blocks on write
415
+ conf .setBoolean (CacheConfig .CACHE_COMPACTED_BLOCKS_ON_WRITE_KEY ,
416
+ cacheBlocksOnCompaction );
417
+
418
+ // TODO: need to change this test if we add a cache size threshold for
419
+ // compactions, or if we implement some other kind of intelligent logic for
420
+ // deciding what blocks to cache-on-write on compaction.
421
+ final String table = "CompactionCacheOnWrite" ;
422
+ final String cf = "myCF" ;
423
+ final byte [] cfBytes = Bytes .toBytes (cf );
424
+ final int maxVersions = 3 ;
425
+ ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder .newBuilder (cfBytes )
426
+ .setCompressionType (compress ).setBloomFilterType (BLOOM_TYPE ).setMaxVersions (maxVersions )
427
+ .setDataBlockEncoding (NoOpDataBlockEncoder .INSTANCE .getDataBlockEncoding ()).build ();
428
+ HRegion region = TEST_UTIL .createTestRegion (table , cfd , blockCache );
429
+ int rowIdx = 0 ;
430
+ long ts = EnvironmentEdgeManager .currentTime ();
431
+ for (int iFile = 0 ; iFile < 5 ; ++iFile ) {
432
+ for (int iRow = 0 ; iRow < 500 ; ++iRow ) {
433
+ String rowStr = "" + (rowIdx * rowIdx * rowIdx ) + "row" + iFile + "_" + iRow ;
434
+ Put p = new Put (Bytes .toBytes (rowStr ));
435
+ ++rowIdx ;
436
+ for (int iCol = 0 ; iCol < 10 ; ++iCol ) {
437
+ String qualStr = "col" + iCol ;
438
+ String valueStr = "value_" + rowStr + "_" + qualStr ;
439
+ for (int iTS = 0 ; iTS < 5 ; ++iTS ) {
440
+ if (useTags ) {
441
+ Tag t = new ArrayBackedTag ((byte ) 1 , "visibility" );
442
+ Tag [] tags = new Tag [1 ];
443
+ tags [0 ] = t ;
444
+ KeyValue kv = new KeyValue (Bytes .toBytes (rowStr ), cfBytes , Bytes .toBytes (qualStr ),
445
+ HConstants .LATEST_TIMESTAMP , Bytes .toBytes (valueStr ), tags );
446
+ p .add (kv );
447
+ } else {
448
+ p .addColumn (cfBytes , Bytes .toBytes (qualStr ), ts ++, Bytes .toBytes (valueStr ));
449
+ }
443
450
}
444
451
}
452
+ p .setDurability (Durability .ASYNC_WAL );
453
+ region .put (p );
454
+ }
455
+ region .flush (true );
456
+ }
457
+
458
+ clearBlockCache (blockCache );
459
+ assertEquals (0 , blockCache .getBlockCount ());
460
+
461
+ region .compact (false );
462
+ LOG .debug ("compactStores() returned" );
463
+
464
+ boolean dataBlockCached = false ;
465
+ for (CachedBlock block : blockCache ) {
466
+ if (BlockType .ENCODED_DATA .equals (block .getBlockType ())
467
+ || BlockType .DATA .equals (block .getBlockType ())) {
468
+ dataBlockCached = true ;
469
+ break ;
445
470
}
446
- p .setDurability (Durability .ASYNC_WAL );
447
- region .put (p );
448
471
}
449
- region .flush (true );
450
- }
451
- clearBlockCache (blockCache );
452
- assertEquals (0 , blockCache .getBlockCount ());
453
- region .compact (false );
454
- LOG .debug ("compactStores() returned" );
455
472
456
- for (CachedBlock block : blockCache ) {
457
- assertNotEquals (BlockType .ENCODED_DATA , block .getBlockType ());
458
- assertNotEquals (BlockType .DATA , block .getBlockType ());
473
+ // Data blocks should be cached in instances where we are caching blocks on write. In the case
474
+ // of testing
475
+ // BucketCache, we cannot verify block type as it is not stored in the cache.
476
+ assertTrue (
477
+ "\n Test description: " + testDescription + "\n cacheBlocksOnCompaction: "
478
+ + cacheBlocksOnCompaction + "\n " ,
479
+ (cacheBlocksOnCompaction && !(blockCache instanceof BucketCache )) == dataBlockCached );
480
+
481
+ region .close ();
482
+ } finally {
483
+ // reset back
484
+ conf .setBoolean (CacheConfig .CACHE_COMPACTED_BLOCKS_ON_WRITE_KEY , localValue );
459
485
}
460
- region .close ();
461
486
}
462
487
463
488
@ Test
@@ -467,8 +492,8 @@ public void testStoreFileCacheOnWrite() throws IOException {
467
492
}
468
493
469
494
@ Test
470
- public void testNotCachingDataBlocksDuringCompaction () throws IOException , InterruptedException {
471
- testNotCachingDataBlocksDuringCompactionInternals ( false );
472
- testNotCachingDataBlocksDuringCompactionInternals ( true );
495
+ public void testCachingDataBlocksDuringCompaction () throws IOException , InterruptedException {
496
+ testCachingDataBlocksDuringCompactionInternals ( false , false );
497
+ testCachingDataBlocksDuringCompactionInternals ( true , true );
473
498
}
474
499
}
0 commit comments