Fix errors of unable to run in OJ

This commit is contained in:
2024-05-21 14:44:42 +00:00
parent 67291a6553
commit 6b758994fc
6 changed files with 36 additions and 16 deletions

View File

@ -74,6 +74,7 @@ FetchContent_Declare(
) )
FetchContent_MakeAvailable(sockpp) FetchContent_MakeAvailable(sockpp)
if(ENABLE_ADVANCED_FEATURE)
FetchContent_Declare( FetchContent_Declare(
zstd zstd
URL_HASH SHA256=3b1c3b46e416d36931efd34663122d7f51b550c87f74de2d38249516fe7d8be5 URL_HASH SHA256=3b1c3b46e416d36931efd34663122d7f51b550c87f74de2d38249516fe7d8be5
@ -83,9 +84,12 @@ FetchContent_Declare(
set(ZSTD_BUILD_SHARED OFF CACHE BOOL "Build shared libraries") 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)
endif()
include_directories(${CMAKE_SOURCE_DIR}/storage/include) include_directories(${CMAKE_SOURCE_DIR}/storage/include)
if(ENABLE_ADVANCED_FEATURE)
include_directories(${CMAKE_SOURCE_DIR}/dataguard/include) include_directories(${CMAKE_SOURCE_DIR}/dataguard/include)
endif()
include_directories(${CMAKE_SOURCE_DIR}/stlite) include_directories(${CMAKE_SOURCE_DIR}/stlite)
include(CTest) include(CTest)
@ -93,6 +97,8 @@ enable_testing()
include(test/ctest_config) include(test/ctest_config)
add_subdirectory(storage) add_subdirectory(storage)
if(ENABLE_ADVANCED_FEATURE)
add_subdirectory(dataguard) add_subdirectory(dataguard)
endif()
add_subdirectory(test) add_subdirectory(test)
add_subdirectory(src) add_subdirectory(src)

View File

@ -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} 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} storage)
if(ENABLE_ADVANCED_FEATURE)
target_link_libraries(${BACKEND_EXETUABLE_NAME} dataguard) target_link_libraries(${BACKEND_EXETUABLE_NAME} dataguard)
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})

View File

@ -97,7 +97,7 @@ std::string TicketSystemEngine::Execute(const std::string &command) {
throw std::invalid_argument("Invalid 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) { std::string TicketSystemEngine::Exit(const std::string &command) {
command_id_t command_id; command_id_t command_id;

View File

@ -1,7 +1,10 @@
#include <sockpp/tcp_acceptor.h> #include <sockpp/tcp_acceptor.h>
#include <cassert>
#include <exception> #include <exception>
#include "basic_defs.h" #include "basic_defs.h"
#ifdef ENABLE_ADVANCED_FEATURE
#include "dataguard/dataguard.h" #include "dataguard/dataguard.h"
#endif
#include "engine.h" #include "engine.h"
#include "storage/bpt.hpp" #include "storage/bpt.hpp"
const std::string main_version = "0.0.1"; 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"); bool is_server = program.is_subcommand_used("server");
LOG->info("Server mode: {}", is_server); LOG->info("Server mode: {}", is_server);
try { try {
#ifdef ENABLE_ADVANCED_FEATURE
if (is_server) { if (is_server) {
auto port = server_command.get<int>("--port"); auto port = server_command.get<int>("--port");
auto address = server_command.get<std::string>("--address"); auto address = server_command.get<std::string>("--address");
@ -100,6 +104,7 @@ int main(int argc, char *argv[]) {
LOG->info("successfully bind to address {} port {}", address, port); LOG->info("successfully bind to address {} port {}", address, port);
throw std::runtime_error("Server mode not implemented"); throw std::runtime_error("Server mode not implemented");
} else { } else {
#endif
std::ios::sync_with_stdio(false); std::ios::sync_with_stdio(false);
std::cin.tie(nullptr); std::cin.tie(nullptr);
std::cout.tie(nullptr); std::cout.tie(nullptr);
@ -107,9 +112,10 @@ int main(int argc, char *argv[]) {
std::string cmd; std::string cmd;
while (std::getline(std::cin, cmd)) { while (std::getline(std::cin, cmd)) {
std::cout << engine.Execute(cmd) << '\n'; std::cout << engine.Execute(cmd) << '\n';
std::cout.flush();
} }
#ifdef ENABLE_ADVANCED_FEATURE
} }
#endif
} catch (std::exception &e) { } catch (std::exception &e) {
LOG->error("Exception: {}", e.what()); LOG->error("Exception: {}", e.what());
return 1; return 1;

View File

@ -28,6 +28,10 @@ class DiskMap : public DataDriverBase {
index_file_path(std::move(index_file_path_)), index_file_path(std::move(index_file_path_)),
data_file_identifier(std::move(data_file_identifier_)), data_file_identifier(std::move(data_file_identifier_)),
data_file_path(std::move(data_file_path_)) { 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_disk_manager = new DiskManager(index_file_path);
index_bpm = new BufferPoolManager(100, 5, index_disk_manager); index_bpm = new BufferPoolManager(100, 5, index_disk_manager);
indexer = new BPlusTreeIndexer<Key, Compare>(index_bpm); indexer = new BPlusTreeIndexer<Key, Compare>(index_bpm);

View File

@ -19,6 +19,8 @@ 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 storage GTest::gtest_main spdlog::spdlog) target_link_libraries(bpt_advanced_test storage GTest::gtest_main spdlog::spdlog)
if(ENABLE_ADVANCED_FEATURE)
add_executable(snapshot_test snapshot_test.cpp) add_executable(snapshot_test snapshot_test.cpp)
target_link_libraries(snapshot_test storage dataguard GTest::gtest_main spdlog::spdlog) target_link_libraries(snapshot_test storage dataguard GTest::gtest_main spdlog::spdlog)
endif()
add_executable(hash_collision_test hash_collision_test.cpp) add_executable(hash_collision_test hash_collision_test.cpp)