set up api chain

This commit is contained in:
2024-04-25 15:05:53 +00:00
parent 243156d497
commit 4b5ebaeef4
11 changed files with 26 additions and 11 deletions

View File

@ -84,11 +84,13 @@ 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}/stlite)
include(CTest)
enable_testing()
add_subdirectory(bpt)
add_subdirectory(snapshot)
add_subdirectory(test)
add_subdirectory(src)

View File

@ -34,6 +34,7 @@ class BPlusTreeIndexer {
// TODO
}
};
BPlusTreeIndexer() = delete;
BPlusTreeIndexer(const BPlusTreeIndexer &) = delete;
BPlusTreeIndexer(BPlusTreeIndexer &&) = delete;
BPlusTreeIndexer &operator=(const BPlusTreeIndexer &) = delete;
@ -80,12 +81,17 @@ class BPlusTreeIndexer {
return true;
}
size_t Size() { return siz; }
void Flush() {
// TODO: do some recording
bpm->FlushAllPages();
}
private:
page_id_t root_page_id;
size_t siz;
page_id_t root_page_id; // stored in the first 4 (0-3) bytes of RawDatMemory
uint64_t siz; // stored in the next 8 (4-11) bytes of RawDatMemory
static KeyComparator key_cmp;
std::shared_mutex latch;
BufferPoolManager *bpm;
};
template <typename KeyType, typename KeyComparator>
KeyComparator BPlusTreeIndexer<KeyType, KeyComparator>::key_cmp = KeyComparator();

View File

@ -249,6 +249,8 @@ class BufferPoolManager {
BufferPoolManager &operator=(const BufferPoolManager &) = delete;
BufferPoolManager &operator=(BufferPoolManager &&) = delete;
~BufferPoolManager();
inline char *RawDataMemory() { return disk_manager->RawDataMemory(); }
inline size_t RawDatMemorySize() { return disk_manager->RawDatMemorySize(); }
/**
* @brief Allocate a page on disk. Caller should acquire the latch before calling this function.
* @return the id of the allocated page

View File

@ -21,7 +21,7 @@ class DiskManager {
~DiskManager();
char *RawDataMemory();
size_t RawDatMemorySize();
void FlushInternalPage();
void FullyFlush();
void Close();
void ReadPage(page_id_t page_id, char *page_data_ptr);
void WritePage(page_id_t page_id, const char *page_data_ptr); // in fact, the page_id is the offest

View File

@ -104,9 +104,7 @@ page_id_t BufferPoolManager::AllocatePage() {
return page_id;
}
void BufferPoolManager::DeallocatePage(page_id_t page_id) {
disk_manager->DeallocatePage(page_id);
}
void BufferPoolManager::DeallocatePage(page_id_t page_id) { disk_manager->DeallocatePage(page_id); }
size_t BufferPoolManager::GetPoolSize() { return pool_size; }
Page *BufferPoolManager::GetPages() { return pages_; }
@ -224,6 +222,7 @@ void BufferPoolManager::FlushAllPages() {
for (auto &pair : page_table_) {
FlushPage(pair.first);
}
disk_manager->FullyFlush();
}
auto BufferPoolManager::DeletePage(page_id_t page_id) -> bool {

View File

@ -20,7 +20,7 @@ DiskManager::DiskManager(const std::string &file_path_)
current_none_empty_page_count = 0;
raw_data_memory = new char[kPageSize - meta_data_size];
memset(raw_data_memory, 0, kPageSize - meta_data_size);
FlushInternalPage();
FullyFlush();
is_new = true;
} else {
// File exists, read metadata from internal page
@ -45,7 +45,7 @@ char *DiskManager::RawDataMemory() { return raw_data_memory; }
size_t DiskManager::RawDatMemorySize() { return kPageSize - meta_data_size; }
void DiskManager::FlushInternalPage() {
void DiskManager::FullyFlush() {
fseek(fp, 0, SEEK_SET);
fwrite(&first_empty_page_id, sizeof(page_id_t), 1, fp);
fwrite(&current_total_page_count, sizeof(size_t), 1, fp);
@ -56,7 +56,7 @@ void DiskManager::FlushInternalPage() {
void DiskManager::Close() {
if (fp != nullptr) {
FlushInternalPage();
FullyFlush();
fclose(fp);
fp = nullptr;
}

2
snapshot/CMakeLists.txt Normal file
View File

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

View File

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

View File

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

View File

@ -7,5 +7,4 @@ 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} libzstd_static)
set_target_properties(${BACKEND_EXETUABLE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

View File

@ -1,5 +1,4 @@
#include <sockpp/tcp_acceptor.h>
#include <zstd.h>
#include "basic_defs.h"
const std::string main_version = "0.0.1";
const std::string build_version = GIT_COMMIT_HASH;