-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose OccValidationPolicy to Java API
Allow users of RocksDB JNI to specify the OCC Validation Policy when using OptimisticTransactionOptionsDB.
- Loading branch information
Showing
14 changed files
with
430 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved. | ||
// This source code is licensed under both the GPLv2 (found in the | ||
// COPYING file in the root directory) and Apache 2.0 License | ||
// (found in the LICENSE.Apache file in the root directory). | ||
// | ||
// This file implements the "bridge" between Java and C++ | ||
// for ROCKSDB_NAMESPACE::OptimisticTransactionDBOptions. | ||
|
||
#include <jni.h> | ||
|
||
#include "include/org_rocksdb_OptimisticTransactionOptions.h" | ||
#include "rocksdb/comparator.h" | ||
#include "rocksdb/utilities/optimistic_transaction_db.h" | ||
#include "rocksjni/cplusplus_to_java_convert.h" | ||
#include "rocksjni/portal.h" | ||
|
||
/* | ||
* Class: org_rocksdb_OptimisticTransactionDBOptions | ||
* Method: newOptimisticTransactionDBOptions | ||
* Signature: ()J | ||
*/ | ||
jlong Java_org_rocksdb_OptimisticTransactionDBOptions_newOptimisticTransactionDBOptions( | ||
JNIEnv* /*env*/, jclass /*jcls*/) { | ||
ROCKSDB_NAMESPACE::OptimisticTransactionDBOptions* opts = | ||
new ROCKSDB_NAMESPACE::OptimisticTransactionDBOptions(); | ||
return GET_CPLUSPLUS_POINTER(opts); | ||
} | ||
|
||
/* | ||
* Class: org_rocksdb_OptimisticTransactionDBOptions | ||
* Method: setOccValidationPolicy | ||
* Signature: (JB)V | ||
*/ | ||
void Java_org_rocksdb_OptimisticTransactionDBOptions_setOccValidationPolicy( | ||
JNIEnv* /*env*/, jclass /*jcls*/, jlong jhandle, jbyte policy) { | ||
auto* opts = | ||
reinterpret_cast<ROCKSDB_NAMESPACE::OptimisticTransactionDBOptions*>( | ||
jhandle); | ||
opts->validate_policy = | ||
ROCKSDB_NAMESPACE::OccValidationPolicyJni::toCppOccValidationPolicy( | ||
policy); | ||
} | ||
|
||
/* | ||
* Class: org_rocksdb_OptimisticTransactionDBOptions | ||
* Method: getOccValidationPolicy | ||
* Signature: (J)B | ||
*/ | ||
jbyte Java_org_rocksdb_OptimisticTransactionDBOptions_getOccValidationPolicy( | ||
JNIEnv* /*env*/, jclass /*jcls*/, jlong jhandle) { | ||
auto* opts = | ||
reinterpret_cast<ROCKSDB_NAMESPACE::OptimisticTransactionDBOptions*>( | ||
jhandle); | ||
return ROCKSDB_NAMESPACE::OccValidationPolicyJni::toJavaOccValidationPolicy( | ||
opts->validate_policy); | ||
} | ||
|
||
/* | ||
* Class: org_rocksdb_OptimisticTransactionDBOptions | ||
* Method: setOccValidationPolicy | ||
* Signature: (JJ)V | ||
*/ | ||
void Java_org_rocksdb_OptimisticTransactionDBOptions_setOccLockBuckets( | ||
JNIEnv* /*env*/, jclass /*jcls*/, jlong jhandle, jlong occ_lock_buckets) { | ||
auto* opts = | ||
reinterpret_cast<ROCKSDB_NAMESPACE::OptimisticTransactionDBOptions*>( | ||
jhandle); | ||
opts->occ_lock_buckets = static_cast<uint32_t>(occ_lock_buckets); | ||
} | ||
|
||
/* | ||
* Class: org_rocksdb_OptimisticTransactionDBOptions | ||
* Method: getOccValidationPolicy | ||
* Signature: (J)J | ||
*/ | ||
jlong Java_org_rocksdb_OptimisticTransactionDBOptions_getOccLockBuckets( | ||
JNIEnv* /*env*/, jclass /*jcls*/, jlong jhandle) { | ||
auto* opts = | ||
reinterpret_cast<ROCKSDB_NAMESPACE::OptimisticTransactionDBOptions*>( | ||
jhandle); | ||
return static_cast<long>(opts->occ_lock_buckets); | ||
} | ||
|
||
/* | ||
* Class: org_rocksdb_OptimisticTransactionDBOptions | ||
* Method: disposeInternal | ||
* Signature: (J)V | ||
*/ | ||
void Java_org_rocksdb_OptimisticTransactionDBOptions_disposeInternalJni( | ||
JNIEnv* /*env*/, jclass /*jcls*/, jlong jhandle) { | ||
delete reinterpret_cast<ROCKSDB_NAMESPACE::OptimisticTransactionDBOptions*>( | ||
jhandle); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) Meta Platforms, Inc. and affiliates. | ||
// This source code is licensed under both the GPLv2 (found in the | ||
// COPYING file in the root directory) and Apache 2.0 License | ||
// (found in the LICENSE.Apache file in the root directory). | ||
|
||
package org.rocksdb; | ||
|
||
/** | ||
* Defines the policy for optimistic concurrency control validation. | ||
* This enum specifies the manner in which the validation occurs | ||
* during the commit stage. | ||
*/ | ||
public enum OccValidationPolicy { | ||
/** | ||
* Validate serially at commit stage, AFTER entering the write-group. | ||
* This method processes isolation validation in a single-threaded manner | ||
* within the write-group, potentially suffering from high mutex contention | ||
* as discussed in the following issue: | ||
* <a href="https://github.com/facebook/rocksdb/issues/4402">GitHub 4402</a> | ||
*/ | ||
VALIDATE_SERIAL((byte) 0), | ||
|
||
/** | ||
* Validate parallelly before the commit stage, BEFORE entering the write-group. | ||
* This approach aims to reduce mutex contention by having each | ||
* transaction acquire locks for its write-set records in a well-defined | ||
* order prior to entering the write-group. | ||
*/ | ||
VALIDATE_PARALLEL((byte) 1); | ||
|
||
private final byte _value; | ||
|
||
/** | ||
* Constructor for the OccValidationPolicy enum. | ||
* @param _value the byte representation that corresponds to | ||
* one of the above enums. | ||
*/ | ||
OccValidationPolicy(final byte _value) { | ||
this._value = _value; | ||
} | ||
|
||
/** | ||
* Retrieves the byte representation associated with this validation policy. | ||
* @return the byte representation of the validation policy. | ||
*/ | ||
public byte getValue() { | ||
return _value; | ||
} | ||
|
||
/** | ||
* Given a byte representation of a value, convert it to {@link OccValidationPolicy}. | ||
* | ||
* @param policy the byte representation of the policy. | ||
* @return the matching OccValidationPolicy. | ||
* @throws IllegalArgumentException if no matching policy is found. | ||
*/ | ||
public static OccValidationPolicy getOccValidationPolicy(final byte policy) { | ||
for (OccValidationPolicy value : OccValidationPolicy.values()) { | ||
if (value.getValue() == policy) { | ||
return value; | ||
} | ||
} | ||
throw new IllegalArgumentException("Unknown OccValidationPolicy constant : " + policy); | ||
} | ||
} |
Oops, something went wrong.