From bada850284b39c27bc2b13491b6f3bfd4479b38f Mon Sep 17 00:00:00 2001 From: Tpt Date: Sun, 12 Dec 2021 19:00:44 +0100 Subject: [PATCH] Txn conflict: allows the OS to do something else before retrying --- lib/src/storage/backend/rocksdb.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/storage/backend/rocksdb.rs b/lib/src/storage/backend/rocksdb.rs index ed992b68..960ce740 100644 --- a/lib/src/storage/backend/rocksdb.rs +++ b/lib/src/storage/backend/rocksdb.rs @@ -20,6 +20,7 @@ use std::ops::Deref; use std::path::{Path, PathBuf}; use std::rc::{Rc, Weak}; use std::sync::Arc; +use std::thread::yield_now; use std::{ptr, slice}; macro_rules! ffi_result { @@ -393,7 +394,10 @@ impl Db { msg == "Resource busy: " || msg == "Operation timed out: Timeout waiting to lock key" }); - if !is_conflict_error { + if is_conflict_error { + // We give a chance to the OS to do something else before retrying in order to help avoiding an other conflict + yield_now(); + } else { // We raise the error return Err(e); }