Skip to content

Commit 7ae8880

Browse files
authored
Increase transaction timeout (#289)
## Usage and product changes Set transaction timeout for opened transactions to 1 hour. This change significantly lowers the impact of #287. ## Implementation Use the new `transaction_with_options` interface of the Rust driver to pass configured transaction options.
1 parent ef9b57b commit 7ae8880

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

src/constants.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*/
6+
7+
use std::time::Duration;
8+
9+
use crate::constants::common::SECONDS_IN_HOUR;
10+
11+
pub mod common {
12+
pub const SECONDS_IN_MINUTE: u64 = 60;
13+
pub const MINUTES_IN_HOUR: u64 = 60;
14+
pub const SECONDS_IN_HOUR: u64 = SECONDS_IN_MINUTE * MINUTES_IN_HOUR;
15+
}
16+
17+
pub const DEFAULT_TRANSACTION_TIMEOUT: Duration = Duration::from_secs(1 * SECONDS_IN_HOUR);

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use crate::{
4141

4242
mod cli;
4343
mod completions;
44+
mod constants;
4445
mod operations;
4546
mod printer;
4647
mod repl;

src/operations.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ use std::{error::Error, fs::read_to_string, path::Path, process::exit, rc::Rc};
99
use futures::stream::StreamExt;
1010
use typedb_driver::{
1111
answer::{QueryAnswer, QueryType},
12-
TransactionType,
12+
TransactionOptions, TransactionType,
1313
};
1414

1515
use crate::{
16+
constants::DEFAULT_TRANSACTION_TIMEOUT,
1617
printer::{print_document, print_row},
1718
repl::command::{parse_one_query, CommandResult, ReplError},
1819
transaction_repl, ConsoleContext,
@@ -155,7 +156,9 @@ pub(crate) fn transaction_read(context: &mut ConsoleContext, input: &[String]) -
155156
let db_name_owned = db_name.clone();
156157
let transaction = context
157158
.background_runtime
158-
.run(async move { driver.transaction(db_name_owned, TransactionType::Read).await })
159+
.run(async move {
160+
driver.transaction_with_options(db_name_owned, TransactionType::Read, default_transaction_options()).await
161+
})
159162
.map_err(|err| Box::new(err) as Box<dyn Error + Send>)?;
160163
context.transaction = Some((transaction, false));
161164
let repl = transaction_repl(db_name, TransactionType::Read);
@@ -169,7 +172,9 @@ pub(crate) fn transaction_write(context: &mut ConsoleContext, input: &[String])
169172
let db_name_owned = db_name.clone();
170173
let transaction = context
171174
.background_runtime
172-
.run(async move { driver.transaction(db_name_owned, TransactionType::Write).await })
175+
.run(async move {
176+
driver.transaction_with_options(db_name_owned, TransactionType::Write, default_transaction_options()).await
177+
})
173178
.map_err(|err| Box::new(err) as Box<dyn Error + Send>)?;
174179
context.transaction = Some((transaction, false));
175180
let repl = transaction_repl(db_name, TransactionType::Write);
@@ -183,7 +188,9 @@ pub(crate) fn transaction_schema(context: &mut ConsoleContext, input: &[String])
183188
let db_name_owned = db_name.clone();
184189
let transaction = context
185190
.background_runtime
186-
.run(async move { driver.transaction(db_name_owned, TransactionType::Schema).await })
191+
.run(async move {
192+
driver.transaction_with_options(db_name_owned, TransactionType::Schema, default_transaction_options()).await
193+
})
187194
.map_err(|err| Box::new(err) as Box<dyn Error + Send>)?;
188195
context.transaction = Some((transaction, false));
189196
let repl = transaction_repl(db_name, TransactionType::Schema);
@@ -307,6 +314,10 @@ pub(crate) fn transaction_query(context: &mut ConsoleContext, input: &[impl AsRe
307314
}
308315
}
309316

317+
fn default_transaction_options() -> TransactionOptions {
318+
TransactionOptions::new().transaction_timeout(DEFAULT_TRANSACTION_TIMEOUT)
319+
}
320+
310321
const QUERY_TYPE_TEMPLATE: &'static str = "<QUERY TYPE>";
311322
const QUERY_COMPILATION_SUCCESS: &'static str = "Finished <QUERY TYPE> query validation and compilation...";
312323
const QUERY_WRITE_FINISHED_STREAMING_ROWS: &'static str = "Finished writes. Streaming rows...";

0 commit comments

Comments
 (0)