diff --git a/nano/secure/transaction.hpp b/nano/secure/transaction.hpp index 8a3ebd9c1..0a1bd90a4 100644 --- a/nano/secure/transaction.hpp +++ b/nano/secure/transaction.hpp @@ -27,6 +27,9 @@ public: // Conversion operator to const nano::store::transaction& virtual operator const nano::store::transaction & () const = 0; + + // Certain transactions may need to be refreshed if they are held for a long time + virtual bool refresh_if_needed (std::chrono::milliseconds max_age = std::chrono::milliseconds{ 500 }) = 0; }; class write_transaction final : public transaction @@ -69,7 +72,7 @@ public: renew (); } - bool refresh_if_needed (std::chrono::milliseconds max_age = std::chrono::milliseconds{ 500 }) + bool refresh_if_needed (std::chrono::milliseconds max_age = std::chrono::milliseconds{ 500 }) override { auto now = std::chrono::steady_clock::now (); if (now - start > max_age) @@ -119,9 +122,9 @@ public: txn.refresh (); } - void refresh_if_needed (std::chrono::milliseconds max_age = std::chrono::milliseconds{ 500 }) + bool refresh_if_needed (std::chrono::milliseconds max_age = std::chrono::milliseconds{ 500 }) override { - txn.refresh_if_needed (max_age); + return txn.refresh_if_needed (max_age); } auto timestamp () const diff --git a/nano/store/transaction.cpp b/nano/store/transaction.cpp index 0d1d6a900..6f475bf06 100644 --- a/nano/store/transaction.cpp +++ b/nano/store/transaction.cpp @@ -83,13 +83,15 @@ void nano::store::read_transaction::refresh () renew (); } -void nano::store::read_transaction::refresh_if_needed (std::chrono::milliseconds max_age) +bool nano::store::read_transaction::refresh_if_needed (std::chrono::milliseconds max_age) { auto now = std::chrono::steady_clock::now (); if (now - start > max_age) { refresh (); + return true; } + return false; } /* diff --git a/nano/store/transaction.hpp b/nano/store/transaction.hpp index 23459a925..0697e1b1e 100644 --- a/nano/store/transaction.hpp +++ b/nano/store/transaction.hpp @@ -66,7 +66,7 @@ public: void reset (); void renew (); void refresh (); - void refresh_if_needed (std::chrono::milliseconds max_age = std::chrono::milliseconds{ 500 }); + bool refresh_if_needed (std::chrono::milliseconds max_age = std::chrono::milliseconds{ 500 }); private: std::unique_ptr impl;