Skip to content

Commit dfd1e78

Browse files
committed
fix: resolve multi thread mkdir error
1 parent 3f03070 commit dfd1e78

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

src/paimon/common/fs/file_system_test.cpp

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -979,16 +979,21 @@ TEST_P(FileSystemTest, TestMkdirsFailsWithExistingParentFile) {
979979
}
980980

981981
TEST_P(FileSystemTest, TestMkdir) {
982-
std::string path = PathUtil::JoinPath(test_root_, "/tmp.txt/tmpB");
983-
ASSERT_OK(fs_->Mkdirs(path));
982+
{
983+
std::string path = PathUtil::JoinPath(test_root_, "/tmp.txt/tmpB");
984+
ASSERT_OK(fs_->Mkdirs(path));
985+
}
986+
{
987+
std::string path = PathUtil::JoinPath(test_root_, "/tmpA/tmpB/");
988+
ASSERT_OK(fs_->Mkdirs(path));
989+
}
990+
{
991+
std::string path = "/";
992+
ASSERT_OK(fs_->Mkdirs(path));
993+
}
984994
}
985995

986996
TEST_P(FileSystemTest, TestMkdir2) {
987-
std::string path = PathUtil::JoinPath(test_root_, "/tmpA/tmpB/");
988-
ASSERT_OK(fs_->Mkdirs(path));
989-
}
990-
991-
TEST_P(FileSystemTest, TestMkdir3) {
992997
{
993998
std::string dir_path = test_root_ + "/file_dir/";
994999
ASSERT_OK_AND_ASSIGN(bool is_exist, fs_->Exists(dir_path));
@@ -1012,6 +1017,7 @@ TEST_P(FileSystemTest, TestMkdir3) {
10121017
}
10131018
}
10141019

1020+
// test for create multi dir such as "partition1/bucket1" and "partition1/bucket2"
10151021
TEST_P(FileSystemTest, TestMkdirMultiThread) {
10161022
uint32_t runs_count = 10;
10171023
uint32_t thread_count = 10;
@@ -1036,6 +1042,30 @@ TEST_P(FileSystemTest, TestMkdirMultiThread) {
10361042
}
10371043
}
10381044

1045+
// test for create multi dir such as "partition1" and "partition1"
1046+
TEST_P(FileSystemTest, TestMkdirMultiThread2) {
1047+
uint32_t runs_count = 10;
1048+
uint32_t thread_count = 10;
1049+
auto executor = CreateDefaultExecutor(thread_count);
1050+
1051+
for (uint32_t i = 0; i < runs_count; i++) {
1052+
std::string uuid;
1053+
ASSERT_TRUE(UUID::Generate(&uuid));
1054+
std::vector<std::future<void>> futures;
1055+
for (uint32_t thread_idx = 0; thread_idx < thread_count; thread_idx++) {
1056+
futures.push_back(Via(executor.get(), [this, &uuid]() -> void {
1057+
std::string dir_path = PathUtil::JoinPath(test_root_, uuid);
1058+
// ASSERT_OK_AND_ASSIGN(bool is_exist, fs_->Exists(dir_path));
1059+
// ASSERT_FALSE(is_exist);
1060+
ASSERT_OK(fs_->Mkdirs(dir_path));
1061+
ASSERT_OK_AND_ASSIGN(bool is_exist, fs_->Exists(dir_path));
1062+
ASSERT_TRUE(is_exist);
1063+
}));
1064+
}
1065+
Wait(futures);
1066+
}
1067+
}
1068+
10391069
TEST_P(FileSystemTest, TestInvalidMkdir) {
10401070
{
10411071
// test mkdir with one exist dir

src/paimon/fs/local/local_file.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,6 @@ Status LocalFile::Mkdir() const {
163163
dir.resize(len - 1);
164164
}
165165
}
166-
if (access(dir.c_str(), F_OK) == 0) {
167-
return Status::Exist(fmt::format("directory '{}' already exist", dir));
168-
}
169166
size_t pos = dir.rfind('/');
170167
if (pos == std::string::npos) {
171168
if (mkdir(dir.c_str(), 0755) < 0) {
@@ -180,9 +177,11 @@ Status LocalFile::Mkdir() const {
180177
PAIMON_RETURN_NOT_OK(MkNestDir(parent_dir));
181178
}
182179
if (mkdir(dir.c_str(), 0755) < 0) {
183-
int32_t cur_errno = errno;
184-
return Status::IOError(
185-
fmt::format("create directory '{}' failed, ec: {}", dir, std::strerror(cur_errno)));
180+
if (errno != EEXIST) {
181+
int32_t cur_errno = errno;
182+
return Status::IOError(
183+
fmt::format("create directory '{}' failed, ec: {}", dir, std::strerror(cur_errno)));
184+
}
186185
}
187186
return Status::OK();
188187
}

0 commit comments

Comments
 (0)