Skip to content

Commit 737f797

Browse files
authored
Fix PDisk race in restart (#10113)
1 parent e05f787 commit 737f797

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

ydb/core/blobstorage/pdisk/blobstorage_pdisk_actor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,9 @@ class TPDiskActor : public TActorBootstrapped<TPDiskActor> {
10691069
void Handle(TEvBlobStorage::TEvAskWardenRestartPDiskResult::TPtr &ev) {
10701070
bool restartAllowed = ev->Get()->RestartAllowed;
10711071

1072-
bool isReadingLog = PDisk->InitPhase == EInitPhase::ReadingSysLog || PDisk->InitPhase == EInitPhase::ReadingLog;
1072+
EInitPhase initPhase = PDisk->InitPhase.load();
1073+
1074+
bool isReadingLog = initPhase == EInitPhase::ReadingSysLog || initPhase == EInitPhase::ReadingLog;
10731075

10741076
if ((isReadingLog && CurrentStateFunc() != &TPDiskActor::StateError) || IsFormattingNow) {
10751077
// If disk is in the process of initialization (reading log) and it is not in error state, or disk is being formatted,

ydb/core/blobstorage/pdisk/blobstorage_pdisk_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class TPDisk : public IPDisk {
168168

169169
// Initialization data
170170
ui64 InitialSysLogWritePosition = 0;
171-
EInitPhase InitPhase = EInitPhase::Uninitialized;
171+
std::atomic<EInitPhase> InitPhase = EInitPhase::Uninitialized;
172172
TBuffer *InitialTailBuffer = nullptr;
173173
TLogPosition InitialLogPosition{0, 0};
174174
volatile ui64 InitialPreviousNonce = 0;

ydb/core/blobstorage/pdisk/blobstorage_pdisk_impl_log.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ void TPDisk::MarkChunksAsReleased(TReleaseChunks& req) {
13131313
void TPDisk::InitiateReadSysLog(const TActorId &pDiskActor) {
13141314
Y_VERIFY_S(PDiskThread.Running(), "expect PDiskThread to be running");
13151315
Y_VERIFY_S(InitPhase == EInitPhase::Uninitialized, "expect InitPhase to be Uninitialized, but InitPhase# "
1316-
<< InitPhase);
1316+
<< InitPhase.load());
13171317
ui32 formatSectorsSize = FormatSectorSize * ReplicationFactor;
13181318
THolder<TEvReadFormatResult> evReadFormatResult(new TEvReadFormatResult(formatSectorsSize, UseHugePages));
13191319
ui8 *formatSectors = evReadFormatResult->FormatSectors.Get();
@@ -1329,7 +1329,7 @@ void TPDisk::ProcessReadLogResult(const NPDisk::TEvReadLogResult &evReadLogResul
13291329
if (evReadLogResult.Status != NKikimrProto::OK) {
13301330
P_LOG(PRI_ERROR, BPD01, "Error on log read",
13311331
(evReadLogResult, evReadLogResult.ToString()),
1332-
(InitPhase, InitPhase));
1332+
(InitPhase, InitPhase.load()));
13331333
switch (InitPhase) {
13341334
case EInitPhase::ReadingSysLog:
13351335
*Mon.PDiskState = NKikimrBlobStorage::TPDiskState::InitialSysLogReadError;
@@ -1509,7 +1509,7 @@ void TPDisk::ProcessReadLogResult(const NPDisk::TEvReadLogResult &evReadLogResul
15091509
return;
15101510
}
15111511
default:
1512-
Y_FAIL_S("Unexpected InitPhase# " << InitPhase);
1512+
Y_FAIL_S("Unexpected InitPhase# " << InitPhase.load());
15131513
}
15141514
}
15151515

ydb/core/blobstorage/ut_blobstorage/lib/env.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ struct TEnvironmentSetup {
153153
}
154154

155155
static void SetupEnv() {
156-
TAppData::TimeProvider = TTestActorSystem::CreateTimeProvider();
157156
ui64 seed = RandomNumber<ui64>();
158157
if (const TString& s = GetEnv("SEED", "")) {
159158
seed = FromString<ui64>(s);
@@ -202,6 +201,7 @@ struct TEnvironmentSetup {
202201

203202
void Initialize() {
204203
Runtime = MakeRuntime();
204+
TAppData::TimeProvider = TTestActorSystem::CreateTimeProvider();
205205
if (Settings.PrepareRuntime) {
206206
Settings.PrepareRuntime(*Runtime);
207207
}

ydb/core/util/testactorsys.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,17 @@ IExecutorPool *TTestActorSystem::CreateTestExecutorPool(ui32 nodeId) {
263263
thread_local TTestActorSystem *TTestActorSystem::CurrentTestActorSystem = nullptr;
264264

265265
TIntrusivePtr<ITimeProvider> TTestActorSystem::CreateTimeProvider() {
266+
auto& clock = CurrentTestActorSystem->Clock;
266267
class TTestActorTimeProvider : public ITimeProvider {
267268
public:
268-
TInstant Now() override { return CurrentTestActorSystem->Clock; }
269+
TTestActorTimeProvider(TInstant& clock)
270+
: Clock(clock)
271+
{}
272+
TInstant Now() override { return Clock; }
273+
private:
274+
TInstant& Clock;
269275
};
270-
return MakeIntrusive<TTestActorTimeProvider>();
276+
return MakeIntrusive<TTestActorTimeProvider>(clock);
271277
}
272278

273279
TIntrusivePtr<IMonotonicTimeProvider> TTestActorSystem::CreateMonotonicTimeProvider() {

0 commit comments

Comments
 (0)