Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB::CompressionCodecFactory::getStaticCodec(const CompressionSetting &): Assertion `inserted' failed #9336

Closed
JinheLin opened this issue Aug 20, 2024 · 2 comments · Fixed by #9312 or #9342
Assignees
Labels

Comments

@JinheLin
Copy link
Contributor

Error

gtests_dbms: /home/jenkins/agent/workspace/tiflash-build-common/tiflash/dbms/src/IO/Compression/CompressionCodecFactory.cpp:97: static CompressionCodecPtr DB::CompressionCodecFactory::getStaticCodec(const CompressionSetting &): Assertion `inserted' failed.

template <>
CompressionCodecPtr CompressionCodecFactory::getStaticCodec<CompressionCodecLZ4>(const CompressionSetting & setting)
{
static constexpr auto MAX_LZ4_MAP_SIZE = 10;
static std::shared_mutex lz4_mutex;
static std::unordered_map<int, CompressionCodecPtr> lz4_map(MAX_LZ4_MAP_SIZE);
{
std::shared_lock lock(lz4_mutex);
auto it = lz4_map.find(setting.level);
if (it != lz4_map.end())
return it->second;
}
std::unique_lock lock(lz4_mutex);
if (lz4_map.size() >= MAX_LZ4_MAP_SIZE)
lz4_map.clear();
auto [it, inserted] = lz4_map.emplace(setting.level, std::make_shared<CompressionCodecLZ4>(setting.level));
assert(inserted);
return it->second;
}

  1. Two threads with the same level acquire shared lock of lz4_mutex and read lz4_map concurrently and both failed because codec of level not exist.
  2. Thread1 acquire unique lock of lz4_mutex, insert codec of level and assert(inserted) successfully.
  3. Thread2 acquire unique lock of lz4_mutex, but insert codec of level failed, and assert(inserted) will crash the process in debug mode.
@JinheLin JinheLin added type/bug The issue is confirmed as a bug. component/storage severity/moderate labels Aug 20, 2024
@JinheLin
Copy link
Contributor Author

Seems the level of compression is determined by dt_compression_level:

M(SettingInt64, dt_compression_level, 1, "The compression level.") \

Can we just create a static object when the server start? @Lloyd-Pottiger

@Lloyd-Pottiger
Copy link
Contributor

I have fixed this in #9312.

Can we just create a static object when the server start? @Lloyd-Pottiger

No, dt_compression_level needs to be dynamically changeable.

@Lloyd-Pottiger Lloyd-Pottiger self-assigned this Aug 22, 2024
@ti-chi-bot ti-chi-bot bot closed this as completed in d68865a Aug 22, 2024
ti-chi-bot bot pushed a commit that referenced this issue Sep 6, 2024
close #8982, close #9336

Compression: Support enabling lightweight compression

Signed-off-by: Lloyd-Pottiger <[email protected]>

Co-authored-by: jinhelin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants