@@ -75,21 +75,49 @@ public void onFlushBegin(final RocksDB rocksDb, final FlushJobInfo flushJobInfo)
75
75
76
76
void deleteTableFile (final AbstractEventListener el , final AtomicBoolean wasCbCalled )
77
77
throws RocksDBException {
78
- try (final Options opt =
79
- new Options ().setCreateIfMissing (true ).setListeners (Collections .singletonList (el ));
78
+ final int KEY_SIZE = 20 ;
79
+ final int VALUE_SIZE = 1000 ;
80
+ final int FILE_SIZE = 64000 ;
81
+ final int NUM_FILES = 10 ;
82
+
83
+ final int KEY_INTERVAL = 10000 ;
84
+ /*
85
+ * Intention of these options is to end up reliably with 10 files
86
+ * we will be deleting using deleteFilesInRange.
87
+ * It is writing roughly number of keys that will fit in 10 files (target size)
88
+ * It is writing interleaved so that files from memory on L0 will overlap
89
+ * Then compaction cleans everything, and we should end up with 10 files
90
+ */
91
+ try (final Options opt = new Options ()
92
+ .setCreateIfMissing (true )
93
+ .setListeners (Collections .singletonList (el ))
94
+ .setCompressionType (CompressionType .NO_COMPRESSION )
95
+ .setTargetFileSizeBase (FILE_SIZE )
96
+ .setWriteBufferSize (FILE_SIZE / 2 )
97
+ .setDisableAutoCompactions (true )
98
+ .setLevelCompactionDynamicLevelBytes (false );
80
99
final RocksDB db = RocksDB .open (opt , dbFolder .getRoot ().getAbsolutePath ())) {
81
- assertThat (db ).isNotNull ();
82
- final byte [] value = new byte [24 ];
83
- rand .nextBytes (value );
84
- db .put ("testKey" .getBytes (), value );
85
- db .flush (new FlushOptions ());
86
- final RocksDB .LiveFiles liveFiles = db .getLiveFiles ();
87
- assertThat (liveFiles ).isNotNull ();
88
- assertThat (liveFiles .files ).isNotNull ();
89
- assertThat (liveFiles .files .isEmpty ()).isFalse ();
100
+ final int records = FILE_SIZE / (KEY_SIZE + VALUE_SIZE );
101
+
102
+ // fill database with key/value pairs
103
+ final byte [] value = new byte [VALUE_SIZE ];
104
+ int key_init = 0 ;
105
+ for (int o = 0 ; o < NUM_FILES ; ++o ) {
106
+ int int_key = key_init ++;
107
+ for (int i = 0 ; i < records ; ++i ) {
108
+ int_key += KEY_INTERVAL ;
109
+ rand .nextBytes (value );
110
+
111
+ db .put (String .format ("%020d" , int_key ).getBytes (), value );
112
+ }
113
+ }
114
+ try (final FlushOptions flushOptions = new FlushOptions ().setWaitForFlush (true )) {
115
+ db .flush (flushOptions );
116
+ }
117
+ db .compactRange ();
90
118
db .deleteFilesInRanges (null , Arrays .asList (null , null ), false /* includeEnd */ );
91
- assertThat (wasCbCalled .get ()).isTrue ();
92
119
}
120
+ assertThat (wasCbCalled .get ()).isTrue ();
93
121
}
94
122
95
123
@ Test
0 commit comments