mirror of https://github.com/facebook/rocksdb.git
Merge pull request #482 from fyrz/RocksJava-TTL-Fix
[RocksJava] Fix ColumnFamily name alloc in TTL DB
This commit is contained in:
commit
d3a736761b
|
@ -57,6 +57,8 @@ jobject
|
||||||
const char* db_path = env->GetStringUTFChars(jdb_path, 0);
|
const char* db_path = env->GetStringUTFChars(jdb_path, 0);
|
||||||
|
|
||||||
std::vector<jbyte*> cfnames_to_free;
|
std::vector<jbyte*> cfnames_to_free;
|
||||||
|
// the zero-terminated version of cfnames_to_free.
|
||||||
|
std::vector<char*> c_cfnames_to_free;
|
||||||
std::vector<jbyteArray> jcfnames_for_free;
|
std::vector<jbyteArray> jcfnames_for_free;
|
||||||
|
|
||||||
std::vector<rocksdb::ColumnFamilyDescriptor> column_families;
|
std::vector<rocksdb::ColumnFamilyDescriptor> column_families;
|
||||||
|
@ -85,12 +87,17 @@ jobject
|
||||||
rocksdb::ColumnFamilyOptionsJni::getHandle(env, jcf_opt_obj);
|
rocksdb::ColumnFamilyOptionsJni::getHandle(env, jcf_opt_obj);
|
||||||
|
|
||||||
jbyte* cfname = env->GetByteArrayElements(byteArray, 0);
|
jbyte* cfname = env->GetByteArrayElements(byteArray, 0);
|
||||||
|
const int len = env->GetArrayLength(byteArray) + 1;
|
||||||
|
char* c_cfname = new char[len];
|
||||||
|
memcpy(c_cfname, cfname, len - 1);
|
||||||
|
c_cfname[len - 1] = 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);
|
||||||
|
c_cfnames_to_free.push_back(c_cfname);
|
||||||
jcfnames_for_free.push_back(byteArray);
|
jcfnames_for_free.push_back(byteArray);
|
||||||
column_families.push_back(rocksdb::ColumnFamilyDescriptor(
|
column_families.push_back(rocksdb::ColumnFamilyDescriptor(
|
||||||
reinterpret_cast<const char *>(cfname),
|
c_cfname, *cfOptions));
|
||||||
*cfOptions));
|
|
||||||
}
|
}
|
||||||
// get iterator for TTL values
|
// get iterator for TTL values
|
||||||
iteratorObj = env->CallObjectMethod(
|
iteratorObj = env->CallObjectMethod(
|
||||||
|
@ -115,6 +122,8 @@ jobject
|
||||||
i != cfnames_to_free.size(); i++) {
|
i != cfnames_to_free.size(); i++) {
|
||||||
// free cfnames
|
// free cfnames
|
||||||
env->ReleaseByteArrayElements(jcfnames_for_free[i], cfnames_to_free[i], 0);
|
env->ReleaseByteArrayElements(jcfnames_for_free[i], cfnames_to_free[i], 0);
|
||||||
|
// free c_cfnames
|
||||||
|
delete[] c_cfnames_to_free[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if open operation was successful
|
// check if open operation was successful
|
||||||
|
@ -167,9 +176,15 @@ jlong Java_org_rocksdb_TtlDB_createColumnFamilyWithTtl(
|
||||||
rocksdb::ColumnFamilyOptionsJni::getHandle(env, jcf_opt_obj);
|
rocksdb::ColumnFamilyOptionsJni::getHandle(env, jcf_opt_obj);
|
||||||
|
|
||||||
jbyte* cfname = env->GetByteArrayElements(byteArray, 0);
|
jbyte* cfname = env->GetByteArrayElements(byteArray, 0);
|
||||||
|
const int len = env->GetArrayLength(byteArray) + 1;
|
||||||
|
char* c_cfname = new char[len];
|
||||||
|
memcpy(c_cfname, cfname, len - 1);
|
||||||
|
c_cfname[len - 1] = 0;
|
||||||
|
|
||||||
rocksdb::Status s = db_handle->CreateColumnFamilyWithTtl(
|
rocksdb::Status s = db_handle->CreateColumnFamilyWithTtl(
|
||||||
*cfOptions, reinterpret_cast<char *>(cfname), &handle, jttl);
|
*cfOptions, c_cfname, &handle, jttl);
|
||||||
env->ReleaseByteArrayElements(byteArray, cfname, 0);
|
env->ReleaseByteArrayElements(byteArray, cfname, 0);
|
||||||
|
delete[] c_cfname;
|
||||||
|
|
||||||
if (s.ok()) {
|
if (s.ok()) {
|
||||||
return reinterpret_cast<jlong>(handle);
|
return reinterpret_cast<jlong>(handle);
|
||||||
|
|
Loading…
Reference in New Issue