Skip to content

[Bug]: Race condition between optimize and checkpoint causes infinity crash #3325

@zpf121

Description

@zpf121

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Version or Commit ID

0.7.0

Other environment information

Actual behavior and How to reproduce it

Description

Running optimize and checkpoint simultaneously can cause the database to crash with an UnrecoverableError.

Error Log

[20:44:24.615] [1856579] [critical] UnrecoverableError: Invalid buffer type: ToMmap
   0# infinity::PrintStacktrace at /home/weilongma/zpf/infinity/src/common/utility/exception_impl.cpp:47
   1# infinity::UnrecoverableError at /home/weilongma/zpf/infinity/src/common/utility/exception_impl.cpp:81
   2# infinity::BufferObj::ToMmap at /home/weilongma/zpf/infinity/src/storage/buffer/buffer_obj_impl.cpp:386
   3# infinity::NewTxn::TryToMmap at /home/weilongma/zpf/infinity/src/storage/new_txn/new_txn_data_impl.cpp:2142
   4# infinity::NewTxn::CheckpointTable at /home/weilongma/zpf/infinity/src/storage/new_txn/new_txn_data_impl.cpp:1396
   5# infinity::NewTxn::CheckpointDB at /home/weilongma/zpf/infinity/src/storage/new_txn/new_txn_impl.cpp:1889
   6# infinity::NewTxn::Checkpoint at /home/weilongma/zpf/infinity/src/storage/new_txn/new_txn_impl.cpp:1802
   7# infinity::NewCheckpointTask::ExecuteWithNewTxn at /home/weilongma/zpf/infinity/src/storage/bg_task/bg_task_impl.cpp:54
   8# infinity::BGTaskProcessor::Process at /home/weilongma/zpf/infinity/src/storage/bg_task/background_process_impl.cpp:93

Root Cause

This is a race condition between optimize and checkpoint operations:

  1. Optimize operation may set buffer type to kToMmap during the dump process.

  2. Checkpoint operation attempts to call BufferObj::ToMmap().

  3. BufferObj

    if (type_ != BufferType::kPersistent) {
        UnrecoverableError(fmt::format("Invalid buffer type: {}", BufferTypeToString(type_)));
    }

Reproduce

In TestMultipleIndexTypesImport, set:
pytest.param("test/data/config/restart_test/test_insert/3.toml", MultiIndexTypesGenerator, 5, 10, 120, marks=pytest.mark.slow)

uv run python3 tools/run_restart_test.py --infinity_path=cmake-build-release/src/infinity --marker=slow --test_case=test_multiple_index_types_import.py 2>&1 | tee /tmp/123456.log

Expected behavior

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions