Skip to content

Commit bad5730

Browse files
authored
Try to lsof, when fail to lock file (#11393)
1 parent 9268875 commit bad5730

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

ydb/tools/stress_tool/device_test_tool_aio_test.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <util/system/hp_timer.h>
2020
#include <util/system/mutex.h>
2121

22+
#include <cstdlib>
23+
2224
#include "device_test_tool.h"
2325

2426
#if defined(_tsan_enabled_)
@@ -219,8 +221,20 @@ class TAioTest : public TPerfTest {
219221
DetectFileParameters(Cfg.Path, DeviceSizeBytes, isBlockDevice);
220222

221223
NPDisk::EIoResult res = IoContext->Setup(MaxEvents, Cfg.DoLockFile);
222-
Y_VERIFY_S(res == NPDisk::EIoResult::Ok, "Error initializing IoContext, error# " << res
223-
<< "; path# " << Cfg.Path.Quote());
224+
if (res != NPDisk::EIoResult::Ok) {
225+
if (res == NPDisk::EIoResult::FileLockError) {
226+
// find out the reason of the lock error
227+
TString lsofCommand = "lsof " + Cfg.Path;
228+
int returnCode = system(lsofCommand.c_str());
229+
if (returnCode == 0) {
230+
Y_FAIL_S("File is locked by another process, see lsof output above");
231+
} else {
232+
Y_FAIL_S("Error in IoContext->Setup, error# " << res);
233+
}
234+
}
235+
Y_VERIFY_S(res == NPDisk::EIoResult::Ok, "Error initializing IoContext, error# " << res
236+
<< "; path# " << Cfg.Path.Quote());
237+
}
224238

225239
THolder<TFileHandle> file(new TFileHandle(Cfg.Path.c_str(), OpenExisting | RdWr | DirectAligned | Sync));
226240

0 commit comments

Comments
 (0)