Skip to content

Commit

Permalink
feat: enable fdb transaction timeout customization (#4166)
Browse files Browse the repository at this point in the history
Co-authored-by: Zeyad Deeb <zeyad.deeb@saks.com>
Co-authored-by: Tobie Morgan Hitchcock <tobie@surrealdb.com>
  • Loading branch information
3 people committed Jun 13, 2024
1 parent 99f41ff commit 1530f91
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
10 changes: 10 additions & 0 deletions core/src/kvs/fdb/cnf.rs
Original file line number Diff line number Diff line change
@@ -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 });
27 changes: 19 additions & 8 deletions core/src/kvs/fdb/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1530f91

Please sign in to comment.