(* Keep only enough commit-history to protect the running transactions that we are still tracking *)
(* There is scope for optimisation here, replacing List.filter with something more efficient,
* probably on a different list-like structure. *)
-let trim () =
+let trim ?txn () =
+ Transaction.trim_short_running_transactions txn;
history := match Transaction.oldest_short_running_transaction () with
| None -> [] (* We have no open transaction, so no history is needed *)
| Some (_, txn) -> (
let end_transaction txn con tid commit =
let success = Connection.end_transaction con tid commit in
- Transaction.end_transaction txn;
- trim ();
+ trim ~txn ();
success
let push (x: history_record) =
| x :: xs -> last xs
in last !short_running_txns
-let end_transaction txn =
+let trim_short_running_transactions txn =
let cutoff = Unix.gettimeofday () -. !Define.conflict_max_history_seconds in
+ let keep = match txn with
+ | None -> (function (start_time, _) -> start_time >= cutoff)
+ | Some t -> (function (start_time, tx) -> start_time >= cutoff && tx != t)
+ in
short_running_txns := List.filter
- (function (start_time, tx) -> start_time >= cutoff && tx != txn)
+ keep
!short_running_txns
let make ?(internal=false) id store =
* than the periodic_ops function *)
let frequent_ops () =
if Unix.gettimeofday () > !next_frequent_ops then (
+ History.trim ();
Domains.incr_conflict_credit domains;
advance_next_frequent_ops ()
) in