further optimize compile
This commit is contained in:
@ -37,6 +37,7 @@ add_definitions(-DZSTD_STATIC_LINKING_ONLY)
|
|||||||
option(ENABLE_ADVANCED_FEATURE "Enable advanced features" OFF)
|
option(ENABLE_ADVANCED_FEATURE "Enable advanced features" OFF)
|
||||||
option(OJ_TEST_BPT "Enable OJ test for B+ Tree" OFF)
|
option(OJ_TEST_BPT "Enable OJ test for B+ Tree" OFF)
|
||||||
option(OJ_TEST_BACKEND "Enable OJ test for backend" ON)
|
option(OJ_TEST_BACKEND "Enable OJ test for backend" ON)
|
||||||
|
option(ENABLE_TEST_POINTS "Enable test points" OFF)
|
||||||
|
|
||||||
# 如果 ENABLE_ADVANCED_FEATURE 选项为 ON,则定义 ENABLE_ADVANCED_FEATURE 宏
|
# 如果 ENABLE_ADVANCED_FEATURE 选项为 ON,则定义 ENABLE_ADVANCED_FEATURE 宏
|
||||||
if (ENABLE_ADVANCED_FEATURE)
|
if (ENABLE_ADVANCED_FEATURE)
|
||||||
@ -45,13 +46,15 @@ endif()
|
|||||||
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
FetchContent_Declare(
|
if(ENABLE_TEST_POINTS)
|
||||||
googletest
|
FetchContent_Declare(
|
||||||
URL_HASH SHA256=1f357c27ca988c3f7c6b4bf68a9395005ac6761f034046e9dde0896e3aba00e4
|
googletest
|
||||||
URL ${CMAKE_SOURCE_DIR}/deps/googletest-v1.14.0-mirror.zip
|
URL_HASH SHA256=1f357c27ca988c3f7c6b4bf68a9395005ac6761f034046e9dde0896e3aba00e4
|
||||||
)
|
URL ${CMAKE_SOURCE_DIR}/deps/googletest-v1.14.0-mirror.zip
|
||||||
FetchContent_MakeAvailable(googletest)
|
)
|
||||||
include(GoogleTest)
|
FetchContent_MakeAvailable(googletest)
|
||||||
|
include(GoogleTest)
|
||||||
|
endif()
|
||||||
|
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
argparse
|
argparse
|
||||||
@ -67,14 +70,15 @@ FetchContent_Declare(
|
|||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(spdlog)
|
FetchContent_MakeAvailable(spdlog)
|
||||||
|
|
||||||
FetchContent_Declare(
|
|
||||||
sockpp
|
|
||||||
URL_HASH SHA256=d144b3dcc7e9f031a9205395deb334b0b9681e1e7db61c066cca22ec2650a77b
|
|
||||||
URL ${CMAKE_SOURCE_DIR}/deps/sockpp-v1.0.0-mirror.zip
|
|
||||||
)
|
|
||||||
FetchContent_MakeAvailable(sockpp)
|
|
||||||
|
|
||||||
if(ENABLE_ADVANCED_FEATURE)
|
if(ENABLE_ADVANCED_FEATURE)
|
||||||
|
FetchContent_Declare(
|
||||||
|
sockpp
|
||||||
|
URL_HASH SHA256=d144b3dcc7e9f031a9205395deb334b0b9681e1e7db61c066cca22ec2650a77b
|
||||||
|
URL ${CMAKE_SOURCE_DIR}/deps/sockpp-v1.0.0-mirror.zip
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(sockpp)
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
zstd
|
zstd
|
||||||
URL_HASH SHA256=3b1c3b46e416d36931efd34663122d7f51b550c87f74de2d38249516fe7d8be5
|
URL_HASH SHA256=3b1c3b46e416d36931efd34663122d7f51b550c87f74de2d38249516fe7d8be5
|
||||||
|
@ -6,9 +6,9 @@ endif()
|
|||||||
add_executable(${BACKEND_EXETUABLE_NAME} main.cpp engine.cpp utils.cpp data.cpp user_system.cpp train_system.cpp transaction_system.cpp)
|
add_executable(${BACKEND_EXETUABLE_NAME} main.cpp engine.cpp utils.cpp data.cpp user_system.cpp train_system.cpp transaction_system.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} storage)
|
target_link_libraries(${BACKEND_EXETUABLE_NAME} storage)
|
||||||
if(ENABLE_ADVANCED_FEATURE)
|
if(ENABLE_ADVANCED_FEATURE)
|
||||||
|
target_link_libraries(${BACKEND_EXETUABLE_NAME} sockpp)
|
||||||
target_link_libraries(${BACKEND_EXETUABLE_NAME} dataguard)
|
target_link_libraries(${BACKEND_EXETUABLE_NAME} dataguard)
|
||||||
endif()
|
endif()
|
||||||
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})
|
@ -11,23 +11,24 @@ struct FullUserData {
|
|||||||
uint8_t privilege;
|
uint8_t privilege;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct StationNameData {
|
||||||
|
char name[100][40];
|
||||||
|
};
|
||||||
|
static_assert(sizeof(StationNameData) == 4000);
|
||||||
|
|
||||||
// waring: this struct is extremely large, later DiskManager should be optimized to handle this
|
// waring: this struct is extremely large, later DiskManager should be optimized to handle this
|
||||||
struct FullTrainData {
|
struct FullTrainData {
|
||||||
char trainID[21];
|
char trainID[21];
|
||||||
uint8_t stationNum;
|
uint8_t stationNum;
|
||||||
// char stations[100][41];
|
|
||||||
hash_t stations_hash[100];
|
hash_t stations_hash[100];
|
||||||
uint32_t seatNum : 18;
|
uint32_t seatNum : 18;
|
||||||
uint16_t startTime : 12;
|
uint16_t startTime : 12;
|
||||||
uint16_t saleDate_beg : 10, saleDate_end : 10;
|
uint16_t saleDate_beg : 10, saleDate_end : 10;
|
||||||
uint8_t type : 6;
|
uint8_t type : 6;
|
||||||
struct StationData {
|
uint16_t travelTime[100];
|
||||||
uint32_t price : 18;
|
uint16_t stopoverTime[100];
|
||||||
uint16_t travelTime : 15;
|
|
||||||
uint16_t stopoverTime : 15;
|
|
||||||
};
|
|
||||||
StationData stations[100];
|
|
||||||
};
|
};
|
||||||
|
struct TicketPriceData {};
|
||||||
|
|
||||||
class TrainDataDrive : public DataDriverBase {};
|
class TrainDataDrive : public DataDriverBase {};
|
||||||
|
|
||||||
|
@ -16,14 +16,42 @@ class TicketSystemEngine {
|
|||||||
#endif
|
#endif
|
||||||
std::string data_directory;
|
std::string data_directory;
|
||||||
std::map<hash_t, uint8_t> online_users;
|
std::map<hash_t, uint8_t> online_users;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief user data system
|
||||||
|
* @details The database for users.
|
||||||
|
*/
|
||||||
DiskMap<hash_t, FullUserData> user_data;
|
DiskMap<hash_t, FullUserData> user_data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief train data system
|
||||||
|
*/
|
||||||
|
DiskMap<hash_t, StationNameData> full_station_name_data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief transaction data system
|
||||||
|
* @details This part is responsible for storing:
|
||||||
|
* - Remaining seat numbers: using HashedTrainID + train number as the index, with a B+ tree point to an array
|
||||||
|
* - Stop information: using the station + HashedTrainID as the index, with a B+ tree point to the train's sales start
|
||||||
|
* and end dates, minutes required from the starting station to the current station, and the current station's stop
|
||||||
|
* time
|
||||||
|
* - Order information: using an incrementing, non-repeating uint64_t as the index, with an OrderData attached
|
||||||
|
* - Waiting queue: using the station + HashedTrainID as the index, with a B+ tree point to a LinkedQueue, storing IDs
|
||||||
|
* pointing to order information
|
||||||
|
* - User purchase history: using HashedUserID as the index, with a LinkedStack attached, with a simple skip list-like
|
||||||
|
* optimization, storing IDs pointing to order information
|
||||||
|
*/
|
||||||
|
// TODO
|
||||||
|
|
||||||
void PrepareExit();
|
void PrepareExit();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline TicketSystemEngine(std::string data_directory)
|
inline TicketSystemEngine(std::string data_directory)
|
||||||
: data_directory(data_directory),
|
: data_directory(data_directory),
|
||||||
user_data("user_data.idx", data_directory + "/user_data.idx", "user_data.val",
|
user_data("user_data.idx", data_directory + "/user_data.idx", "user_data.val",
|
||||||
data_directory + "/user_data.val") {}
|
data_directory + "/user_data.val"),
|
||||||
|
full_station_name_data("station_name.idx", data_directory + "/station_name.idx", "station_name.val",
|
||||||
|
data_directory + "/station_name.val") {}
|
||||||
std::string Execute(const std::string &command);
|
std::string Execute(const std::string &command);
|
||||||
|
|
||||||
// User system
|
// User system
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#include <sockpp/tcp_acceptor.h>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include "basic_defs.h"
|
#include "basic_defs.h"
|
||||||
#ifdef ENABLE_ADVANCED_FEATURE
|
#ifdef ENABLE_ADVANCED_FEATURE
|
||||||
|
#include <sockpp/tcp_acceptor.h>
|
||||||
#include "dataguard/dataguard.h"
|
#include "dataguard/dataguard.h"
|
||||||
#endif
|
#endif
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
@ -3,25 +3,27 @@ if(OJ_TEST_BPT)
|
|||||||
target_link_libraries(code storage)
|
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)
|
if(ENABLE_TEST_POINTS)
|
||||||
target_link_libraries(replacer_test storage GTest::gtest_main)
|
add_executable(replacer_test replacer_test.cpp)
|
||||||
add_executable(buffer_pool_manager_test buffer_pool_manager_test.cpp)
|
target_link_libraries(replacer_test storage GTest::gtest_main)
|
||||||
target_link_libraries(buffer_pool_manager_test storage GTest::gtest_main spdlog::spdlog)
|
add_executable(buffer_pool_manager_test buffer_pool_manager_test.cpp)
|
||||||
add_executable(page_guard_test page_guard_test.cpp)
|
target_link_libraries(buffer_pool_manager_test storage GTest::gtest_main spdlog::spdlog)
|
||||||
target_link_libraries(page_guard_test storage GTest::gtest_main)
|
add_executable(page_guard_test page_guard_test.cpp)
|
||||||
add_executable(bpt_basic_test bpt_basic_test.cpp)
|
target_link_libraries(page_guard_test storage GTest::gtest_main)
|
||||||
target_link_libraries(bpt_basic_test storage GTest::gtest_main spdlog::spdlog)
|
add_executable(bpt_basic_test bpt_basic_test.cpp)
|
||||||
add_executable(buffer_pool_manager_extreme_test buffer_pool_manager_extreme_test.cpp)
|
target_link_libraries(bpt_basic_test storage GTest::gtest_main spdlog::spdlog)
|
||||||
target_link_libraries(buffer_pool_manager_extreme_test storage)
|
add_executable(buffer_pool_manager_extreme_test buffer_pool_manager_extreme_test.cpp)
|
||||||
add_executable(t1_std t1_std.cpp)
|
target_link_libraries(buffer_pool_manager_extreme_test storage)
|
||||||
set_target_properties(t1_std PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
add_executable(t1_std t1_std.cpp)
|
||||||
add_executable(t1_mk t1_mk.cpp)
|
set_target_properties(t1_std PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||||
set_target_properties(t1_mk PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
add_executable(t1_mk t1_mk.cpp)
|
||||||
add_executable(bpt_advanced_test bpt_advanced_test.cpp)
|
set_target_properties(t1_mk PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||||
target_link_libraries(bpt_advanced_test storage GTest::gtest_main spdlog::spdlog)
|
add_executable(bpt_advanced_test bpt_advanced_test.cpp)
|
||||||
if(ENABLE_ADVANCED_FEATURE)
|
target_link_libraries(bpt_advanced_test storage GTest::gtest_main spdlog::spdlog)
|
||||||
add_executable(snapshot_test snapshot_test.cpp)
|
if(ENABLE_ADVANCED_FEATURE)
|
||||||
target_link_libraries(snapshot_test storage dataguard GTest::gtest_main spdlog::spdlog)
|
add_executable(snapshot_test snapshot_test.cpp)
|
||||||
endif()
|
target_link_libraries(snapshot_test storage dataguard GTest::gtest_main spdlog::spdlog)
|
||||||
add_executable(hash_collision_test hash_collision_test.cpp)
|
endif()
|
||||||
add_executable(utils_test utils_test.cpp)
|
add_executable(hash_collision_test hash_collision_test.cpp)
|
||||||
|
add_executable(utils_test utils_test.cpp)
|
||||||
|
endif()
|
Reference in New Issue
Block a user