Skip to content

Commit da97f8e

Browse files
committed
Address PR comments.
1 parent bfa4733 commit da97f8e

File tree

2 files changed

+18
-30
lines changed

2 files changed

+18
-30
lines changed

java/src/main/java/org/rocksdb/RocksDB.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.nio.ByteBuffer;
1313
import java.util.*;
1414
import java.util.concurrent.atomic.AtomicReference;
15-
import java.util.stream.IntStream;
1615
import org.rocksdb.util.Environment;
1716

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

307306
final byte[][] cfNames = new byte[columnFamilyDescriptors.size()][];
308307
final long[] cfOptionHandles = new long[columnFamilyDescriptors.size()];
308+
int defaultColumnFamilyIndex = -1;
309309
for (int i = 0; i < columnFamilyDescriptors.size(); i++) {
310310
final ColumnFamilyDescriptor cfDescriptor = columnFamilyDescriptors
311311
.get(i);
312312
cfNames[i] = cfDescriptor.getName();
313313
cfOptionHandles[i] = cfDescriptor.getOptions().nativeHandle_;
314+
if(Arrays.equals(cfDescriptor.getName(),
315+
RocksDB.DEFAULT_COLUMN_FAMILY)) {
316+
defaultColumnFamilyIndex = i;
317+
}
318+
}
319+
if(defaultColumnFamilyIndex < 0) {
320+
new IllegalArgumentException("You must provide the default column family in your columnFamilyDescriptors");
314321
}
315322

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

327334
db.ownedColumnFamilyHandles.addAll(columnFamilyHandles);
328-
329-
// ColumnFamilyHandle.isDefaultColumnFamily() doesn't work here yet, as we are in process of
330-
// opening database
331-
OptionalInt defaultCfIndex = IntStream.of(0, columnFamilyDescriptors.size() - 1)
332-
.filter(x
333-
-> Arrays.equals(columnFamilyDescriptors.get(x).getName(),
334-
RocksDB.DEFAULT_COLUMN_FAMILY))
335-
.findFirst();
336-
if (defaultCfIndex.isPresent()) {
337-
db.storeDefaultColumnFamilyHandle(columnFamilyHandles.get(defaultCfIndex.getAsInt()));
338-
} else {
339-
throw new RocksDBException("No default column family");
340-
}
341-
335+
db.storeDefaultColumnFamilyHandle(columnFamilyHandles.get(defaultColumnFamilyIndex));
342336
return db;
343337
}
344338

java/src/main/java/org/rocksdb/TtlDB.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import java.util.Arrays;
99
import java.util.List;
10-
import java.util.OptionalInt;
11-
import java.util.stream.IntStream;
1210

1311
/**
1412
* Database with TTL support.
@@ -122,13 +120,21 @@ public static TtlDB open(final DBOptions options, final String db_path,
122120
+ " family handle.");
123121
}
124122

123+
int defaultColumnFamilyIndex = -1;
125124
final byte[][] cfNames = new byte[columnFamilyDescriptors.size()][];
126125
final long[] cfOptionHandles = new long[columnFamilyDescriptors.size()];
127126
for (int i = 0; i < columnFamilyDescriptors.size(); i++) {
128127
final ColumnFamilyDescriptor cfDescriptor =
129128
columnFamilyDescriptors.get(i);
130129
cfNames[i] = cfDescriptor.getName();
131130
cfOptionHandles[i] = cfDescriptor.getOptions().nativeHandle_;
131+
if(Arrays.equals(cfDescriptor.getName(),
132+
RocksDB.DEFAULT_COLUMN_FAMILY)) {
133+
defaultColumnFamilyIndex = i;
134+
}
135+
}
136+
if(defaultColumnFamilyIndex < 0) {
137+
new IllegalArgumentException("You must provide the default column family in your columnFamilyDescriptors");
132138
}
133139

134140
final int[] ttlVals = new int[ttlValues.size()];
@@ -144,19 +150,7 @@ public static TtlDB open(final DBOptions options, final String db_path,
144150
}
145151
ttlDB.storeOptionsInstance(options);
146152
ttlDB.ownedColumnFamilyHandles.addAll(columnFamilyHandles);
147-
148-
// ColumnFamilyHandle.isDefaultColumnFamily() doesn't work here yet, as we are in process of
149-
// opening database
150-
OptionalInt defaultCfIndex = IntStream.of(0, columnFamilyDescriptors.size() - 1)
151-
.filter(x
152-
-> Arrays.equals(columnFamilyDescriptors.get(x).getName(),
153-
RocksDB.DEFAULT_COLUMN_FAMILY))
154-
.findFirst();
155-
if (defaultCfIndex.isPresent()) {
156-
ttlDB.storeDefaultColumnFamilyHandle(columnFamilyHandles.get(defaultCfIndex.getAsInt()));
157-
} else {
158-
throw new RocksDBException("No defaultColumnFamily");
159-
}
153+
ttlDB.storeDefaultColumnFamilyHandle(columnFamilyHandles.get(defaultColumnFamilyIndex));
160154

161155
return ttlDB;
162156
}

0 commit comments

Comments
 (0)