refactored
This commit is contained in:
@ -83,14 +83,14 @@ set(ZSTD_BUILD_SHARED OFF CACHE BOOL "Build shared libraries")
|
|||||||
set(ZSTD_BUILD_DEPRECATED OFF CACHE BOOL "Build deprecated module")
|
set(ZSTD_BUILD_DEPRECATED OFF CACHE BOOL "Build deprecated module")
|
||||||
FetchContent_MakeAvailable(zstd)
|
FetchContent_MakeAvailable(zstd)
|
||||||
|
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/bpt/include)
|
include_directories(${CMAKE_SOURCE_DIR}/storage/include)
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/snapshot/include)
|
include_directories(${CMAKE_SOURCE_DIR}/dataguard/include)
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/stlite)
|
include_directories(${CMAKE_SOURCE_DIR}/stlite)
|
||||||
|
|
||||||
include(CTest)
|
include(CTest)
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
add_subdirectory(bpt)
|
add_subdirectory(storage)
|
||||||
add_subdirectory(snapshot)
|
add_subdirectory(dataguard)
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
@ -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
2
dataguard/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
add_library(dataguard STATIC src/snapshot.cpp src/txn_logger.cpp)
|
||||||
|
target_link_libraries(dataguard libzstd_static storage)
|
2
dataguard/include/dataguard/dataguard.h
Normal file
2
dataguard/include/dataguard/dataguard.h
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#include "dataguard/snapshot.h"
|
||||||
|
#include "dataguard/txn_logger.h"
|
15
dataguard/include/dataguard/snapshot.h
Normal file
15
dataguard/include/dataguard/snapshot.h
Normal 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
|
4
dataguard/include/dataguard/txn_logger.h
Normal file
4
dataguard/include/dataguard/txn_logger.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#ifndef TXN_LOGGER_H
|
||||||
|
#define TXN_LOGGER_H
|
||||||
|
|
||||||
|
#endif
|
2
dataguard/src/snapshot.cpp
Normal file
2
dataguard/src/snapshot.cpp
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#include "dataguard/snapshot.h"
|
||||||
|
#include <zstd.h>
|
1
dataguard/src/txn_logger.cpp
Normal file
1
dataguard/src/txn_logger.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "dataguard/txn_logger.h"
|
@ -1,5 +1,5 @@
|
|||||||
# 规划的Bonus实现方式
|
# 规划的Bonus实现方式
|
||||||
- 缓存:LRU
|
- 缓存:LRU-K
|
||||||
- 空间回收
|
- 空间回收
|
||||||
- 快照:贯通于数据库系统和火车票系统整体,以文件为单位夹打快照(类似于git,在火车票系统后端处于非活动状态时操作,比对stage区和版本库中的最后一次commit,然后打一个新的commit进去),额外消耗空间为 当前文件实际大小 + 压缩后的 当前文件实际大小+变化量,使用zstd算法压缩。交互方式:`./core-cli snapshot [options]`。而stage功能内置于DiskManager,当收到信号后,会把工作文件夹的变化打进stage区。
|
- 快照:贯通于数据库系统和火车票系统整体,以文件为单位夹打快照(类似于git,在火车票系统后端处于非活动状态时操作,比对stage区和版本库中的最后一次commit,然后打一个新的commit进去),额外消耗空间为 当前文件实际大小 + 压缩后的 当前文件实际大小+变化量,使用zstd算法压缩。交互方式:`./core-cli snapshot [options]`。而stage功能内置于DiskManager,当收到信号后,会把工作文件夹的变化打进stage区。
|
||||||
- 并发:内置于数据库系统,基于`std::shared_mutex`的简单并发,可以真正意义上支持读操作的并发,但写操作会独占数据库的控制权。(但火车票系统会直接在整个业务层面上加读写锁,因此不会直接使用数据库系统的并发安全)。
|
- 并发:内置于数据库系统,基于`std::shared_mutex`的简单并发,可以真正意义上支持读操作的并发,但写操作会独占数据库的控制权。(但火车票系统会直接在整个业务层面上加读写锁,因此不会直接使用数据库系统的并发安全)。
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
add_library(snapshot STATIC src/snapshot.cpp)
|
|
||||||
target_link_libraries(snapshot libzstd_static)
|
|
@ -1,4 +0,0 @@
|
|||||||
#ifndef SNAP_SHOT_H
|
|
||||||
#define SNAP_SHOT_H
|
|
||||||
|
|
||||||
#endif // SNAP_SHOT_H
|
|
@ -1,2 +0,0 @@
|
|||||||
#include "snapshot/snapshot.h"
|
|
||||||
#include <zstd.h>
|
|
@ -7,4 +7,6 @@ add_executable(${BACKEND_EXETUABLE_NAME} main.cpp)
|
|||||||
target_link_libraries(${BACKEND_EXETUABLE_NAME} argparse)
|
target_link_libraries(${BACKEND_EXETUABLE_NAME} argparse)
|
||||||
target_link_libraries(${BACKEND_EXETUABLE_NAME} spdlog::spdlog)
|
target_link_libraries(${BACKEND_EXETUABLE_NAME} spdlog::spdlog)
|
||||||
target_link_libraries(${BACKEND_EXETUABLE_NAME} sockpp)
|
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})
|
set_target_properties(${BACKEND_EXETUABLE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
@ -1,5 +1,7 @@
|
|||||||
#include <sockpp/tcp_acceptor.h>
|
#include <sockpp/tcp_acceptor.h>
|
||||||
#include "basic_defs.h"
|
#include "basic_defs.h"
|
||||||
|
#include "storage/bpt.hpp"
|
||||||
|
#include "dataguard/dataguard.h"
|
||||||
const std::string main_version = "0.0.1";
|
const std::string main_version = "0.0.1";
|
||||||
const std::string build_version = GIT_COMMIT_HASH;
|
const std::string build_version = GIT_COMMIT_HASH;
|
||||||
std::shared_ptr<spdlog::logger> logger_ptr;
|
std::shared_ptr<spdlog::logger> logger_ptr;
|
||||||
|
1
storage/CMakeLists.txt
Normal file
1
storage/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
add_library(storage STATIC src/disk_manager.cpp src/replacer.cpp src/buffer_pool_manager.cpp src/bpt.cpp)
|
@ -4,9 +4,9 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
#include "vector.hpp"
|
#include "vector.hpp"
|
||||||
#include "bpt/bpt_page.hpp"
|
#include "storage/bpt_page.hpp"
|
||||||
#include "bpt/buffer_pool_manager.h"
|
#include "storage/buffer_pool_manager.h"
|
||||||
#include "bpt/config.h"
|
#include "storage/config.h"
|
||||||
/**
|
/**
|
||||||
* @brief B+ Tree Indexer
|
* @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
|
* @warning The KeyType must can be stored byte by byte. As this is only the indexer, the type of value is always
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef BPT_PAGE_HPP
|
#ifndef BPT_PAGE_HPP
|
||||||
#define BPT_PAGE_HPP
|
#define BPT_PAGE_HPP
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "bpt/config.h"
|
#include "storage/config.h"
|
||||||
template <typename KeyType, size_t kPageSize = 4096>
|
template <typename KeyType, size_t kPageSize = 4096>
|
||||||
struct ActualDataType {
|
struct ActualDataType {
|
||||||
typedef std::pair<KeyType, default_numeric_index_t> value_type;
|
typedef std::pair<KeyType, default_numeric_index_t> value_type;
|
@ -6,9 +6,9 @@
|
|||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
#include "map.hpp"
|
#include "map.hpp"
|
||||||
#include "list.hpp"
|
#include "list.hpp"
|
||||||
#include "bpt/config.h"
|
#include "storage/config.h"
|
||||||
#include "bpt/disk_manager.h"
|
#include "storage/disk_manager.h"
|
||||||
#include "bpt/replacer.h"
|
#include "storage/replacer.h"
|
||||||
class BufferPoolManager;
|
class BufferPoolManager;
|
||||||
class Page {
|
class Page {
|
||||||
public:
|
public:
|
@ -2,7 +2,7 @@
|
|||||||
#define DISK_MANAGER_H
|
#define DISK_MANAGER_H
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "bpt/config.h"
|
#include "storage/config.h"
|
||||||
class DiskManager {
|
class DiskManager {
|
||||||
/**
|
/**
|
||||||
* The Data Structure on Disk:
|
* The Data Structure on Disk:
|
@ -2,7 +2,7 @@
|
|||||||
#define REPLACER_H
|
#define REPLACER_H
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include "bpt/config.h"
|
#include "storage/config.h"
|
||||||
class LRUKReplacer {
|
class LRUKReplacer {
|
||||||
public:
|
public:
|
||||||
LRUKReplacer() = delete;
|
LRUKReplacer() = delete;
|
@ -1,4 +1,4 @@
|
|||||||
#include "bpt/bpt.hpp"
|
#include "storage/bpt.hpp"
|
||||||
#include "bpt/config.h"
|
#include "storage/config.h"
|
||||||
const b_plus_tree_value_index_t kInvalidValueIndex = -1;
|
const b_plus_tree_value_index_t kInvalidValueIndex = -1;
|
||||||
const default_numeric_index_t kInvalidNumericIndex = -1;
|
const default_numeric_index_t kInvalidNumericIndex = -1;
|
@ -1,7 +1,7 @@
|
|||||||
#include "bpt/buffer_pool_manager.h"
|
#include "storage/buffer_pool_manager.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include "bpt/config.h"
|
#include "storage/config.h"
|
||||||
Page::Page() : mem(new char[kPageSize]) {}
|
Page::Page() : mem(new char[kPageSize]) {}
|
||||||
Page::~Page() { delete[] mem; }
|
Page::~Page() { delete[] mem; }
|
||||||
void Page::ResetMemory() { memset(mem, 0, kPageSize); }
|
void Page::ResetMemory() { memset(mem, 0, kPageSize); }
|
@ -1,4 +1,4 @@
|
|||||||
#include "bpt/disk_manager.h"
|
#include "storage/disk_manager.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
@ -1,4 +1,4 @@
|
|||||||
#include "bpt/replacer.h"
|
#include "storage/replacer.h"
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
LRUKReplacer::LRUKReplacer(size_t max_frame_count, size_t k_value)
|
LRUKReplacer::LRUKReplacer(size_t max_frame_count, size_t k_value)
|
||||||
: max_frame_count(max_frame_count), k_value(k_value) {
|
: max_frame_count(max_frame_count), k_value(k_value) {
|
@ -1,21 +1,21 @@
|
|||||||
if(OJ_TEST_BPT)
|
if(OJ_TEST_BPT)
|
||||||
add_executable(code oj_test_interface_for_bpt.cpp)
|
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})
|
set_target_properties(code PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||||
endif()
|
endif()
|
||||||
add_executable(replacer_test replacer_test.cpp)
|
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)
|
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)
|
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)
|
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)
|
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)
|
add_executable(t1_std t1_std.cpp)
|
||||||
set_target_properties(t1_std PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
set_target_properties(t1_std PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||||
add_executable(t1_mk t1_mk.cpp)
|
add_executable(t1_mk t1_mk.cpp)
|
||||||
set_target_properties(t1_mk PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
set_target_properties(t1_mk PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||||
add_executable(bpt_advanced_test bpt_advanced_test.cpp)
|
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)
|
@ -1,8 +1,8 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "bpt/buffer_pool_manager.h"
|
#include "storage/buffer_pool_manager.h"
|
||||||
#include "bpt/config.h"
|
#include "storage/config.h"
|
||||||
#include "bpt/disk_manager.h"
|
#include "storage/disk_manager.h"
|
||||||
#ifndef BPT_MEMORYRIVER_HPP
|
#ifndef BPT_MEMORYRIVER_HPP
|
||||||
#define BPT_MEMORYRIVER_HPP
|
#define BPT_MEMORYRIVER_HPP
|
||||||
|
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include "bpt/bpt.hpp"
|
#include "storage/bpt.hpp"
|
||||||
#include "bpt/buffer_pool_manager.h"
|
#include "storage/buffer_pool_manager.h"
|
||||||
#include "bpt/config.h"
|
#include "storage/config.h"
|
||||||
#include "bpt/disk_manager.h"
|
#include "storage/disk_manager.h"
|
||||||
namespace bpt_advanced_test {
|
namespace bpt_advanced_test {
|
||||||
template <size_t length>
|
template <size_t length>
|
||||||
class FixLengthString {
|
class FixLengthString {
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include "bpt/bpt.hpp"
|
#include "storage/bpt.hpp"
|
||||||
#include "bpt/buffer_pool_manager.h"
|
#include "storage/buffer_pool_manager.h"
|
||||||
#include "bpt/config.h"
|
#include "storage/config.h"
|
||||||
#include "bpt/disk_manager.h"
|
#include "storage/disk_manager.h"
|
||||||
namespace bpt_basic_test {
|
namespace bpt_basic_test {
|
||||||
template <size_t length>
|
template <size_t length>
|
||||||
class FixLengthString {
|
class FixLengthString {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "bpt/buffer_pool_manager.h"
|
#include "storage/buffer_pool_manager.h"
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <spdlog/async.h>
|
#include <spdlog/async.h>
|
||||||
#include <spdlog/sinks/basic_file_sink.h>
|
#include <spdlog/sinks/basic_file_sink.h>
|
||||||
@ -14,9 +14,9 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "MemoryRiver.hpp"
|
#include "MemoryRiver.hpp"
|
||||||
#include "MemoryRiverStd.hpp"
|
#include "MemoryRiverStd.hpp"
|
||||||
#include "bpt/bpt_page.hpp"
|
#include "storage/bpt_page.hpp"
|
||||||
#include "bpt/config.h"
|
#include "storage/config.h"
|
||||||
#include "bpt/disk_manager.h"
|
#include "storage/disk_manager.h"
|
||||||
// Demonstrate some basic assertions.
|
// Demonstrate some basic assertions.
|
||||||
TEST(HelloTest, BasicAssertions) {
|
TEST(HelloTest, BasicAssertions) {
|
||||||
// Expect two strings not to be equal.
|
// Expect two strings not to be equal.
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
#include <ios>
|
#include <ios>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "bpt/bpt.hpp"
|
#include "storage/bpt.hpp"
|
||||||
#include "bpt/buffer_pool_manager.h"
|
#include "storage/buffer_pool_manager.h"
|
||||||
typedef uint64_t hash_t;
|
typedef uint64_t hash_t;
|
||||||
inline hash_t Hash(std::string str) noexcept {
|
inline hash_t Hash(std::string str) noexcept {
|
||||||
constexpr static char salt1[10] = "mL;]-=eT";
|
constexpr static char salt1[10] = "mL;]-=eT";
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "bpt/buffer_pool_manager.h"
|
#include "storage/buffer_pool_manager.h"
|
||||||
#include "bpt/config.h"
|
#include "storage/config.h"
|
||||||
|
|
||||||
TEST(PageGuardTest, SampleTest) {
|
TEST(PageGuardTest, SampleTest) {
|
||||||
const std::string db_name = "/tmp/test.db";
|
const std::string db_name = "/tmp/test.db";
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "bpt/replacer.h"
|
#include "storage/replacer.h"
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include "bpt/config.h"
|
#include "storage/config.h"
|
||||||
// Demonstrate some basic assertions.
|
// Demonstrate some basic assertions.
|
||||||
TEST(HelloTest, BasicAssertions) {
|
TEST(HelloTest, BasicAssertions) {
|
||||||
// Expect two strings not to be equal.
|
// Expect two strings not to be equal.
|
||||||
|
Reference in New Issue
Block a user