[RocksJava] Fix ColumnFamily name alloc in TTL DB

While fixing the RocksDB ColumnFamily name the TTL DB
wasn`t touched. This commit resolves this.
This commit is contained in:
fyrz 2015-01-31 14:43:21 +01:00
parent 6c6037f60c
commit 939bb36597

View file

@ -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);