From 8046f2946efa98fe8d845efb66f97f4664f93fd7 Mon Sep 17 00:00:00 2001 From: Tinkerrr Date: Fri, 17 Jul 2020 21:00:42 +0800 Subject: [PATCH] Hotfix 2487 (#2892) * update. Signed-off-by: Tinkerrr * update. Signed-off-by: Tinkerrr * add fd check Signed-off-by: Tinkerrr * fix Signed-off-by: Tinkerrr --- CHANGELOG.md | 1 + core/src/server/init/InstanceLockCheck.cpp | 23 ++++++++++++++++++++++ core/src/server/init/InstanceLockCheck.h | 9 +++++++++ core/src/utils/SignalUtil.cpp | 3 +++ 4 files changed, 36 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1c4b9cb56..d9b80838df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ Please mark all change in change log and use the issue from GitHub - \#2774 Server down during loading data - \#2776 Fix too many data copies during creating IVF index - \#2813 To implemente RNSG IP +- \#2487 HotFix release lock failed on NAS ## Feature diff --git a/core/src/server/init/InstanceLockCheck.cpp b/core/src/server/init/InstanceLockCheck.cpp index bd89f9631c..df04e4408d 100644 --- a/core/src/server/init/InstanceLockCheck.cpp +++ b/core/src/server/init/InstanceLockCheck.cpp @@ -23,6 +23,12 @@ namespace milvus { namespace server { +InstanceLockCheck* +InstanceLockCheck::GetInstance() { + static InstanceLockCheck lk; + return &lk; +} + Status InstanceLockCheck::Check(const std::string& path) { std::string lock_path = path + "/lock"; @@ -37,6 +43,7 @@ InstanceLockCheck::Check(const std::string& path) { msg += "Could not open file: " + lock_path + ", " + strerror(errno); return Status(SERVER_UNEXPECTED_ERROR, msg); } + InstanceLockCheck::GetInstance()->lk_path = lock_path; // Acquire a write lock struct flock fl; @@ -66,5 +73,21 @@ InstanceLockCheck::Check(const std::string& path) { return Status::OK(); } +void +InstanceLockCheck::Release() { + auto fd = open(InstanceLockCheck::GetInstance()->lk_path.c_str(), O_RDWR | O_CREAT | O_NOFOLLOW, 0640); + if (fd < 0) { + std::string msg; + if (errno == EROFS) { + // Not using locking for read-only lock file + msg += "Lock file is read-only."; + } + msg += "Could not open file for release: " + InstanceLockCheck::GetInstance()->lk_path + ", " + strerror(errno); + LOG_SERVER_ERROR_ << msg; + return; + } + close(fd); +} + } // namespace server } // namespace milvus diff --git a/core/src/server/init/InstanceLockCheck.h b/core/src/server/init/InstanceLockCheck.h index 14f88343d6..8f5cb3d09d 100644 --- a/core/src/server/init/InstanceLockCheck.h +++ b/core/src/server/init/InstanceLockCheck.h @@ -21,6 +21,15 @@ class InstanceLockCheck { public: static Status Check(const std::string& path); + + static void + Release(); + + static InstanceLockCheck* + GetInstance(); + + public: + std::string lk_path; }; // InstanceLockCheck } // namespace server diff --git a/core/src/utils/SignalUtil.cpp b/core/src/utils/SignalUtil.cpp index 003088c579..cfb36ca592 100644 --- a/core/src/utils/SignalUtil.cpp +++ b/core/src/utils/SignalUtil.cpp @@ -11,6 +11,7 @@ #include "utils/SignalUtil.h" #include "src/server/Server.h" +#include "src/server/init/InstanceLockCheck.h" #include "utils/Log.h" #include @@ -22,6 +23,8 @@ namespace server { void SignalUtil::HandleSignal(int signum) { + InstanceLockCheck::Release(); + LOG_SERVER_INFO_ << "Release lock!" << signum; switch (signum) { case SIGINT: case SIGUSR2: {