Loading core/src/server/Server.cpp +6 −1 Original line number Diff line number Diff line Loading @@ -177,7 +177,7 @@ Server::Start() { STATUS_CHECK(Directory::Access(config.storage.path(), wal_path, config.logs.path())); if (config.system.lock.enable()) { STATUS_CHECK(Directory::Lock(config.storage.path(), wal_path)); STATUS_CHECK(Directory::Lock(config.storage.path(), wal_path, fd_list_)); } } Loading Loading @@ -214,6 +214,11 @@ void Server::Stop() { std::cerr << "Milvus server is going to shutdown ..." << std::endl; for (auto fd : fd_list_) { LOG_SERVER_DEBUG_C << "close directory lock file descriptor: " << fd; close(fd); } /* Unlock and close lockfile */ if (pid_fd_ != -1) { int ret = lockf(pid_fd_, F_ULOCK, 0); Loading core/src/server/Server.h +4 −1 Original line number Diff line number Diff line Loading @@ -12,6 +12,8 @@ #pragma once #include <string> #include <vector> #include "config/ServerConfig.h" #include "utils/Status.h" Loading Loading @@ -57,7 +59,8 @@ class Server { int pid_fd_ = -1; std::string pid_filename_; std::string config_filename_; // ConfigMgrPtr config_mgr_; /* Used for lock work directory */ std::vector<int64_t> fd_list_; }; // Server } // namespace milvus::server core/src/server/init/Directory.cpp +13 −5 Original line number Diff line number Diff line Loading @@ -33,10 +33,17 @@ Directory::Initialize(const std::string& storage_path, const std::string& wal_pa } Status Directory::Lock(const std::string& storage_path, const std::string& wal_path) { Directory::Lock(const std::string& storage_path, const std::string& wal_path, std::vector<int64_t>& fd_list) { try { lock(storage_path); lock(wal_path); auto storage_fd = lock(storage_path); if (storage_fd > 0) { fd_list.push_back(storage_fd); } auto wal_fd = lock(wal_path); if (wal_fd > 0) { fd_list.push_back(wal_fd); } } catch (std::exception& ex) { return Status(SERVER_UNEXPECTED_ERROR, ex.what()); } Loading Loading @@ -72,10 +79,10 @@ Directory::init(const std::string& path) { } } void int64_t Directory::lock(const std::string& path) { if (path.empty()) { return; return -1; } std::string lock_path = path + "/lock"; auto fd = open(lock_path.c_str(), O_RDWR | O_CREAT | O_NOFOLLOW, 0640); Loading Loading @@ -113,6 +120,7 @@ Directory::lock(const std::string& path) { close(fd); throw std::runtime_error(msg); } return fd; } void Loading core/src/server/init/Directory.h +3 −2 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ #pragma once #include <string> #include <vector> #include "utils/Status.h" Loading @@ -23,7 +24,7 @@ class Directory { Initialize(const std::string& storage_path, const std::string& wal_path, const std::string& log_path); static Status Lock(const std::string& storage_path, const std::string& wal_path); Lock(const std::string& storage_path, const std::string& wal_path, std::vector<int64_t>& fd_list); static Status Access(const std::string& storage_path, const std::string& wal_path, const std::string& log_path); Loading @@ -32,7 +33,7 @@ class Directory { static void init(const std::string& path); static void static int64_t lock(const std::string& path); static void Loading Loading
core/src/server/Server.cpp +6 −1 Original line number Diff line number Diff line Loading @@ -177,7 +177,7 @@ Server::Start() { STATUS_CHECK(Directory::Access(config.storage.path(), wal_path, config.logs.path())); if (config.system.lock.enable()) { STATUS_CHECK(Directory::Lock(config.storage.path(), wal_path)); STATUS_CHECK(Directory::Lock(config.storage.path(), wal_path, fd_list_)); } } Loading Loading @@ -214,6 +214,11 @@ void Server::Stop() { std::cerr << "Milvus server is going to shutdown ..." << std::endl; for (auto fd : fd_list_) { LOG_SERVER_DEBUG_C << "close directory lock file descriptor: " << fd; close(fd); } /* Unlock and close lockfile */ if (pid_fd_ != -1) { int ret = lockf(pid_fd_, F_ULOCK, 0); Loading
core/src/server/Server.h +4 −1 Original line number Diff line number Diff line Loading @@ -12,6 +12,8 @@ #pragma once #include <string> #include <vector> #include "config/ServerConfig.h" #include "utils/Status.h" Loading Loading @@ -57,7 +59,8 @@ class Server { int pid_fd_ = -1; std::string pid_filename_; std::string config_filename_; // ConfigMgrPtr config_mgr_; /* Used for lock work directory */ std::vector<int64_t> fd_list_; }; // Server } // namespace milvus::server
core/src/server/init/Directory.cpp +13 −5 Original line number Diff line number Diff line Loading @@ -33,10 +33,17 @@ Directory::Initialize(const std::string& storage_path, const std::string& wal_pa } Status Directory::Lock(const std::string& storage_path, const std::string& wal_path) { Directory::Lock(const std::string& storage_path, const std::string& wal_path, std::vector<int64_t>& fd_list) { try { lock(storage_path); lock(wal_path); auto storage_fd = lock(storage_path); if (storage_fd > 0) { fd_list.push_back(storage_fd); } auto wal_fd = lock(wal_path); if (wal_fd > 0) { fd_list.push_back(wal_fd); } } catch (std::exception& ex) { return Status(SERVER_UNEXPECTED_ERROR, ex.what()); } Loading Loading @@ -72,10 +79,10 @@ Directory::init(const std::string& path) { } } void int64_t Directory::lock(const std::string& path) { if (path.empty()) { return; return -1; } std::string lock_path = path + "/lock"; auto fd = open(lock_path.c_str(), O_RDWR | O_CREAT | O_NOFOLLOW, 0640); Loading Loading @@ -113,6 +120,7 @@ Directory::lock(const std::string& path) { close(fd); throw std::runtime_error(msg); } return fd; } void Loading
core/src/server/init/Directory.h +3 −2 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ #pragma once #include <string> #include <vector> #include "utils/Status.h" Loading @@ -23,7 +24,7 @@ class Directory { Initialize(const std::string& storage_path, const std::string& wal_path, const std::string& log_path); static Status Lock(const std::string& storage_path, const std::string& wal_path); Lock(const std::string& storage_path, const std::string& wal_path, std::vector<int64_t>& fd_list); static Status Access(const std::string& storage_path, const std::string& wal_path, const std::string& log_path); Loading @@ -32,7 +33,7 @@ class Directory { static void init(const std::string& path); static void static int64_t lock(const std::string& path); static void Loading