feat: enable fdb transaction timeout customization (#4166)
Co-authored-by: Zeyad Deeb <zeyad.deeb@saks.com> Co-authored-by: Tobie Morgan Hitchcock <tobie@surrealdb.com>
This commit is contained in:
parent
99f41ff1a0
commit
1530f9107e
2 changed files with 29 additions and 8 deletions
10
core/src/kvs/fdb/cnf.rs
Normal file
10
core/src/kvs/fdb/cnf.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
use once_cell::sync::Lazy;
|
||||
|
||||
pub static FOUNDATIONDB_TRANSACTION_TIMEOUT: Lazy<i32> =
|
||||
lazy_env_parse_or_else!("SURREAL_FOUNDATIONDB_TRANSACTION_TIMEOUT", i32, |_| { 5000 });
|
||||
|
||||
pub static FOUNDATIONDB_TRANSACTION_RETRY_LIMIT: Lazy<i32> =
|
||||
lazy_env_parse_or_else!("SURREAL_FOUNDATIONDB_TRANSACTION_RETRY_LIMIT", i32, |_| { 5 });
|
||||
|
||||
pub static FOUNDATIONDB_TRANSACTION_MAX_RETRY_DELAY: Lazy<i32> =
|
||||
lazy_env_parse_or_else!("SURREAL_FOUNDATIONDB_TRANSACTION_MAX_RETRY_DELAY", i32, |_| { 500 });
|
|
@ -1,11 +1,13 @@
|
|||
#![cfg(feature = "kv-fdb")]
|
||||
|
||||
mod cnf;
|
||||
|
||||
use crate::err::Error;
|
||||
use crate::kvs::Check;
|
||||
use crate::kvs::Key;
|
||||
use crate::kvs::Val;
|
||||
use crate::vs::{u64_to_versionstamp, Versionstamp};
|
||||
use foundationdb::options;
|
||||
use foundationdb::options::DatabaseOption;
|
||||
use futures::TryStreamExt;
|
||||
use std::ops::Range;
|
||||
use std::sync::Arc;
|
||||
|
@ -90,14 +92,23 @@ impl Datastore {
|
|||
|
||||
match foundationdb::Database::from_path(path) {
|
||||
Ok(db) => {
|
||||
db.set_option(options::DatabaseOption::TransactionRetryLimit(5)).map_err(|e| {
|
||||
Error::Ds(format!("Unable to set transaction retry limit: {}", e))
|
||||
// Set the transaction timeout
|
||||
db.set_option(DatabaseOption::TransactionTimeout(
|
||||
*cnf::FOUNDATIONDB_TRANSACTION_TIMEOUT,
|
||||
))
|
||||
.map_err(|e| Error::Ds(format!("Unable to set transaction timeout: {e}")))?;
|
||||
// Set the transaction retry liimt
|
||||
db.set_option(DatabaseOption::TransactionRetryLimit(
|
||||
*cnf::FOUNDATIONDB_TRANSACTION_RETRY_LIMIT,
|
||||
))
|
||||
.map_err(|e| Error::Ds(format!("Unable to set transaction retry limit: {e}")))?;
|
||||
// Set the transaction max retry delay
|
||||
db.set_option(DatabaseOption::TransactionMaxRetryDelay(
|
||||
*cnf::FOUNDATIONDB_TRANSACTION_MAX_RETRY_DELAY,
|
||||
))
|
||||
.map_err(|e| {
|
||||
Error::Ds(format!("Unable to set transaction max retry delay: {e}"))
|
||||
})?;
|
||||
db.set_option(options::DatabaseOption::TransactionTimeout(5000))
|
||||
.map_err(|e| Error::Ds(format!("Unable to set transaction timeout: {}", e)))?;
|
||||
db.set_option(options::DatabaseOption::TransactionMaxRetryDelay(500)).map_err(
|
||||
|e| Error::Ds(format!("Unable to set transaction max retry delay: {}", e)),
|
||||
)?;
|
||||
Ok(Datastore {
|
||||
db,
|
||||
_fdbnet,
|
||||
|
|
Loading…
Reference in a new issue