aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSemyon Danilov <senya@ydb.tech>2024-10-07 13:15:57 +0400
committerGitHub <noreply@github.com>2024-10-07 13:15:57 +0400
commit737f797b5636c3d63f45d085ae3bffcf3168621c (patch)
tree690013731595dc5122817797a457e7e5a6685096
parente05f787d5d710d58070af7ab394f6da4e6b258da (diff)
downloadydb-737f797b5636c3d63f45d085ae3bffcf3168621c.tar.gz
Fix PDisk race in restart (#10113)
-rw-r--r--ydb/core/blobstorage/pdisk/blobstorage_pdisk_actor.cpp4
-rw-r--r--ydb/core/blobstorage/pdisk/blobstorage_pdisk_impl.h2
-rw-r--r--ydb/core/blobstorage/pdisk/blobstorage_pdisk_impl_log.cpp6
-rw-r--r--ydb/core/blobstorage/ut_blobstorage/lib/env.h2
-rw-r--r--ydb/core/util/testactorsys.cpp10
5 files changed, 16 insertions, 8 deletions
diff --git a/ydb/core/blobstorage/pdisk/blobstorage_pdisk_actor.cpp b/ydb/core/blobstorage/pdisk/blobstorage_pdisk_actor.cpp
index 38c90188fa..f405c5acd9 100644
--- a/ydb/core/blobstorage/pdisk/blobstorage_pdisk_actor.cpp
+++ b/ydb/core/blobstorage/pdisk/blobstorage_pdisk_actor.cpp
@@ -1069,7 +1069,9 @@ public:
void Handle(TEvBlobStorage::TEvAskWardenRestartPDiskResult::TPtr &ev) {
bool restartAllowed = ev->Get()->RestartAllowed;
- bool isReadingLog = PDisk->InitPhase == EInitPhase::ReadingSysLog || PDisk->InitPhase == EInitPhase::ReadingLog;
+ EInitPhase initPhase = PDisk->InitPhase.load();
+
+ bool isReadingLog = initPhase == EInitPhase::ReadingSysLog || initPhase == EInitPhase::ReadingLog;
if ((isReadingLog && CurrentStateFunc() != &TPDiskActor::StateError) || IsFormattingNow) {
// If disk is in the process of initialization (reading log) and it is not in error state, or disk is being formatted,
diff --git a/ydb/core/blobstorage/pdisk/blobstorage_pdisk_impl.h b/ydb/core/blobstorage/pdisk/blobstorage_pdisk_impl.h
index e571605489..029aed2907 100644
--- a/ydb/core/blobstorage/pdisk/blobstorage_pdisk_impl.h
+++ b/ydb/core/blobstorage/pdisk/blobstorage_pdisk_impl.h
@@ -168,7 +168,7 @@ public:
// Initialization data
ui64 InitialSysLogWritePosition = 0;
- EInitPhase InitPhase = EInitPhase::Uninitialized;
+ std::atomic<EInitPhase> InitPhase = EInitPhase::Uninitialized;
TBuffer *InitialTailBuffer = nullptr;
TLogPosition InitialLogPosition{0, 0};
volatile ui64 InitialPreviousNonce = 0;
diff --git a/ydb/core/blobstorage/pdisk/blobstorage_pdisk_impl_log.cpp b/ydb/core/blobstorage/pdisk/blobstorage_pdisk_impl_log.cpp
index 8bd2e20ced..6b05ffaab7 100644
--- a/ydb/core/blobstorage/pdisk/blobstorage_pdisk_impl_log.cpp
+++ b/ydb/core/blobstorage/pdisk/blobstorage_pdisk_impl_log.cpp
@@ -1313,7 +1313,7 @@ void TPDisk::MarkChunksAsReleased(TReleaseChunks& req) {
void TPDisk::InitiateReadSysLog(const TActorId &pDiskActor) {
Y_VERIFY_S(PDiskThread.Running(), "expect PDiskThread to be running");
Y_VERIFY_S(InitPhase == EInitPhase::Uninitialized, "expect InitPhase to be Uninitialized, but InitPhase# "
- << InitPhase);
+ << InitPhase.load());
ui32 formatSectorsSize = FormatSectorSize * ReplicationFactor;
THolder<TEvReadFormatResult> evReadFormatResult(new TEvReadFormatResult(formatSectorsSize, UseHugePages));
ui8 *formatSectors = evReadFormatResult->FormatSectors.Get();
@@ -1329,7 +1329,7 @@ void TPDisk::ProcessReadLogResult(const NPDisk::TEvReadLogResult &evReadLogResul
if (evReadLogResult.Status != NKikimrProto::OK) {
P_LOG(PRI_ERROR, BPD01, "Error on log read",
(evReadLogResult, evReadLogResult.ToString()),
- (InitPhase, InitPhase));
+ (InitPhase, InitPhase.load()));
switch (InitPhase) {
case EInitPhase::ReadingSysLog:
*Mon.PDiskState = NKikimrBlobStorage::TPDiskState::InitialSysLogReadError;
@@ -1509,7 +1509,7 @@ void TPDisk::ProcessReadLogResult(const NPDisk::TEvReadLogResult &evReadLogResul
return;
}
default:
- Y_FAIL_S("Unexpected InitPhase# " << InitPhase);
+ Y_FAIL_S("Unexpected InitPhase# " << InitPhase.load());
}
}
diff --git a/ydb/core/blobstorage/ut_blobstorage/lib/env.h b/ydb/core/blobstorage/ut_blobstorage/lib/env.h
index 80c088012f..104fa4986b 100644
--- a/ydb/core/blobstorage/ut_blobstorage/lib/env.h
+++ b/ydb/core/blobstorage/ut_blobstorage/lib/env.h
@@ -153,7 +153,6 @@ struct TEnvironmentSetup {
}
static void SetupEnv() {
- TAppData::TimeProvider = TTestActorSystem::CreateTimeProvider();
ui64 seed = RandomNumber<ui64>();
if (const TString& s = GetEnv("SEED", "")) {
seed = FromString<ui64>(s);
@@ -202,6 +201,7 @@ struct TEnvironmentSetup {
void Initialize() {
Runtime = MakeRuntime();
+ TAppData::TimeProvider = TTestActorSystem::CreateTimeProvider();
if (Settings.PrepareRuntime) {
Settings.PrepareRuntime(*Runtime);
}
diff --git a/ydb/core/util/testactorsys.cpp b/ydb/core/util/testactorsys.cpp
index f8de98e419..af4169672b 100644
--- a/ydb/core/util/testactorsys.cpp
+++ b/ydb/core/util/testactorsys.cpp
@@ -263,11 +263,17 @@ IExecutorPool *TTestActorSystem::CreateTestExecutorPool(ui32 nodeId) {
thread_local TTestActorSystem *TTestActorSystem::CurrentTestActorSystem = nullptr;
TIntrusivePtr<ITimeProvider> TTestActorSystem::CreateTimeProvider() {
+ auto& clock = CurrentTestActorSystem->Clock;
class TTestActorTimeProvider : public ITimeProvider {
public:
- TInstant Now() override { return CurrentTestActorSystem->Clock; }
+ TTestActorTimeProvider(TInstant& clock)
+ : Clock(clock)
+ {}
+ TInstant Now() override { return Clock; }
+ private:
+ TInstant& Clock;
};
- return MakeIntrusive<TTestActorTimeProvider>();
+ return MakeIntrusive<TTestActorTimeProvider>(clock);
}
TIntrusivePtr<IMonotonicTimeProvider> TTestActorSystem::CreateMonotonicTimeProvider() {