refactored

This commit is contained in:
2024-05-01 04:12:05 +00:00
parent 6c20530cc8
commit ec920f7255
37 changed files with 79 additions and 57 deletions

View File

@ -83,14 +83,14 @@ set(ZSTD_BUILD_SHARED OFF CACHE BOOL "Build shared libraries")
set(ZSTD_BUILD_DEPRECATED OFF CACHE BOOL "Build deprecated module")
FetchContent_MakeAvailable(zstd)
include_directories(${CMAKE_SOURCE_DIR}/bpt/include)
include_directories(${CMAKE_SOURCE_DIR}/snapshot/include)
include_directories(${CMAKE_SOURCE_DIR}/storage/include)
include_directories(${CMAKE_SOURCE_DIR}/dataguard/include)
include_directories(${CMAKE_SOURCE_DIR}/stlite)
include(CTest)
enable_testing()
add_subdirectory(bpt)
add_subdirectory(snapshot)
add_subdirectory(storage)
add_subdirectory(dataguard)
add_subdirectory(test)
add_subdirectory(src)

View File

@ -1 +0,0 @@
add_library(bpt STATIC src/disk_manager.cpp src/replacer.cpp src/buffer_pool_manager.cpp src/bpt.cpp)

2
dataguard/CMakeLists.txt Normal file
View File

@ -0,0 +1,2 @@
add_library(dataguard STATIC src/snapshot.cpp src/txn_logger.cpp)
target_link_libraries(dataguard libzstd_static storage)

View File

@ -0,0 +1,2 @@
#include "dataguard/snapshot.h"
#include "dataguard/txn_logger.h"

View File

@ -0,0 +1,15 @@
#ifndef SNAP_SHOT_H
#define SNAP_SHOT_H
#include <string>
#include "map.hpp"
#include "vector.hpp"
class SnapShotManager {
public:
// For safety and simplicity, we delete all the copy/move constructor and copy/move assignment operator. Please
// manager it using smart pointer.
SnapShotManager(const SnapShotManager &) = delete;
SnapShotManager(SnapShotManager &&) = delete;
SnapShotManager &operator=(const SnapShotManager &) = delete;
SnapShotManager &operator=(SnapShotManager &&) = delete;
};
#endif // SNAP_SHOT_H

View File

@ -0,0 +1,4 @@
#ifndef TXN_LOGGER_H
#define TXN_LOGGER_H
#endif

View File

@ -0,0 +1,2 @@
#include "dataguard/snapshot.h"
#include <zstd.h>

View File

@ -0,0 +1 @@
#include "dataguard/txn_logger.h"

View File

@ -1,5 +1,5 @@
# 规划的Bonus实现方式
- 缓存LRU
- 缓存LRU-K
- 空间回收
- 快照贯通于数据库系统和火车票系统整体以文件为单位夹打快照类似于git在火车票系统后端处于非活动状态时操作比对stage区和版本库中的最后一次commit然后打一个新的commit进去额外消耗空间为 当前文件实际大小 + 压缩后的 当前文件实际大小+变化量使用zstd算法压缩。交互方式`./core-cli snapshot [options]`。而stage功能内置于DiskManager当收到信号后会把工作文件夹的变化打进stage区。
- 并发:内置于数据库系统,基于`std::shared_mutex`的简单并发,可以真正意义上支持读操作的并发,但写操作会独占数据库的控制权。(但火车票系统会直接在整个业务层面上加读写锁,因此不会直接使用数据库系统的并发安全)。

View File

@ -1,2 +0,0 @@
add_library(snapshot STATIC src/snapshot.cpp)
target_link_libraries(snapshot libzstd_static)

View File

@ -1,4 +0,0 @@
#ifndef SNAP_SHOT_H
#define SNAP_SHOT_H
#endif // SNAP_SHOT_H

View File

@ -1,2 +0,0 @@
#include "snapshot/snapshot.h"
#include <zstd.h>

View File

