Skip to content

Commit 3f03070

Browse files
authored
fix: prevent glog crash on concurrent initialization (#6)
* fix: prevent glog crash on concurrent initialization
1 parent b4e2c1c commit 3f03070

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/paimon/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ if(PAIMON_BUILD_TESTS)
335335
common/io/buffered_input_stream_test.cpp
336336
common/io/memory_segment_output_stream_test.cpp
337337
common/io/offset_input_stream_test.cpp
338+
common/logging/logging_test.cpp
338339
common/metrics/metrics_impl_test.cpp
339340
common/options/memory_size_test.cpp
340341
common/options/time_duration_test.cpp

src/paimon/common/logging/logging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ std::unique_ptr<Logger> Logger::GetLogger(const std::string& path) {
8181
std::shared_lock<std::shared_mutex> lock(getRegistryLock());
8282
return creator.value()(path);
8383
}
84-
84+
std::unique_lock<std::shared_mutex> ulock(getRegistryLock());
8585
if (!google::IsGoogleLoggingInitialized()) {
8686
google::InitGoogleLogging(program_invocation_name);
8787
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2025-present Alibaba Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "paimon/logging.h"
17+
18+
#include <future>
19+
#include <random>
20+
#include <thread>
21+
22+
#include "paimon/common/executor/future.h"
23+
#include "paimon/executor.h"
24+
#include "paimon/testing/utils/testharness.h"
25+
namespace paimon::test {
26+
TEST(LoggerTest, TestMultiThreadGetLogger) {
27+
auto executor = CreateDefaultExecutor(/*thread_count=*/4);
28+
auto get_logger = []() {
29+
auto logger = Logger::GetLogger("my_log");
30+
ASSERT_TRUE(logger);
31+
};
32+
33+
std::vector<std::future<void>> futures;
34+
for (int i = 0; i < 1000; ++i) {
35+
futures.push_back(Via(executor.get(), get_logger));
36+
}
37+
Wait(futures);
38+
}
39+
} // namespace paimon::test

0 commit comments

Comments
 (0)