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);
|
||||
|
||||
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<rocksdb::ColumnFamilyDescriptor> column_families;
|
||||
@ -85,12 +87,17 @@ jobject
|
||||
rocksdb::ColumnFamilyOptionsJni::getHandle(env, jcf_opt_obj);
|
||||
|
||||
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
|
||||
cfnames_to_free.push_back(cfname);
|
||||
c_cfnames_to_free.push_back(c_cfname);
|
||||
jcfnames_for_free.push_back(byteArray);
|
||||
column_families.push_back(rocksdb::ColumnFamilyDescriptor(
|
||||
reinterpret_cast<const char *>(cfname),
|
||||
*cfOptions));
|
||||
c_cfname, *cfOptions));
|
||||
}
|
||||
// get iterator for TTL values
|
||||
iteratorObj = env->CallObjectMethod(
|
||||
@ -115,6 +122,8 @@ jobject
|
||||
i != cfnames_to_free.size(); i++) {
|
||||
// free cfnames
|
||||
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
|
||||
@ -167,9 +176,15 @@ jlong Java_org_rocksdb_TtlDB_createColumnFamilyWithTtl(
|
||||
rocksdb::ColumnFamilyOptionsJni::getHandle(env, jcf_opt_obj);
|
||||
|
||||
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(
|
||||
*cfOptions, reinterpret_cast<char *>(cfname), &handle, jttl);
|
||||
*cfOptions, c_cfname, &handle, jttl);
|
||||
env->ReleaseByteArrayElements(byteArray, cfname, 0);
|
||||
delete[] c_cfname;
|
||||
|
||||
if (s.ok()) {
|
||||
return reinterpret_cast<jlong>(handle);
|
||||
|
Loading…
Reference in New Issue
Block a user