Virtual transaction refresh_if_needed

This commit is contained in:
Piotr Wójcik 2024-10-26 00:05:47 +02:00
commit bdf129b96b
3 changed files with 10 additions and 5 deletions

View file

@ -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

View file

@ -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;
}
/*

View file

@ -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<read_transaction_impl> impl;