@ -7,4 +7,6 @@ add_executable(${BACKEND_EXETUABLE_NAME} main.cpp)
target_link_libraries(${BACKEND_EXETUABLE_NAME} argparse)
target_link_libraries(${BACKEND_EXETUABLE_NAME} spdlog::spdlog)
target_link_libraries(${BACKEND_EXETUABLE_NAME} sockpp)
target_link_libraries(${BACKEND_EXETUABLE_NAME} storage)
target_link_libraries(${BACKEND_EXETUABLE_NAME} dataguard)
set_target_properties(${BACKEND_EXETUABLE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

View File

@ -1,5 +1,7 @@
#include <sockpp/tcp_acceptor.h>
#include "basic_defs.h"
#include "storage/bpt.hpp"
#include "dataguard/dataguard.h"
const std::string main_version = "0.0.1";
const std::string build_version = GIT_COMMIT_HASH;
std::shared_ptr<spdlog::logger> logger_ptr;

1
storage/CMakeLists.txt Normal file
View File

@ -0,0 +1 @@
add_library(storage STATIC src/disk_manager.cpp src/replacer.cpp src/buffer_pool_manager.cpp src/bpt.cpp)

View File

@ -4,9 +4,9 @@
#include <cstring>
#include <shared_mutex>
#include "vector.hpp"
#include "bpt/bpt_page.hpp"
#include "bpt/buffer_pool_manager.h"
#include "bpt/config.h"
#include "storage/bpt_page.hpp"
#include "storage/buffer_pool_manager.h"
#include "storage/config.h"
/**
* @brief B+ Tree Indexer
* @warning The KeyType must can be stored byte by byte. As this is only the indexer, the type of value is always

View File

@ -1,7 +1,7 @@
#ifndef BPT_PAGE_HPP
#define BPT_PAGE_HPP
#include <utility>
#include "bpt/config.h"
#include "storage/config.h"
template <typename KeyType, size_t kPageSize = 4096>
struct ActualDataType {
typedef std::pair<KeyType, default_numeric_index_t> value_type;

View File

@ -6,9 +6,9 @@
#include <shared_mutex>
#include "map.hpp"
#include "list.hpp"
#include "bpt/config.h"
#include "bpt/disk_manager.h"
#include "bpt/replacer.h"
#include "storage/config.h"
#include "storage/disk_manager.h"
#include "storage/replacer.h"
class BufferPoolManager;
class Page {
public:

View File

@ -2,7 +2,7 @@
#define DISK_MANAGER_H
#include <cstdio>
#include <string>
#include "bpt/config.h"
#include "storage/config.h"
class DiskManager {
/**
* The Data Structure on Disk:

View File

@ -2,7 +2,7 @@
#define REPLACER_H
#include <cstddef>
#include <mutex>
#include "bpt/config.h"
#include "storage/config.h"
class LRUKReplacer {
public:
LRUKReplacer() = delete;

View File

@ -1,4 +1,4 @@
#include "bpt/bpt.hpp"
#include "bpt/config.h"
#include "storage/bpt.hpp"
#include "storage/config.h"
const b_plus_tree_value_index_t kInvalidValueIndex = -1;
const default_numeric_index_t kInvalidNumericIndex = -1;

View File

@ -1,7 +1,7 @@
#include "bpt/buffer_pool_manager.h"
#include "storage/buffer_pool_manager.h"
#include <cstring>
#include <mutex>
#include "bpt/config.h"
#include "storage/config.h"
Page::Page() : mem(new char[kPageSize]) {}
Page::~Page() { delete[] mem; }
void Page::ResetMemory() { memset(mem, 0, kPageSize); }

View File

@ -1,4 +1,4 @@
#include "bpt/disk_manager.h"
#include "storage/disk_manager.h"
#include <cstring>
#include <exception>
#include <stdexcept>

View File

@ -1,4 +1,4 @@
#include "bpt/replacer.h"
#include "storage/replacer.h"
#include <cstddef>
LRUKReplacer::LRUKReplacer(size_t max_frame_count, size_t k_value)
: max_frame_count(max_frame_count), k_value(k_value) {

View File

@ -1,21 +1,21 @@
if(OJ_TEST_BPT)
add_executable(code oj_test_interface_for_bpt.cpp)
target_link_libraries(code bpt)
target_link_libraries(code storage)
set_target_properties(code PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
add_executable(replacer_test replacer_test.cpp)
target_link_libraries(replacer_test bpt GTest::gtest_main)
target_link_libraries(replacer_test storage GTest::gtest_main)
add_executable(buffer_pool_manager_test buffer_pool_manager_test.cpp)
target_link_libraries(buffer_pool_manager_test bpt GTest::gtest_main spdlog::spdlog)
target_link_libraries(buffer_pool_manager_test storage GTest::gtest_main spdlog::spdlog)
add_executable(page_guard_test page_guard_test.cpp)
target_link_libraries(page_guard_test bpt GTest::gtest_main)
target_link_libraries(page_guard_test storage GTest::gtest_main)
add_executable(bpt_basic_test bpt_basic_test.cpp)
target_link_libraries(bpt_basic_test bpt GTest::gtest_main spdlog::spdlog)
target_link_libraries(bpt_basic_test storage GTest::gtest_main spdlog::spdlog)
add_executable(buffer_pool_manager_extreme_test buffer_pool_manager_extreme_test.cpp)
target_link_libraries(buffer_pool_manager_extreme_test bpt)
target_link_libraries(buffer_pool_manager_extreme_test storage)
add_executable(t1_std t1_std.cpp)
set_target_properties(t1_std PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
add_executable(t1_mk t1_mk.cpp)
set_target_properties(t1_mk PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
add_executable(bpt_advanced_test bpt_advanced_test.cpp)
target_link_libraries(bpt_advanced_test bpt GTest::gtest_main spdlog::spdlog)
target_link_libraries(bpt_advanced_test storage GTest::gtest_main spdlog::spdlog)

View File

@ -1,8 +1,8 @@
#include <cstddef>
#include <cstring>
#include "bpt/buffer_pool_manager.h"
#include "bpt/config.h"
#include "bpt/disk_manager.h"
#include "storage/buffer_pool_manager.h"
#include "storage/config.h"
#include "storage/disk_manager.h"
#ifndef BPT_MEMORYRIVER_HPP
#define BPT_MEMORYRIVER_HPP

View File

@ -5,10 +5,10 @@
#include <spdlog/spdlog.h>
#include <map>
#include <random>
#include "bpt/bpt.hpp"
#include "bpt/buffer_pool_manager.h"
#include "bpt/config.h"
#include "bpt/disk_manager.h"
#include "storage/bpt.hpp"
#include "storage/buffer_pool_manager.h"
#include "storage/config.h"
#include "storage/disk_manager.h"
namespace bpt_advanced_test {
template <size_t length>
class FixLengthString {

View File

@ -5,10 +5,10 @@
#include <spdlog/spdlog.h>
#include <map>
#include <random>
#include "bpt/bpt.hpp"
#include "bpt/buffer_pool_manager.h"
#include "bpt/config.h"
#include "bpt/disk_manager.h"
#include "storage/bpt.hpp"
#include "storage/buffer_pool_manager.h"
#include "storage/config.h"
#include "storage/disk_manager.h"
namespace bpt_basic_test {
template <size_t length>
class FixLengthString {

View File

@ -1,4 +1,4 @@
#include "bpt/buffer_pool_manager.h"
#include "storage/buffer_pool_manager.h"
#include <gtest/gtest.h>
#include <spdlog/async.h>
#include <spdlog/sinks/basic_file_sink.h>
@ -14,9 +14,9 @@
#include <vector>
#include "MemoryRiver.hpp"
#include "MemoryRiverStd.hpp"
#include "bpt/bpt_page.hpp"
#include "bpt/config.h"
#include "bpt/disk_manager.h"
#include "storage/bpt_page.hpp"
#include "storage/config.h"
#include "storage/disk_manager.h"
// Demonstrate some basic assertions.
TEST(HelloTest, BasicAssertions) {
// Expect two strings not to be equal.

View File

@ -3,8 +3,8 @@
#include <ios>
#include <iostream>
#include <string>
#include "bpt/bpt.hpp"
#include "bpt/buffer_pool_manager.h"
#include "storage/bpt.hpp"
#include "storage/buffer_pool_manager.h"
typedef uint64_t hash_t;
inline hash_t Hash(std::string str) noexcept {
constexpr static char salt1[10] = "mL;]-=eT";

View File

@ -4,8 +4,8 @@
#include <memory>
#include <random>
#include <string>
#include "bpt/buffer_pool_manager.h"
#include "bpt/config.h"
#include "storage/buffer_pool_manager.h"
#include "storage/config.h"
TEST(PageGuardTest, SampleTest) {
const std::string db_name = "/tmp/test.db";

View File

@ -1,6 +1,6 @@
#include "bpt/replacer.h"
#include "storage/replacer.h"
#include <gtest/gtest.h>
#include "bpt/config.h"
#include "storage/config.h"
// Demonstrate some basic assertions.
TEST(HelloTest, BasicAssertions) {
// Expect two strings not to be equal.