[RocksJava] ColumnFamilyDescriptor alignment with listColumnFamilies
Summary: Previous to this commit ColumnFamilyDescriptor took a String as name for the ColumnFamily name. String is however encoding dependent which is bad because listColumnFamilies returns byte arrays without any encoding information. All public API call were deprecated and flagged to be removed in 3.10.0 Test Plan: make rocksdbjava make test mvn -f rocksjni.pom package Reviewers: yhchiang, adamretter, ankgup87 Subscribers: dhruba Differential Revision: https://reviews.facebook.net/D30525
This commit is contained in:
parent
15d2abbec3
commit
0aab1005f8
@ -33,7 +33,8 @@ public class RocksDBColumnFamilySample {
|
|||||||
|
|
||||||
// create column family
|
// create column family
|
||||||
columnFamilyHandle = db.createColumnFamily(
|
columnFamilyHandle = db.createColumnFamily(
|
||||||
new ColumnFamilyDescriptor("new_cf", new ColumnFamilyOptions()));
|
new ColumnFamilyDescriptor("new_cf".getBytes(),
|
||||||
|
new ColumnFamilyOptions()));
|
||||||
assert(columnFamilyHandle != null);
|
assert(columnFamilyHandle != null);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
@ -56,7 +57,7 @@ public class RocksDBColumnFamilySample {
|
|||||||
RocksDB.DEFAULT_COLUMN_FAMILY, new ColumnFamilyOptions()));
|
RocksDB.DEFAULT_COLUMN_FAMILY, new ColumnFamilyOptions()));
|
||||||
// open the new one, too
|
// open the new one, too
|
||||||
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
|
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
|
||||||
"new_cf", new ColumnFamilyOptions()));
|
"new_cf".getBytes(), new ColumnFamilyOptions()));
|
||||||
List<ColumnFamilyHandle> columnFamilyHandles = new ArrayList<>();
|
List<ColumnFamilyHandle> columnFamilyHandles = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
db = RocksDB.open(new DBOptions(), db_path,
|
db = RocksDB.open(new DBOptions(), db_path,
|
||||||
|
@ -16,8 +16,21 @@ public class ColumnFamilyDescriptor {
|
|||||||
* options,</p>
|
* options,</p>
|
||||||
*
|
*
|
||||||
* @param columnFamilyName name of column family.
|
* @param columnFamilyName name of column family.
|
||||||
|
* @deprecated will be removed in RocksDB 3.10.0. Use {}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public ColumnFamilyDescriptor(final String columnFamilyName){
|
public ColumnFamilyDescriptor(final String columnFamilyName){
|
||||||
|
this(columnFamilyName.getBytes(), new ColumnFamilyOptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Creates a new Column Family using a name and default
|
||||||
|
* options,</p>
|
||||||
|
*
|
||||||
|
* @param columnFamilyName name of column family.
|
||||||
|
* @since 3.10.0
|
||||||
|
*/
|
||||||
|
public ColumnFamilyDescriptor(final byte[] columnFamilyName) {
|
||||||
this(columnFamilyName, new ColumnFamilyOptions());
|
this(columnFamilyName, new ColumnFamilyOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,9 +41,25 @@ public class ColumnFamilyDescriptor {
|
|||||||
* @param columnFamilyName name of column family.
|
* @param columnFamilyName name of column family.
|
||||||
* @param columnFamilyOptions options to be used with
|
* @param columnFamilyOptions options to be used with
|
||||||
* column family.
|
* column family.
|
||||||
|
* @deprecated will be removed in RocksDB 3.10.0. Use {}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public ColumnFamilyDescriptor(final String columnFamilyName,
|
public ColumnFamilyDescriptor(final String columnFamilyName,
|
||||||
final ColumnFamilyOptions columnFamilyOptions) {
|
final ColumnFamilyOptions columnFamilyOptions) {
|
||||||
|
this(columnFamilyName.getBytes(), columnFamilyOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Creates a new Column Family using a name and custom
|
||||||
|
* options.</p>
|
||||||
|
*
|
||||||
|
* @param columnFamilyName name of column family.
|
||||||
|
* @param columnFamilyOptions options to be used with
|
||||||
|
* column family.
|
||||||
|
* @since 3.10.0
|
||||||
|
*/
|
||||||
|
public ColumnFamilyDescriptor(final byte[] columnFamilyName,
|
||||||
|
final ColumnFamilyOptions columnFamilyOptions) {
|
||||||
columnFamilyName_ = columnFamilyName;
|
columnFamilyName_ = columnFamilyName;
|
||||||
columnFamilyOptions_ = columnFamilyOptions;
|
columnFamilyOptions_ = columnFamilyOptions;
|
||||||
}
|
}
|
||||||
@ -39,8 +68,9 @@ public class ColumnFamilyDescriptor {
|
|||||||
* Retrieve name of column family.
|
* Retrieve name of column family.
|
||||||
*
|
*
|
||||||
* @return column family name.
|
* @return column family name.
|
||||||
|
* @since 3.10.0
|
||||||
*/
|
*/
|
||||||
public String columnFamilyName() {
|
public byte[] columnFamilyName() {
|
||||||
return columnFamilyName_;
|
return columnFamilyName_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +83,6 @@ public class ColumnFamilyDescriptor {
|
|||||||
return columnFamilyOptions_;
|
return columnFamilyOptions_;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String columnFamilyName_;
|
private final byte[] columnFamilyName_;
|
||||||
private final ColumnFamilyOptions columnFamilyOptions_;
|
private final ColumnFamilyOptions columnFamilyOptions_;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import org.rocksdb.util.Environment;
|
|||||||
* indicates sth wrong at the RocksDB library side and the call failed.
|
* indicates sth wrong at the RocksDB library side and the call failed.
|
||||||
*/
|
*/
|
||||||
public class RocksDB extends RocksObject {
|
public class RocksDB extends RocksObject {
|
||||||
public static final String DEFAULT_COLUMN_FAMILY = "default";
|
public static final byte[] DEFAULT_COLUMN_FAMILY = "default".getBytes();
|
||||||
public static final int NOT_FOUND = -1;
|
public static final int NOT_FOUND = -1;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@ -116,7 +116,7 @@ public abstract class AbstractComparatorTest {
|
|||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
cfDescriptors.add(new ColumnFamilyDescriptor(
|
cfDescriptors.add(new ColumnFamilyDescriptor(
|
||||||
RocksDB.DEFAULT_COLUMN_FAMILY));
|
RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||||
cfDescriptors.add(new ColumnFamilyDescriptor("new_cf",
|
cfDescriptors.add(new ColumnFamilyDescriptor("new_cf".getBytes(),
|
||||||
new ColumnFamilyOptions().setComparator(
|
new ColumnFamilyOptions().setComparator(
|
||||||
getAscendingIntKeyComparator())));
|
getAscendingIntKeyComparator())));
|
||||||
List<ColumnFamilyHandle> cfHandles = new ArrayList<>();
|
List<ColumnFamilyHandle> cfHandles = new ArrayList<>();
|
||||||
|
@ -68,7 +68,7 @@ public class ColumnFamilyTest {
|
|||||||
dbOptions.setCreateIfMissing(true);
|
dbOptions.setCreateIfMissing(true);
|
||||||
|
|
||||||
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
|
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
|
||||||
db.createColumnFamily(new ColumnFamilyDescriptor("new_cf",
|
db.createColumnFamily(new ColumnFamilyDescriptor("new_cf".getBytes(),
|
||||||
new ColumnFamilyOptions()));
|
new ColumnFamilyOptions()));
|
||||||
db.close();
|
db.close();
|
||||||
List<byte[]> columnFamilyNames;
|
List<byte[]> columnFamilyNames;
|
||||||
@ -102,7 +102,7 @@ public class ColumnFamilyTest {
|
|||||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||||
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
|
cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes()));
|
||||||
|
|
||||||
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
||||||
cfNames, columnFamilyHandleList);
|
cfNames, columnFamilyHandleList);
|
||||||
@ -191,12 +191,12 @@ public class ColumnFamilyTest {
|
|||||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||||
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
|
cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes()));
|
||||||
|
|
||||||
db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath(),
|
db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath(),
|
||||||
cfNames, columnFamilyHandleList);
|
cfNames, columnFamilyHandleList);
|
||||||
tmpColumnFamilyHandle = db.createColumnFamily(
|
tmpColumnFamilyHandle = db.createColumnFamily(
|
||||||
new ColumnFamilyDescriptor("tmpCF", new ColumnFamilyOptions()));
|
new ColumnFamilyDescriptor("tmpCF".getBytes(), new ColumnFamilyOptions()));
|
||||||
db.put(tmpColumnFamilyHandle, "key".getBytes(), "value".getBytes());
|
db.put(tmpColumnFamilyHandle, "key".getBytes(), "value".getBytes());
|
||||||
db.dropColumnFamily(tmpColumnFamilyHandle);
|
db.dropColumnFamily(tmpColumnFamilyHandle);
|
||||||
tmpColumnFamilyHandle.dispose();
|
tmpColumnFamilyHandle.dispose();
|
||||||
@ -226,7 +226,7 @@ public class ColumnFamilyTest {
|
|||||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||||
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
|
cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes()));
|
||||||
|
|
||||||
db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath(),
|
db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath(),
|
||||||
cfNames, columnFamilyHandleList);
|
cfNames, columnFamilyHandleList);
|
||||||
@ -273,7 +273,7 @@ public class ColumnFamilyTest {
|
|||||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||||
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
|
cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes()));
|
||||||
|
|
||||||
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
||||||
cfNames, columnFamilyHandleList);
|
cfNames, columnFamilyHandleList);
|
||||||
@ -322,7 +322,7 @@ public class ColumnFamilyTest {
|
|||||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
cfDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
cfDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||||
cfDescriptors.add(new ColumnFamilyDescriptor("new_cf"));
|
cfDescriptors.add(new ColumnFamilyDescriptor("new_cf".getBytes()));
|
||||||
|
|
||||||
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
||||||
cfDescriptors, columnFamilyHandleList);
|
cfDescriptors, columnFamilyHandleList);
|
||||||
@ -367,7 +367,7 @@ public class ColumnFamilyTest {
|
|||||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||||
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
|
cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes()));
|
||||||
|
|
||||||
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
||||||
cfNames, columnFamilyHandleList);
|
cfNames, columnFamilyHandleList);
|
||||||
@ -409,7 +409,7 @@ public class ColumnFamilyTest {
|
|||||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||||
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
|
cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes()));
|
||||||
|
|
||||||
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
||||||
cfNames, columnFamilyHandleList);
|
cfNames, columnFamilyHandleList);
|
||||||
@ -459,7 +459,7 @@ public class ColumnFamilyTest {
|
|||||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||||
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
|
cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes()));
|
||||||
|
|
||||||
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
||||||
cfNames, columnFamilyHandleList);
|
cfNames, columnFamilyHandleList);
|
||||||
@ -487,7 +487,7 @@ public class ColumnFamilyTest {
|
|||||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||||
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
|
cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes()));
|
||||||
|
|
||||||
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
||||||
cfNames, columnFamilyHandleList);
|
cfNames, columnFamilyHandleList);
|
||||||
@ -515,7 +515,7 @@ public class ColumnFamilyTest {
|
|||||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||||
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
|
cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes()));
|
||||||
|
|
||||||
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
||||||
cfNames, columnFamilyHandleList);
|
cfNames, columnFamilyHandleList);
|
||||||
@ -543,7 +543,7 @@ public class ColumnFamilyTest {
|
|||||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||||
cfNames.add(new ColumnFamilyDescriptor("new_cf"));
|
cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes()));
|
||||||
|
|
||||||
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath(),
|
||||||
cfNames, columnFamilyHandleList);
|
cfNames, columnFamilyHandleList);
|
||||||
|
@ -37,8 +37,8 @@ public class KeyMayExistTest {
|
|||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
cfDescriptors.add(new ColumnFamilyDescriptor("default"));
|
cfDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||||
cfDescriptors.add(new ColumnFamilyDescriptor("new_cf"));
|
cfDescriptors.add(new ColumnFamilyDescriptor("new_cf".getBytes()));
|
||||||
db = RocksDB.open(options,
|
db = RocksDB.open(options,
|
||||||
dbFolder.getRoot().getAbsolutePath(),
|
dbFolder.getRoot().getAbsolutePath(),
|
||||||
cfDescriptors, columnFamilyHandleList);
|
cfDescriptors, columnFamilyHandleList);
|
||||||
|
@ -8,7 +8,6 @@ package org.rocksdb.test;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.ClassRule;
|
import org.junit.ClassRule;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -73,10 +72,10 @@ public class MergeTest {
|
|||||||
|
|
||||||
List<ColumnFamilyDescriptor> cfDescriptors =
|
List<ColumnFamilyDescriptor> cfDescriptors =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
cfDescriptors.add(new ColumnFamilyDescriptor("default",
|
cfDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
|
||||||
new ColumnFamilyOptions().setMergeOperatorName(
|
new ColumnFamilyOptions().setMergeOperatorName(
|
||||||
"stringappend")));
|
"stringappend")));
|
||||||
cfDescriptors.add(new ColumnFamilyDescriptor("default",
|
cfDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
|
||||||
new ColumnFamilyOptions().setMergeOperatorName(
|
new ColumnFamilyOptions().setMergeOperatorName(
|
||||||
"stringappend")));
|
"stringappend")));
|
||||||
db = RocksDB.open(opt, db_path_string,
|
db = RocksDB.open(opt, db_path_string,
|
||||||
@ -158,10 +157,10 @@ public class MergeTest {
|
|||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
List<ColumnFamilyHandle> columnFamilyHandleList =
|
List<ColumnFamilyHandle> columnFamilyHandleList =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
cfDescriptors.add(new ColumnFamilyDescriptor("default",
|
cfDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
|
||||||
new ColumnFamilyOptions().setMergeOperator(
|
new ColumnFamilyOptions().setMergeOperator(
|
||||||
stringAppendOperator)));
|
stringAppendOperator)));
|
||||||
cfDescriptors.add(new ColumnFamilyDescriptor("new_cf",
|
cfDescriptors.add(new ColumnFamilyDescriptor("new_cf".getBytes(),
|
||||||
new ColumnFamilyOptions().setMergeOperator(
|
new ColumnFamilyOptions().setMergeOperator(
|
||||||
stringAppendOperator)));
|
stringAppendOperator)));
|
||||||
db = RocksDB.open(opt, db_path_string,
|
db = RocksDB.open(opt, db_path_string,
|
||||||
@ -178,7 +177,7 @@ public class MergeTest {
|
|||||||
|
|
||||||
// Test also with createColumnFamily
|
// Test also with createColumnFamily
|
||||||
columnFamilyHandle = db.createColumnFamily(
|
columnFamilyHandle = db.createColumnFamily(
|
||||||
new ColumnFamilyDescriptor("new_cf2",
|
new ColumnFamilyDescriptor("new_cf2".getBytes(),
|
||||||
new ColumnFamilyOptions().setMergeOperator(stringAppendOperator)));
|
new ColumnFamilyOptions().setMergeOperator(stringAppendOperator)));
|
||||||
// writing xx under cfkey2
|
// writing xx under cfkey2
|
||||||
db.put(columnFamilyHandle, "cfkey2".getBytes(), "xx".getBytes());
|
db.put(columnFamilyHandle, "cfkey2".getBytes(), "xx".getBytes());
|
||||||
|
@ -58,9 +58,9 @@ public class ReadOnlyTest {
|
|||||||
db = RocksDB.open(
|
db = RocksDB.open(
|
||||||
dbFolder.getRoot().getAbsolutePath(), cfDescriptors, columnFamilyHandleList);
|
dbFolder.getRoot().getAbsolutePath(), cfDescriptors, columnFamilyHandleList);
|
||||||
columnFamilyHandleList.add(db.createColumnFamily(
|
columnFamilyHandleList.add(db.createColumnFamily(
|
||||||
new ColumnFamilyDescriptor("new_cf", new ColumnFamilyOptions())));
|
new ColumnFamilyDescriptor("new_cf".getBytes(), new ColumnFamilyOptions())));
|
||||||
columnFamilyHandleList.add(db.createColumnFamily(
|
columnFamilyHandleList.add(db.createColumnFamily(
|
||||||
new ColumnFamilyDescriptor("new_cf2", new ColumnFamilyOptions())));
|
new ColumnFamilyDescriptor("new_cf2".getBytes(), new ColumnFamilyOptions())));
|
||||||
db.put(columnFamilyHandleList.get(2), "key2".getBytes(),
|
db.put(columnFamilyHandleList.get(2), "key2".getBytes(),
|
||||||
"value2".getBytes());
|
"value2".getBytes());
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ public class ReadOnlyTest {
|
|||||||
new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
|
new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY,
|
||||||
new ColumnFamilyOptions()));
|
new ColumnFamilyOptions()));
|
||||||
cfDescriptors.add(
|
cfDescriptors.add(
|
||||||
new ColumnFamilyDescriptor("new_cf2", new ColumnFamilyOptions()));
|
new ColumnFamilyDescriptor("new_cf2".getBytes(), new ColumnFamilyOptions()));
|
||||||
db3 = RocksDB.openReadOnly(
|
db3 = RocksDB.openReadOnly(
|
||||||
dbFolder.getRoot().getAbsolutePath(), cfDescriptors, readOnlyColumnFamilyHandleList2);
|
dbFolder.getRoot().getAbsolutePath(), cfDescriptors, readOnlyColumnFamilyHandleList2);
|
||||||
assertThat(new String(db3.get(readOnlyColumnFamilyHandleList2.get(1),
|
assertThat(new String(db3.get(readOnlyColumnFamilyHandleList2.get(1),
|
||||||
|
@ -370,7 +370,7 @@ public class RocksDBTest {
|
|||||||
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
|
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
|
||||||
RocksDB.DEFAULT_COLUMN_FAMILY));
|
RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||||
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
|
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
|
||||||
"new_cf",
|
"new_cf".getBytes(),
|
||||||
new ColumnFamilyOptions().
|
new ColumnFamilyOptions().
|
||||||
setDisableAutoCompactions(true).
|
setDisableAutoCompactions(true).
|
||||||
setCompactionStyle(CompactionStyle.LEVEL).
|
setCompactionStyle(CompactionStyle.LEVEL).
|
||||||
@ -501,7 +501,7 @@ public class RocksDBTest {
|
|||||||
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
|
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
|
||||||
RocksDB.DEFAULT_COLUMN_FAMILY));
|
RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||||
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
|
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
|
||||||
"new_cf",
|
"new_cf".getBytes(),
|
||||||
new ColumnFamilyOptions().
|
new ColumnFamilyOptions().
|
||||||
setDisableAutoCompactions(true).
|
setDisableAutoCompactions(true).
|
||||||
setCompactionStyle(CompactionStyle.LEVEL).
|
setCompactionStyle(CompactionStyle.LEVEL).
|
||||||
@ -556,7 +556,7 @@ public class RocksDBTest {
|
|||||||
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
|
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
|
||||||
RocksDB.DEFAULT_COLUMN_FAMILY));
|
RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||||
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
|
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
|
||||||
"new_cf",
|
"new_cf".getBytes(),
|
||||||
new ColumnFamilyOptions().
|
new ColumnFamilyOptions().
|
||||||
setDisableAutoCompactions(true).
|
setDisableAutoCompactions(true).
|
||||||
setCompactionStyle(CompactionStyle.LEVEL).
|
setCompactionStyle(CompactionStyle.LEVEL).
|
||||||
@ -670,7 +670,7 @@ public class RocksDBTest {
|
|||||||
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
|
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
|
||||||
RocksDB.DEFAULT_COLUMN_FAMILY));
|
RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||||
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
|
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
|
||||||
"new_cf",
|
"new_cf".getBytes(),
|
||||||
new ColumnFamilyOptions().
|
new ColumnFamilyOptions().
|
||||||
setDisableAutoCompactions(true).
|
setDisableAutoCompactions(true).
|
||||||
setCompactionStyle(CompactionStyle.LEVEL).
|
setCompactionStyle(CompactionStyle.LEVEL).
|
||||||
|
@ -172,7 +172,7 @@ class ColumnFamilyDescriptorJni {
|
|||||||
static jmethodID getColumnFamilyNameMethod(JNIEnv* env) {
|
static jmethodID getColumnFamilyNameMethod(JNIEnv* env) {
|
||||||
static jmethodID mid = env->GetMethodID(
|
static jmethodID mid = env->GetMethodID(
|
||||||
getColumnFamilyDescriptorClass(env),
|
getColumnFamilyDescriptorClass(env),
|
||||||
"columnFamilyName", "()Ljava/lang/String;");
|
"columnFamilyName", "()[B");
|
||||||
assert(mid != nullptr);
|
assert(mid != nullptr);
|
||||||
return mid;
|
return mid;
|
||||||
}
|
}
|
||||||
|
@ -74,8 +74,8 @@ jobject
|
|||||||
rocksdb::DB* db = nullptr;
|
rocksdb::DB* db = nullptr;
|
||||||
const char* db_path = env->GetStringUTFChars(jdb_path, 0);
|
const char* db_path = env->GetStringUTFChars(jdb_path, 0);
|
||||||
|
|
||||||
std::vector<const char*> cfnames_to_free;
|
std::vector<jbyte*> cfnames_to_free;
|
||||||
std::vector<jstring> jcfnames_for_free;
|
std::vector<jbyteArray> jcfnames_for_free;
|
||||||
|
|
||||||
std::vector<rocksdb::ColumnFamilyDescriptor> column_families;
|
std::vector<rocksdb::ColumnFamilyDescriptor> column_families;
|
||||||
std::vector<rocksdb::ColumnFamilyHandle* > handles;
|
std::vector<rocksdb::ColumnFamilyHandle* > handles;
|
||||||
@ -90,9 +90,10 @@ jobject
|
|||||||
jobject jcf_descriptor = env->CallObjectMethod(iteratorObj,
|
jobject jcf_descriptor = env->CallObjectMethod(iteratorObj,
|
||||||
rocksdb::ListJni::getNextMethod(env));
|
rocksdb::ListJni::getNextMethod(env));
|
||||||
// get ColumnFamilyName
|
// get ColumnFamilyName
|
||||||
jstring jstr = (jstring) env->CallObjectMethod(jcf_descriptor,
|
jbyteArray byteArray = static_cast<jbyteArray>(env->CallObjectMethod(
|
||||||
|
jcf_descriptor,
|
||||||
rocksdb::ColumnFamilyDescriptorJni::getColumnFamilyNameMethod(
|
rocksdb::ColumnFamilyDescriptorJni::getColumnFamilyNameMethod(
|
||||||
env));
|
env)));
|
||||||
// get CF Options
|
// get CF Options
|
||||||
jobject jcf_opt_obj = env->CallObjectMethod(jcf_descriptor,
|
jobject jcf_opt_obj = env->CallObjectMethod(jcf_descriptor,
|
||||||
rocksdb::ColumnFamilyDescriptorJni::getColumnFamilyOptionsMethod(
|
rocksdb::ColumnFamilyDescriptorJni::getColumnFamilyOptionsMethod(
|
||||||
@ -100,12 +101,13 @@ jobject
|
|||||||
rocksdb::ColumnFamilyOptions* cfOptions =
|
rocksdb::ColumnFamilyOptions* cfOptions =
|
||||||
rocksdb::ColumnFamilyOptionsJni::getHandle(env, jcf_opt_obj);
|
rocksdb::ColumnFamilyOptionsJni::getHandle(env, jcf_opt_obj);
|
||||||
|
|
||||||
const char* cfname = env->GetStringUTFChars(jstr, 0);
|
jbyte* cfname = env->GetByteArrayElements(byteArray, 0);
|
||||||
|
|
||||||
// free allocated cfnames after call to open
|
// free allocated cfnames after call to open
|
||||||
cfnames_to_free.push_back(cfname);
|
cfnames_to_free.push_back(cfname);
|
||||||
jcfnames_for_free.push_back(jstr);
|
jcfnames_for_free.push_back(byteArray);
|
||||||
column_families.push_back(rocksdb::ColumnFamilyDescriptor(cfname,
|
column_families.push_back(rocksdb::ColumnFamilyDescriptor(
|
||||||
|
reinterpret_cast<char *>(cfname),
|
||||||
*cfOptions));
|
*cfOptions));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +118,7 @@ jobject
|
|||||||
for (std::vector<jbyte*>::size_type i = 0;
|
for (std::vector<jbyte*>::size_type i = 0;
|
||||||
i != cfnames_to_free.size(); i++) {
|
i != cfnames_to_free.size(); i++) {
|
||||||
// free cfnames
|
// free cfnames
|
||||||
env->ReleaseStringUTFChars(jcfnames_for_free[i], cfnames_to_free[i]);
|
env->ReleaseByteArrayElements(jcfnames_for_free[i], cfnames_to_free[i], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if open operation was successful
|
// check if open operation was successful
|
||||||
@ -157,8 +159,8 @@ jobject Java_org_rocksdb_RocksDB_open__JLjava_lang_String_2Ljava_util_List_2I(
|
|||||||
rocksdb::DB* db = nullptr;
|
rocksdb::DB* db = nullptr;
|
||||||
const char* db_path = env->GetStringUTFChars(jdb_path, 0);
|
const char* db_path = env->GetStringUTFChars(jdb_path, 0);
|
||||||
|
|
||||||
std::vector<const char*> cfnames_to_free;
|
std::vector<jbyte*> cfnames_to_free;
|
||||||
std::vector<jstring> jcfnames_for_free;
|
std::vector<jbyteArray> jcfnames_for_free;
|
||||||
|
|
||||||
std::vector<rocksdb::ColumnFamilyDescriptor> column_families;
|
std::vector<rocksdb::ColumnFamilyDescriptor> column_families;
|
||||||
std::vector<rocksdb::ColumnFamilyHandle* > handles;
|
std::vector<rocksdb::ColumnFamilyHandle* > handles;
|
||||||
@ -173,9 +175,10 @@ jobject Java_org_rocksdb_RocksDB_open__JLjava_lang_String_2Ljava_util_List_2I(
|
|||||||
jobject jcf_descriptor = env->CallObjectMethod(iteratorObj,
|
jobject jcf_descriptor = env->CallObjectMethod(iteratorObj,
|
||||||
rocksdb::ListJni::getNextMethod(env));
|
rocksdb::ListJni::getNextMethod(env));
|
||||||
// get ColumnFamilyName
|
// get ColumnFamilyName
|
||||||
jstring jstr = (jstring) env->CallObjectMethod(jcf_descriptor,
|
jbyteArray byteArray = static_cast<jbyteArray>(env->CallObjectMethod(
|
||||||
|
jcf_descriptor,
|
||||||
rocksdb::ColumnFamilyDescriptorJni::getColumnFamilyNameMethod(
|
rocksdb::ColumnFamilyDescriptorJni::getColumnFamilyNameMethod(
|
||||||
env));
|
env)));
|
||||||
// get CF Options
|
// get CF Options
|
||||||
jobject jcf_opt_obj = env->CallObjectMethod(jcf_descriptor,
|
jobject jcf_opt_obj = env->CallObjectMethod(jcf_descriptor,
|
||||||
rocksdb::ColumnFamilyDescriptorJni::getColumnFamilyOptionsMethod(
|
rocksdb::ColumnFamilyDescriptorJni::getColumnFamilyOptionsMethod(
|
||||||
@ -183,12 +186,13 @@ jobject Java_org_rocksdb_RocksDB_open__JLjava_lang_String_2Ljava_util_List_2I(
|
|||||||
rocksdb::ColumnFamilyOptions* cfOptions =
|
rocksdb::ColumnFamilyOptions* cfOptions =
|
||||||
rocksdb::ColumnFamilyOptionsJni::getHandle(env, jcf_opt_obj);
|
rocksdb::ColumnFamilyOptionsJni::getHandle(env, jcf_opt_obj);
|
||||||
|
|
||||||
const char* cfname = env->GetStringUTFChars(jstr, 0);
|
jbyte* cfname = env->GetByteArrayElements(byteArray, 0);
|
||||||
|
|
||||||
// free allocated cfnames after call to open
|
// free allocated cfnames after call to open
|
||||||
cfnames_to_free.push_back(cfname);
|
cfnames_to_free.push_back(cfname);
|
||||||
jcfnames_for_free.push_back(jstr);
|
jcfnames_for_free.push_back(byteArray);
|
||||||
column_families.push_back(rocksdb::ColumnFamilyDescriptor(cfname,
|
column_families.push_back(rocksdb::ColumnFamilyDescriptor(
|
||||||
|
reinterpret_cast<const char *>(cfname),
|
||||||
*cfOptions));
|
*cfOptions));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +203,7 @@ jobject Java_org_rocksdb_RocksDB_open__JLjava_lang_String_2Ljava_util_List_2I(
|
|||||||
for (std::vector<jbyte*>::size_type i = 0;
|
for (std::vector<jbyte*>::size_type i = 0;
|
||||||
i != cfnames_to_free.size(); i++) {
|
i != cfnames_to_free.size(); i++) {
|
||||||
// free cfnames
|
// free cfnames
|
||||||
env->ReleaseStringUTFChars(jcfnames_for_free[i], cfnames_to_free[i]);
|
env->ReleaseByteArrayElements(jcfnames_for_free[i], cfnames_to_free[i], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if open operation was successful
|
// check if open operation was successful
|
||||||
@ -1181,9 +1185,11 @@ jlong Java_org_rocksdb_RocksDB_createColumnFamily(
|
|||||||
rocksdb::ColumnFamilyHandle* handle;
|
rocksdb::ColumnFamilyHandle* handle;
|
||||||
auto db_handle = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
auto db_handle = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
||||||
|
|
||||||
jstring jstr = (jstring) env->CallObjectMethod(jcf_descriptor,
|
// get ColumnFamilyName
|
||||||
|
jbyteArray byteArray = static_cast<jbyteArray>(env->CallObjectMethod(
|
||||||
|
jcf_descriptor,
|
||||||
rocksdb::ColumnFamilyDescriptorJni::getColumnFamilyNameMethod(
|
rocksdb::ColumnFamilyDescriptorJni::getColumnFamilyNameMethod(
|
||||||
env));
|
env)));
|
||||||
// get CF Options
|
// get CF Options
|
||||||
jobject jcf_opt_obj = env->CallObjectMethod(jcf_descriptor,
|
jobject jcf_opt_obj = env->CallObjectMethod(jcf_descriptor,
|
||||||
rocksdb::ColumnFamilyDescriptorJni::getColumnFamilyOptionsMethod(
|
rocksdb::ColumnFamilyDescriptorJni::getColumnFamilyOptionsMethod(
|
||||||
@ -1191,10 +1197,10 @@ jlong Java_org_rocksdb_RocksDB_createColumnFamily(
|
|||||||
rocksdb::ColumnFamilyOptions* cfOptions =
|
rocksdb::ColumnFamilyOptions* cfOptions =
|
||||||
rocksdb::ColumnFamilyOptionsJni::getHandle(env, jcf_opt_obj);
|
rocksdb::ColumnFamilyOptionsJni::getHandle(env, jcf_opt_obj);
|
||||||
|
|
||||||
const char* cfname = env->GetStringUTFChars(jstr, 0);
|
jbyte* cfname = env->GetByteArrayElements(byteArray, 0);
|
||||||
rocksdb::Status s = db_handle->CreateColumnFamily(
|
rocksdb::Status s = db_handle->CreateColumnFamily(
|
||||||
*cfOptions, cfname, &handle);
|
*cfOptions, reinterpret_cast<char *>(cfname), &handle);
|
||||||
env->ReleaseStringUTFChars(jstr, cfname);
|
env->ReleaseByteArrayElements(byteArray, cfname, 0);
|
||||||
|
|
||||||
if (s.ok()) {
|
if (s.ok()) {
|
||||||
return reinterpret_cast<jlong>(handle);
|
return reinterpret_cast<jlong>(handle);
|
||||||
|
Loading…
Reference in New Issue
Block a user