Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,4 @@ public void dumpToFileWithPrefix(File externalFile, KEY prefix) throws RocksData
public void loadFromFile(File externalFile) throws RocksDatabaseException {
table.loadFromFile(externalFile);
}

@Override
public void close() throws Exception {
table.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,6 @@ public String getName() {
return family.getName();
}

@Override
public void close() {
// Nothing do for a Column Family.
}

@Override
public long getEstimatedKeyCount() throws RocksDatabaseException {
return db.estimateNumKeys(family);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* different kind of tables.
*/
@InterfaceStability.Evolving
public interface Table<KEY, VALUE> extends AutoCloseable {
public interface Table<KEY, VALUE> {

/**
* Puts a key-value pair into the store.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,6 @@ public long getEstimatedKeyCount() throws RocksDatabaseException {
return rawTable.getEstimatedKeyCount();
}

@Override
public void close() {
rawTable.close();

}

@Override
public void addCacheEntry(CacheKey<KEY> cacheKey,
CacheValue<VALUE> cacheValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,12 @@ public ManagedDBOptions getNewDBOptions() {

public void insertRandomData(RDBStore dbStore, int familyIndex)
throws IOException {
try (Table<byte[], byte[]> firstTable = dbStore.getTable(families.
get(familyIndex))) {
assertNotNull(firstTable, "Table cannot be null");
for (int x = 0; x < 100; x++) {
byte[] key =
RandomStringUtils.secure().next(10).getBytes(StandardCharsets.UTF_8);
byte[] value =
RandomStringUtils.secure().next(10).getBytes(StandardCharsets.UTF_8);
firstTable.put(key, value);
}
} catch (Exception e) {
throw new IOException(e);
Table<byte[], byte[]> firstTable = dbStore.getTable(families.get(familyIndex));
assertNotNull(firstTable, "Table cannot be null");
for (int x = 0; x < 100; x++) {
byte[] key = RandomStringUtils.secure().next(10).getBytes(StandardCharsets.UTF_8);
byte[] value = RandomStringUtils.secure().next(10).getBytes(StandardCharsets.UTF_8);
firstTable.put(key, value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ public InMemoryTestTable(Map<KEY, VALUE> map) {
this.map.putAll(map);
}

@Override
public void close() {
}

@Override
public void put(KEY key, VALUE value) {
map.put(key, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,12 @@ public void builderWithDoubleTableName(@TempDir Path tempDir)
.build();
// Building should succeed without error.

try (Table<byte[], byte[]> firstTable = dbStore.getTable("FIRST")) {
byte[] key =
RandomStringUtils.secure().next(9).getBytes(StandardCharsets.UTF_8);
byte[] value =
RandomStringUtils.secure().next(9).getBytes(StandardCharsets.UTF_8);
firstTable.put(key, value);
byte[] temp = firstTable.get(key);
assertArrayEquals(value, temp);
}
final Table<byte[], byte[]> firstTable = dbStore.getTable("FIRST");
byte[] key = RandomStringUtils.secure().next(9).getBytes(StandardCharsets.UTF_8);
byte[] value = RandomStringUtils.secure().next(9).getBytes(StandardCharsets.UTF_8);
firstTable.put(key, value);
byte[] temp = firstTable.get(key);
assertArrayEquals(value, temp);

dbStore.close();
}
Expand All @@ -118,19 +115,16 @@ public void builderWithDataWrites(@TempDir Path tempDir) throws Exception {
.addTable("First")
.addTable("Second")
.build()) {
try (Table<byte[], byte[]> firstTable = dbStore.getTable("First")) {
byte[] key =
RandomStringUtils.secure().next(9).getBytes(StandardCharsets.UTF_8);
byte[] value =
RandomStringUtils.secure().next(9).getBytes(StandardCharsets.UTF_8);
firstTable.put(key, value);
byte[] temp = firstTable.get(key);
assertArrayEquals(value, temp);
}
final Table<byte[], byte[]> firstTable = dbStore.getTable("First");
byte[] key = RandomStringUtils.secure().next(9).getBytes(StandardCharsets.UTF_8);
byte[] value = RandomStringUtils.secure().next(9).getBytes(StandardCharsets.UTF_8);
firstTable.put(key, value);
byte[] temp = firstTable.get(key);
assertArrayEquals(value, temp);

try (Table secondTable = dbStore.getTable("Second")) {
assertTrue(secondTable.isEmpty());
}

final Table<byte[], byte[]> secondTable = dbStore.getTable("Second");
assertTrue(secondTable.isEmpty());
}
}

Expand All @@ -145,19 +139,15 @@ public void builderWithDiskProfileWrites(@TempDir Path tempDir)
.addTable("Second")
.setProfile(DBProfile.DISK)
.build()) {
try (Table<byte[], byte[]> firstTable = dbStore.getTable("First")) {
byte[] key =
RandomStringUtils.secure().next(9).getBytes(StandardCharsets.UTF_8);
byte[] value =
RandomStringUtils.secure().next(9).getBytes(StandardCharsets.UTF_8);
firstTable.put(key, value);
byte[] temp = firstTable.get(key);
assertArrayEquals(value, temp);
}
Table<byte[], byte[]> firstTable = dbStore.getTable("First");
byte[] key = RandomStringUtils.secure().next(9).getBytes(StandardCharsets.UTF_8);
byte[] value = RandomStringUtils.secure().next(9).getBytes(StandardCharsets.UTF_8);
firstTable.put(key, value);
byte[] temp = firstTable.get(key);
assertArrayEquals(value, temp);

try (Table secondTable = dbStore.getTable("Second")) {
assertTrue(secondTable.isEmpty());
}
Table<byte[], byte[]> secondTable = dbStore.getTable("Second");
assertTrue(secondTable.isEmpty());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,14 @@ public void tearDown() throws Exception {

public void insertRandomData(RDBStore dbStore, int familyIndex)
throws IOException {
try (Table<byte[], byte[]> firstTable = dbStore.getTable(families.
get(familyIndex))) {
assertNotNull(firstTable, "Table cannot be null");
for (int x = 0; x < 100; x++) {
byte[] key =
Table<byte[], byte[]> firstTable = dbStore.getTable(families.get(familyIndex));
assertNotNull(firstTable, "Table cannot be null");
for (int x = 0; x < 100; x++) {
byte[] key =
RandomStringUtils.secure().next(10).getBytes(StandardCharsets.UTF_8);
byte[] value =
byte[] value =
RandomStringUtils.secure().next(10).getBytes(StandardCharsets.UTF_8);
firstTable.put(key, value);
}
} catch (Exception e) {
throw new IOException(e);
firstTable.put(key, value);
}
}

Expand Down Expand Up @@ -191,20 +187,17 @@ public void moveKey() throws Exception {
byte[] value =
RandomStringUtils.secure().next(10).getBytes(StandardCharsets.UTF_8);

try (Table firstTable = rdbStore.getTable(families.get(1))) {
firstTable.put(key, value);
try (Table<byte[], byte[]> secondTable = rdbStore
.getTable(families.get(2))) {
rdbStore.move(key, firstTable, secondTable);
byte[] newvalue = secondTable.get(key);
// Make sure we have value in the second table
assertNotNull(newvalue);
//and it is same as what we wrote to the FirstTable
assertArrayEquals(value, newvalue);
}
// After move this key must not exist in the first table.
assertNull(firstTable.get(key));
}
final Table<byte[], byte[]> firstTable = rdbStore.getTable(families.get(1));
firstTable.put(key, value);
final Table<byte[], byte[]> secondTable = rdbStore.getTable(families.get(2));
rdbStore.move(key, firstTable, secondTable);
byte[] newvalue = secondTable.get(key);
// Make sure we have value in the second table
assertNotNull(newvalue);
//and it is same as what we wrote to the FirstTable
assertArrayEquals(value, newvalue);
// After move this key must not exist in the first table.
assertNull(firstTable.get(key));
}

@Test
Expand All @@ -216,20 +209,16 @@ public void moveWithValue() throws Exception {

byte[] nextValue =
RandomStringUtils.secure().next(10).getBytes(StandardCharsets.UTF_8);
try (Table firstTable = rdbStore.getTable(families.get(1))) {
firstTable.put(key, value);
try (Table<byte[], byte[]> secondTable = rdbStore
.getTable(families.get(2))) {
rdbStore.move(key, nextValue, firstTable, secondTable);
byte[] newvalue = secondTable.get(key);
// Make sure we have value in the second table
assertNotNull(newvalue);
//and it is not same as what we wrote to the FirstTable, and equals
// the new value.
assertArrayEquals(nextValue, newvalue);
}
}

Table<byte[], byte[]> firstTable = rdbStore.getTable(families.get(1));
firstTable.put(key, value);
Table<byte[], byte[]> secondTable = rdbStore.getTable(families.get(2));
rdbStore.move(key, nextValue, firstTable, secondTable);
byte[] newvalue = secondTable.get(key);
// Make sure we have value in the second table
assertNotNull(newvalue);
//and it is not same as what we wrote to the FirstTable, and equals
// the new value.
assertArrayEquals(nextValue, newvalue);
}

@Test
Expand All @@ -250,9 +239,8 @@ public void getEstimatedKeyCount() throws Exception {
@Test
public void getTable() throws Exception {
for (String tableName : families) {
try (Table table = rdbStore.getTable(tableName)) {
assertNotNull(table, tableName + "is null");
}
Table<byte[], byte[]> table = rdbStore.getTable(tableName);
assertNotNull(table, tableName + "is null");
}
assertThrows(IOException.class,
() -> rdbStore.getTable("ATableWithNoName"));
Expand Down Expand Up @@ -315,48 +303,42 @@ public void testRocksDBCheckpointCleanup() throws Exception {

@Test
public void testGetDBUpdatesSince() throws Exception {

try (Table firstTable = rdbStore.getTable(families.get(1))) {
firstTable.put(
org.apache.commons.codec.binary.StringUtils.getBytesUtf16("Key1"),
org.apache.commons.codec.binary.StringUtils
.getBytesUtf16("Value1"));
firstTable.put(
org.apache.commons.codec.binary.StringUtils.getBytesUtf16("Key2"),
org.apache.commons.codec.binary.StringUtils
.getBytesUtf16("Value2"));
}
final Table<byte[], byte[]> firstTable = rdbStore.getTable(families.get(1));
firstTable.put(
getBytesUtf16("Key1"),
getBytesUtf16("Value1"));
firstTable.put(
getBytesUtf16("Key2"),
getBytesUtf16("Value2"));
assertEquals(2, rdbStore.getDb().getLatestSequenceNumber());

DBUpdatesWrapper dbUpdatesSince = rdbStore.getUpdatesSince(0);
assertEquals(2, dbUpdatesSince.getData().size());
}

static byte[] getBytesUtf16(String s) {
return s.getBytes(StandardCharsets.UTF_16);
}

@Test
public void testGetDBUpdatesSinceWithLimitCount() throws Exception {

try (Table firstTable = rdbStore.getTable(families.get(1))) {
firstTable.put(
org.apache.commons.codec.binary.StringUtils.getBytesUtf16("Key1"),
org.apache.commons.codec.binary.StringUtils
.getBytesUtf16("Value1"));
firstTable.put(
org.apache.commons.codec.binary.StringUtils.getBytesUtf16("Key2"),
org.apache.commons.codec.binary.StringUtils
.getBytesUtf16("Value2"));
firstTable.put(
org.apache.commons.codec.binary.StringUtils.getBytesUtf16("Key3"),
org.apache.commons.codec.binary.StringUtils
.getBytesUtf16("Value3"));
firstTable.put(
org.apache.commons.codec.binary.StringUtils.getBytesUtf16("Key4"),
org.apache.commons.codec.binary.StringUtils
.getBytesUtf16("Value4"));
firstTable.put(
org.apache.commons.codec.binary.StringUtils.getBytesUtf16("Key5"),
org.apache.commons.codec.binary.StringUtils
.getBytesUtf16("Value5"));
}
final Table<byte[], byte[]> firstTable = rdbStore.getTable(families.get(1));
firstTable.put(
getBytesUtf16("Key1"),
getBytesUtf16("Value1"));
firstTable.put(
getBytesUtf16("Key2"),
getBytesUtf16("Value2"));
firstTable.put(
getBytesUtf16("Key3"),
getBytesUtf16("Value3"));
firstTable.put(
getBytesUtf16("Key4"),
getBytesUtf16("Value4"));
firstTable.put(
getBytesUtf16("Key5"),
getBytesUtf16("Value5"));
assertEquals(5, rdbStore.getDb().getLatestSequenceNumber());

DBUpdatesWrapper dbUpdatesSince = rdbStore.getUpdatesSince(0, 5);
Expand All @@ -370,12 +352,10 @@ public void testDowngrade() throws Exception {
// Write data to current DB which has 6 column families at the time of
// writing this test.
for (String family : families) {
try (Table table = rdbStore.getTable(family)) {
byte[] key = family.getBytes(StandardCharsets.UTF_8);
byte[] value =
RandomStringUtils.secure().next(10).getBytes(StandardCharsets.UTF_8);
table.put(key, value);
}
final Table<byte[], byte[]> table = rdbStore.getTable(family);
byte[] key = family.getBytes(StandardCharsets.UTF_8);
byte[] value = RandomStringUtils.secure().next(10).getBytes(StandardCharsets.UTF_8);
table.put(key, value);
}
// Close current DB.
rdbStore.close();
Expand All @@ -394,21 +374,19 @@ public void testDowngrade() throws Exception {
rdbStore = newRDBStore(rdbStore.getDbLocation(), options, configSet,
MAX_DB_UPDATES_SIZE_THRESHOLD);
for (String family : familiesMinusOne) {
try (Table table = rdbStore.getTable(family)) {
assertNotNull(table, family + "is null");
Object val = table.get(family.getBytes(StandardCharsets.UTF_8));
assertNotNull(val);
}
final Table<byte[], byte[]> table = rdbStore.getTable(family);
assertNotNull(table, family + "is null");
Object val = table.get(family.getBytes(StandardCharsets.UTF_8));
assertNotNull(val);
}

// Technically the extra column family should also be open, even though
// we do not use it.
String extraFamily = families.get(families.size() - 1);
try (Table table = rdbStore.getTable(extraFamily)) {
assertNotNull(table, extraFamily + "is null");
Object val = table.get(extraFamily.getBytes(StandardCharsets.UTF_8));
assertNotNull(val);
}
final Table<byte[], byte[]> table = rdbStore.getTable(extraFamily);
assertNotNull(table, extraFamily + "is null");
Object val = table.get(extraFamily.getBytes(StandardCharsets.UTF_8));
assertNotNull(val);
}

@Test
Expand Down
Loading