From 6b758994fc46bb838139fa0c565a94fe69745ba9 Mon Sep 17 00:00:00 2001 From: happyZYM Date: Tue, 21 May 2024 14:44:42 +0000 Subject: [PATCH] Fix errors of unable to run in OJ --- CMakeLists.txt | 28 +++++++++++++++++----------- src/CMakeLists.txt | 4 +++- src/engine.cpp | 2 +- src/main.cpp | 8 +++++++- storage/include/storage/disk_map.hpp | 4 ++++ test/CMakeLists.txt | 6 ++++-- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a50f365..f619df5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,18 +74,22 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(sockpp) -FetchContent_Declare( - zstd - URL_HASH SHA256=3b1c3b46e416d36931efd34663122d7f51b550c87f74de2d38249516fe7d8be5 - URL ${CMAKE_SOURCE_DIR}/deps/zstd-v1.5.6-mirror.zip - SOURCE_SUBDIR build/cmake -) -set(ZSTD_BUILD_SHARED OFF CACHE BOOL "Build shared libraries") -set(ZSTD_BUILD_DEPRECATED OFF CACHE BOOL "Build deprecated module") -FetchContent_MakeAvailable(zstd) +if(ENABLE_ADVANCED_FEATURE) + FetchContent_Declare( + zstd + URL_HASH SHA256=3b1c3b46e416d36931efd34663122d7f51b550c87f74de2d38249516fe7d8be5 + URL ${CMAKE_SOURCE_DIR}/deps/zstd-v1.5.6-mirror.zip + SOURCE_SUBDIR build/cmake + ) + set(ZSTD_BUILD_SHARED OFF CACHE BOOL "Build shared libraries") + set(ZSTD_BUILD_DEPRECATED OFF CACHE BOOL "Build deprecated module") + FetchContent_MakeAvailable(zstd) +endif() include_directories(${CMAKE_SOURCE_DIR}/storage/include) -include_directories(${CMAKE_SOURCE_DIR}/dataguard/include) +if(ENABLE_ADVANCED_FEATURE) + include_directories(${CMAKE_SOURCE_DIR}/dataguard/include) +endif() include_directories(${CMAKE_SOURCE_DIR}/stlite) include(CTest) @@ -93,6 +97,8 @@ enable_testing() include(test/ctest_config) add_subdirectory(storage) -add_subdirectory(dataguard) +if(ENABLE_ADVANCED_FEATURE) + add_subdirectory(dataguard) +endif() add_subdirectory(test) add_subdirectory(src) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dcabc5f..51ddf54 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,5 +8,7 @@ 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) +if(ENABLE_ADVANCED_FEATURE) + target_link_libraries(${BACKEND_EXETUABLE_NAME} dataguard) +endif() set_target_properties(${BACKEND_EXETUABLE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) \ No newline at end of file diff --git a/src/engine.cpp b/src/engine.cpp index 9b74c7c..94ce890 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -97,7 +97,7 @@ std::string TicketSystemEngine::Execute(const std::string &command) { throw std::invalid_argument("Invalid command."); } -std::string TicketSystemEngine::Clean() { return "Clean"; } +std::string TicketSystemEngine::Clean() { throw std::runtime_error("Command clean is not implemented"); } std::string TicketSystemEngine::Exit(const std::string &command) { command_id_t command_id; diff --git a/src/main.cpp b/src/main.cpp index 1c67f67..ca50677 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,10 @@ #include +#include #include #include "basic_defs.h" +#ifdef ENABLE_ADVANCED_FEATURE #include "dataguard/dataguard.h" +#endif #include "engine.h" #include "storage/bpt.hpp" const std::string main_version = "0.0.1"; @@ -86,6 +89,7 @@ int main(int argc, char *argv[]) { bool is_server = program.is_subcommand_used("server"); LOG->info("Server mode: {}", is_server); try { +#ifdef ENABLE_ADVANCED_FEATURE if (is_server) { auto port = server_command.get("--port"); auto address = server_command.get("--address"); @@ -100,6 +104,7 @@ int main(int argc, char *argv[]) { LOG->info("successfully bind to address {} port {}", address, port); throw std::runtime_error("Server mode not implemented"); } else { +#endif std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); @@ -107,9 +112,10 @@ int main(int argc, char *argv[]) { std::string cmd; while (std::getline(std::cin, cmd)) { std::cout << engine.Execute(cmd) << '\n'; - std::cout.flush(); } +#ifdef ENABLE_ADVANCED_FEATURE } +#endif } catch (std::exception &e) { LOG->error("Exception: {}", e.what()); return 1; diff --git a/storage/include/storage/disk_map.hpp b/storage/include/storage/disk_map.hpp index 2d070c4..52db2ef 100644 --- a/storage/include/storage/disk_map.hpp +++ b/storage/include/storage/disk_map.hpp @@ -28,6 +28,10 @@ class DiskMap : public DataDriverBase { index_file_path(std::move(index_file_path_)), data_file_identifier(std::move(data_file_identifier_)), data_file_path(std::move(data_file_path_)) { + // if (index_file_path.length() >= 2 && index_file_path[0] == '.' && index_file_path[1] == '/') + // index_file_path = index_file_path.substr(2); + // if (data_file_path.length() >= 2 && data_file_path[0] == '.' && data_file_path[1] == '/') + // data_file_path = data_file_path.substr(2); index_disk_manager = new DiskManager(index_file_path); index_bpm = new BufferPoolManager(100, 5, index_disk_manager); indexer = new BPlusTreeIndexer(index_bpm); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index dd20e7d..02b52e9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -19,6 +19,8 @@ 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 storage GTest::gtest_main spdlog::spdlog) -add_executable(snapshot_test snapshot_test.cpp) -target_link_libraries(snapshot_test storage dataguard GTest::gtest_main spdlog::spdlog) +if(ENABLE_ADVANCED_FEATURE) + add_executable(snapshot_test snapshot_test.cpp) + target_link_libraries(snapshot_test storage dataguard GTest::gtest_main spdlog::spdlog) +endif() add_executable(hash_collision_test hash_collision_test.cpp) \ No newline at end of file