Skip to content

Commit

Permalink
Address PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhubner committed Dec 21, 2023
1 parent bfa4733 commit 49ed9a0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 30 deletions.
24 changes: 9 additions & 15 deletions java/src/main/java/org/rocksdb/RocksDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.nio.ByteBuffer;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.IntStream;
import org.rocksdb.util.Environment;

/**
Expand Down Expand Up @@ -306,11 +305,19 @@ public static RocksDB open(final DBOptions options, final String path,

final byte[][] cfNames = new byte[columnFamilyDescriptors.size()][];
final long[] cfOptionHandles = new long[columnFamilyDescriptors.size()];
int defaultColumnFamilyIndex = -1;
for (int i = 0; i < columnFamilyDescriptors.size(); i++) {
final ColumnFamilyDescriptor cfDescriptor = columnFamilyDescriptors
.get(i);
cfNames[i] = cfDescriptor.getName();
cfOptionHandles[i] = cfDescriptor.getOptions().nativeHandle_;
if (Arrays.equals(cfDescriptor.getName(), RocksDB.DEFAULT_COLUMN_FAMILY)) {
defaultColumnFamilyIndex = i;
}
}
if (defaultColumnFamilyIndex < 0) {
new IllegalArgumentException(
"You must provide the default column family in your columnFamilyDescriptors");
}

final long[] handles = open(options.nativeHandle_, path, cfNames,
Expand All @@ -325,20 +332,7 @@ public static RocksDB open(final DBOptions options, final String path,
}

db.ownedColumnFamilyHandles.addAll(columnFamilyHandles);

// ColumnFamilyHandle.isDefaultColumnFamily() doesn't work here yet, as we are in process of
// opening database
OptionalInt defaultCfIndex = IntStream.of(0, columnFamilyDescriptors.size() - 1)
.filter(x
-> Arrays.equals(columnFamilyDescriptors.get(x).getName(),
RocksDB.DEFAULT_COLUMN_FAMILY))
.findFirst();
if (defaultCfIndex.isPresent()) {
db.storeDefaultColumnFamilyHandle(columnFamilyHandles.get(defaultCfIndex.getAsInt()));
} else {
throw new RocksDBException("No default column family");
}

db.storeDefaultColumnFamilyHandle(columnFamilyHandles.get(defaultColumnFamilyIndex));
return db;
}

Expand Down
24 changes: 9 additions & 15 deletions java/src/main/java/org/rocksdb/TtlDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import java.util.Arrays;
import java.util.List;
import java.util.OptionalInt;
import java.util.stream.IntStream;

/**
* Database with TTL support.
Expand Down Expand Up @@ -122,13 +120,21 @@ public static TtlDB open(final DBOptions options, final String db_path,
+ " family handle.");
}

int defaultColumnFamilyIndex = -1;
final byte[][] cfNames = new byte[columnFamilyDescriptors.size()][];
final long[] cfOptionHandles = new long[columnFamilyDescriptors.size()];
for (int i = 0; i < columnFamilyDescriptors.size(); i++) {
final ColumnFamilyDescriptor cfDescriptor =
columnFamilyDescriptors.get(i);
cfNames[i] = cfDescriptor.getName();
cfOptionHandles[i] = cfDescriptor.getOptions().nativeHandle_;
if (Arrays.equals(cfDescriptor.getName(), RocksDB.DEFAULT_COLUMN_FAMILY)) {
defaultColumnFamilyIndex = i;
}
}
if (defaultColumnFamilyIndex < 0) {
new IllegalArgumentException(
"You must provide the default column family in your columnFamilyDescriptors");
}

final int[] ttlVals = new int[ttlValues.size()];
Expand All @@ -144,19 +150,7 @@ public static TtlDB open(final DBOptions options, final String db_path,
}
ttlDB.storeOptionsInstance(options);
ttlDB.ownedColumnFamilyHandles.addAll(columnFamilyHandles);

// ColumnFamilyHandle.isDefaultColumnFamily() doesn't work here yet, as we are in process of
// opening database
OptionalInt defaultCfIndex = IntStream.of(0, columnFamilyDescriptors.size() - 1)
.filter(x
-> Arrays.equals(columnFamilyDescriptors.get(x).getName(),
RocksDB.DEFAULT_COLUMN_FAMILY))
.findFirst();
if (defaultCfIndex.isPresent()) {
ttlDB.storeDefaultColumnFamilyHandle(columnFamilyHandles.get(defaultCfIndex.getAsInt()));
} else {
throw new RocksDBException("No defaultColumnFamily");
}
ttlDB.storeDefaultColumnFamilyHandle(columnFamilyHandles.get(defaultColumnFamilyIndex));

return ttlDB;
}
Expand Down

0 comments on commit 49ed9a0

Please sign in to comment.