Skip to content

Conversation

@manishym
Copy link
Owner

No description provided.

@github-actions
Copy link

Unit tests passed.

📊 Coverage Summary:

src/storage/stdmap_memtable.h             | 100%      2| 0.0%     2|    -      0
src/utils/file_buffer_writer.cpp          |50.0%     16| 0.0%     7|    -      0
src/utils/i_writable_buffer.h             | 200%      1| 0.0%     1|    -      0
src/wal/block_device_wal.h                |21.8%     55| 0.0%     8|    -      0
src/wal/interface.h                       | 200%      1| 0.0%     1|    -      0
src/wal/passthrough_wal.h                 | 100%      7| 0.0%     7|    -      0
src/wal/wal_entry_serializer.h            |12.1%     33| 0.0%     4|    -      0
src/wal/wal_factory.h                     | 7.1%     14| 0.0%     1|    -      0
src/wal/wal_serializer.cpp                |15.4%     13| 0.0%     1|    -      0
tests/unit/block_device_wal_test.cpp      |18.5%     65| 0.0%    12|    -      0
tests/unit/block_lsm_tree_test.cpp        |21.1%     19| 0.0%     4|    -      0
tests/unit/file_buffer_writer_test.cpp    |50.8%     59| 0.0%    30|    -      0
tests/unit/map_test.cpp                   |31.1%    132| 0.0%    41|    -      0
tests/unit/memtable_test.cpp              |33.3%     36| 0.0%    12|    -      0
tests/unit/passthrough_wal_test.cpp       |84.8%     33| 0.0%    28|    -      0
tests/unit/server_test.cpp                |21.6%     37| 0.0%     8|    -      0
tests/unit/wal_factory_test.cpp           |70.6%     17| 0.0%    12|    -      0
tests/unit/wal_serializer_test.cpp        |49.3%     73| 0.0%    36|    -      0
================================================================================
                                    Total:|32.8%    892| 0.0%   273|    -      0

@manishym manishym requested a review from Copilot July 20, 2025 05:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces LSM Tree support to the key-value store system. The implementation provides a block-based LSM Tree structure with automatic memtable flushing to persistent SST files on disk when size thresholds are reached.

  • Adds BlockLSMTree class with put/get/delete operations and automatic memtable flushing
  • Implements SST file persistence using WAL entry serialization format
  • Integrates LSM configuration into the runtime configuration system

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/storage/block_lsm_tree.h Defines the BlockLSMTree class interface with memtable and SST file management
src/storage/block_lsm_tree.cpp Implements LSM tree operations, memtable flushing, and SST file search functionality
tests/unit/block_lsm_tree_test.cpp Adds unit test for flush-on-threshold behavior and file verification
src/config/runtime_config.json Adds LSM configuration section with memtable size and directory settings
CMakeLists.txt Integrates new source and test files into build system
Comments suppressed due to low confidence (1)

tests/unit/block_lsm_tree_test.cpp:21

  • Test does not verify cleanup failure scenarios. If rmdir or std::remove fail, subsequent test runs may be affected by leftover files.
    ASSERT_EQ(stat("lsm_test/sst_0.sst", &st), 0);

Comment on lines +52 to +53
if (fd < 0)
return;
Copy link

Copilot AI Jul 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File descriptor is not checked for error before use. If open() fails, fd will be negative but the code continues to use it in subsequent operations.

Suggested change
if (fd < 0)
return;
if (fd < 0) {
std::cerr << "Error opening file '" << path << "': " << std::strerror(errno) << std::endl;
return;
}

Copilot uses AI. Check for mistakes.
return;
std::string path = dir_ + "/sst_" + std::to_string(next_file_id_++) + ".sst";
int fd = ::open(path.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0666);
if (fd < 0)
Copy link

Copilot AI Jul 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Early return on file open failure leaves the SST file path untracked, but memtable data is lost. This could cause data loss as the memtable should only be cleared after successful flush.

Copilot uses AI. Check for mistakes.
entry = {WalOpType::DELETE, kv.first, ""};
}
auto buf = WalEntrySerializer::serialize(entry);
if (!writeAll(fd, buf.data(), buf.size())) {
Copy link

Copilot AI Jul 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When writeAll fails, the function breaks out of the loop but still adds the partially written file to sst_files_ and clears the memtable, potentially causing data loss.

Copilot uses AI. Check for mistakes.
}
uint32_t klen, vlen;
std::memcpy(&klen, header+1, sizeof(uint32_t));
std::memcpy(&vlen, header+1+sizeof(uint32_t), sizeof(uint32_t));
Copy link

Copilot AI Jul 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No validation of klen and vlen values read from file. Malformed or malicious SST files could cause excessive memory allocation or integer overflow.

Suggested change
std::memcpy(&vlen, header+1+sizeof(uint32_t), sizeof(uint32_t));
std::memcpy(&vlen, header+1+sizeof(uint32_t), sizeof(uint32_t));
if (klen > MAX_KEY_LENGTH || vlen > MAX_VALUE_LENGTH) {
::close(fd);
return false;
}

Copilot uses AI. Check for mistakes.
Comment on lines +77 to +78
uint8_t header[1 + sizeof(uint32_t)*2];
ssize_t r = ::read(fd, header, sizeof(header));
Copy link

Copilot AI Jul 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Magic number for header size calculation. Consider defining a constant like HEADER_SIZE to make the code more readable and maintainable.

Suggested change
uint8_t header[1 + sizeof(uint32_t)*2];
ssize_t r = ::read(fd, header, sizeof(header));
uint8_t header[HEADER_SIZE];
ssize_t r = ::read(fd, header, HEADER_SIZE);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant