diff options
author | Alexey Borzenkov <snaury@yandex-team.ru> | 2022-04-18 18:40:28 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-04-18 18:40:28 +0300 |
commit | 9ada39f7f8bf02130d705ad98476449e5ff29443 (patch) | |
tree | 5f685fdb250fe15b40eec5b95a3817f2957d3f12 /library | |
parent | 86304e375567b039455008cdc9b12cfc5f5c66de (diff) | |
download | ydb-9ada39f7f8bf02130d705ad98476449e5ff29443.tar.gz |
22-2: Snapshot isolation with prioritized reads, KIKIMR-13910
Merge from trunk: r9171244, r9229795, r9244174, r9285534, r9300998, r9313872
REVIEW: 2435130
x-ydb-stable-ref: 9c878f6e7949737ee83323c98c1b7c64c372710e
Diffstat (limited to 'library')
-rw-r--r-- | library/cpp/actors/core/monotonic_provider.cpp | 16 | ||||
-rw-r--r-- | library/cpp/actors/core/monotonic_provider.h | 14 | ||||
-rw-r--r-- | library/cpp/actors/core/ya.make | 2 | ||||
-rw-r--r-- | library/cpp/actors/testlib/test_runtime.cpp | 26 | ||||
-rw-r--r-- | library/cpp/actors/testlib/test_runtime.h | 5 |
5 files changed, 63 insertions, 0 deletions
diff --git a/library/cpp/actors/core/monotonic_provider.cpp b/library/cpp/actors/core/monotonic_provider.cpp new file mode 100644 index 0000000000..fb3b656da6 --- /dev/null +++ b/library/cpp/actors/core/monotonic_provider.cpp @@ -0,0 +1,16 @@ +#include "monotonic_provider.h" + +namespace NActors { + +class TDefaultMonotonicTimeProvider : public IMonotonicTimeProvider { +public: + TMonotonic Now() override { + return TMonotonic::Now(); + } +}; + +TIntrusivePtr<IMonotonicTimeProvider> CreateDefaultMonotonicTimeProvider() { + return TIntrusivePtr<IMonotonicTimeProvider>(new TDefaultMonotonicTimeProvider); +} + +} // namespace NActors diff --git a/library/cpp/actors/core/monotonic_provider.h b/library/cpp/actors/core/monotonic_provider.h new file mode 100644 index 0000000000..98e1203400 --- /dev/null +++ b/library/cpp/actors/core/monotonic_provider.h @@ -0,0 +1,14 @@ +#pragma once + +#include "monotonic.h" + +namespace NActors { + +class IMonotonicTimeProvider : public TThrRefBase { +public: + virtual TMonotonic Now() = 0; +}; + +TIntrusivePtr<IMonotonicTimeProvider> CreateDefaultMonotonicTimeProvider(); + +} // namespace NActors diff --git a/library/cpp/actors/core/ya.make b/library/cpp/actors/core/ya.make index 880a9d00db..2979020d68 100644 --- a/library/cpp/actors/core/ya.make +++ b/library/cpp/actors/core/ya.make @@ -83,6 +83,8 @@ SRCS( mon_stats.h monotonic.cpp monotonic.h + monotonic_provider.cpp + monotonic_provider.h worker_context.cpp worker_context.h probes.cpp diff --git a/library/cpp/actors/testlib/test_runtime.cpp b/library/cpp/actors/testlib/test_runtime.cpp index 6fa25b9965..51d93ba6e9 100644 --- a/library/cpp/actors/testlib/test_runtime.cpp +++ b/library/cpp/actors/testlib/test_runtime.cpp @@ -233,6 +233,20 @@ namespace NActors { TTestActorRuntimeBase& Runtime; }; + class TTestActorRuntimeBase::TMonotonicTimeProvider : public IMonotonicTimeProvider { + public: + TMonotonicTimeProvider(TTestActorRuntimeBase& runtime) + : Runtime(runtime) + { } + + TMonotonic Now() override { + return Runtime.GetCurrentMonotonicTime(); + } + + private: + TTestActorRuntimeBase& Runtime; + }; + class TTestActorRuntimeBase::TSchedulerThreadStub : public ISchedulerThread { public: TSchedulerThreadStub(TTestActorRuntimeBase* runtime, TTestActorRuntimeBase::TNodeDataBase* node) @@ -470,6 +484,7 @@ namespace NActors { , NeedMonitoring(false) , RandomProvider(CreateDeterministicRandomProvider(DefaultRandomSeed)) , TimeProvider(new TTimeProvider(*this)) + , MonotonicTimeProvider(new TMonotonicTimeProvider(*this)) , ShouldContinue() , CurrentTimestamp(0) , DispatchTimeout(DEFAULT_DISPATCH_TIMEOUT) @@ -797,6 +812,12 @@ namespace NActors { return TInstant::MicroSeconds(CurrentTimestamp); } + TMonotonic TTestActorRuntimeBase::GetCurrentMonotonicTime() const { + TGuard<TMutex> guard(Mutex); + Y_VERIFY(!UseRealThreads); + return TMonotonic::MicroSeconds(CurrentTimestamp); + } + void TTestActorRuntimeBase::UpdateCurrentTime(TInstant newTime) { static int counter = 0; ++counter; @@ -823,6 +844,11 @@ namespace NActors { return TimeProvider; } + TIntrusivePtr<IMonotonicTimeProvider> TTestActorRuntimeBase::GetMonotonicTimeProvider() { + Y_VERIFY(!UseRealThreads); + return MonotonicTimeProvider; + } + ui32 TTestActorRuntimeBase::GetNodeId(ui32 index) const { Y_VERIFY(index < NodeCount); return FirstNodeId + index; diff --git a/library/cpp/actors/testlib/test_runtime.h b/library/cpp/actors/testlib/test_runtime.h index 26e3b45c98..c14cde1b66 100644 --- a/library/cpp/actors/testlib/test_runtime.h +++ b/library/cpp/actors/testlib/test_runtime.h @@ -6,6 +6,7 @@ #include <library/cpp/actors/core/events.h> #include <library/cpp/actors/core/executor_thread.h> #include <library/cpp/actors/core/mailbox.h> +#include <library/cpp/actors/core/monotonic_provider.h> #include <library/cpp/actors/util/should_continue.h> #include <library/cpp/actors/interconnect/poller_tcp.h> #include <library/cpp/actors/interconnect/mock/ic_mock.h> @@ -188,6 +189,7 @@ namespace NActors { class TSchedulerThreadStub; class TExecutorPoolStub; class TTimeProvider; + class TMonotonicTimeProvider; enum class EEventAction { PROCESS, @@ -229,7 +231,9 @@ namespace NActors { void SetLogBackend(const TAutoPtr<TLogBackend> logBackend); void SetLogPriority(NActors::NLog::EComponent component, NActors::NLog::EPriority priority); TIntrusivePtr<ITimeProvider> GetTimeProvider(); + TIntrusivePtr<IMonotonicTimeProvider> GetMonotonicTimeProvider(); TInstant GetCurrentTime() const; + TMonotonic GetCurrentMonotonicTime() const; void UpdateCurrentTime(TInstant newTime); void AdvanceCurrentTime(TDuration duration); void AddLocalService(const TActorId& actorId, const TActorSetupCmd& cmd, ui32 nodeIndex = 0); @@ -534,6 +538,7 @@ namespace NActors { TIntrusivePtr<IRandomProvider> RandomProvider; TIntrusivePtr<ITimeProvider> TimeProvider; + TIntrusivePtr<IMonotonicTimeProvider> MonotonicTimeProvider; protected: struct TNodeDataBase: public TThrRefBase { |