1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
8 import static java
.nio
.charset
.StandardCharsets
.UTF_8
;
9 import static org
.assertj
.core
.api
.Assertions
.assertThat
;
11 import java
.util
.List
;
12 import org
.junit
.ClassRule
;
13 import org
.junit
.Rule
;
14 import org
.junit
.Test
;
15 import org
.junit
.rules
.TemporaryFolder
;
17 public class SstPartitionerTest
{
19 public static final RocksNativeLibraryResource ROCKS_NATIVE_LIBRARY_RESOURCE
=
20 new RocksNativeLibraryResource();
22 @Rule public TemporaryFolder dbFolder
= new TemporaryFolder();
25 public void sstFixedPrefix() throws RocksDBException
{
26 try (SstPartitionerFixedPrefixFactory factory
= new SstPartitionerFixedPrefixFactory(4);
28 new Options().setCreateIfMissing(true).setSstPartitionerFactory(factory
);
29 final RocksDB db
= RocksDB
.open(opt
, dbFolder
.getRoot().getAbsolutePath())) {
30 // writing (long)100 under key
31 db
.put("aaaa1".getBytes(), "A".getBytes());
32 db
.put("bbbb1".getBytes(), "B".getBytes());
33 db
.flush(new FlushOptions());
35 db
.put("aaaa0".getBytes(), "A2".getBytes());
36 db
.put("aaaa2".getBytes(), "A2".getBytes());
37 db
.flush(new FlushOptions());
41 List
<LiveFileMetaData
> metadata
= db
.getLiveFilesMetaData();
42 assertThat(metadata
.size()).isEqualTo(2);
47 public void sstFixedPrefixFamily() throws RocksDBException
{
48 final byte[] cfName
= "new_cf".getBytes(UTF_8
);
49 final ColumnFamilyDescriptor cfDescriptor
= new ColumnFamilyDescriptor(cfName
,
50 new ColumnFamilyOptions().setSstPartitionerFactory(
51 new SstPartitionerFixedPrefixFactory(4)));
53 try (final Options opt
= new Options().setCreateIfMissing(true);
54 final RocksDB db
= RocksDB
.open(opt
, dbFolder
.getRoot().getAbsolutePath())) {
55 final ColumnFamilyHandle columnFamilyHandle
= db
.createColumnFamily(cfDescriptor
);
57 // writing (long)100 under key
58 db
.put(columnFamilyHandle
, "aaaa1".getBytes(), "A".getBytes());
59 db
.put(columnFamilyHandle
, "bbbb1".getBytes(), "B".getBytes());
60 db
.flush(new FlushOptions(), columnFamilyHandle
);
62 db
.put(columnFamilyHandle
, "aaaa0".getBytes(), "A2".getBytes());
63 db
.put(columnFamilyHandle
, "aaaa2".getBytes(), "A2".getBytes());
64 db
.flush(new FlushOptions(), columnFamilyHandle
);
66 db
.compactRange(columnFamilyHandle
);
68 List
<LiveFileMetaData
> metadata
= db
.getLiveFilesMetaData();
69 assertThat(metadata
.size()).isEqualTo(2);