mirror of
https://github.com/deepseek-ai/3FS
synced 2025-06-26 18:16:45 +00:00
Initial commit
This commit is contained in:
24
src/mgmtd/ops/GetPrimaryMgmtdOperation.cc
Normal file
24
src/mgmtd/ops/GetPrimaryMgmtdOperation.cc
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "GetPrimaryMgmtdOperation.h"
|
||||
|
||||
#include "mgmtd/service/helpers.h"
|
||||
|
||||
namespace hf3fs::mgmtd {
|
||||
CoTryTask<GetPrimaryMgmtdRsp> GetPrimaryMgmtdOperation::handle(MgmtdState &state) const {
|
||||
CO_RETURN_ON_ERROR(state.validateClusterId(*this, req.clusterId));
|
||||
auto now = state.utcNow();
|
||||
auto lease = co_await state.currentLease(now);
|
||||
if (lease.has_value()) {
|
||||
co_return GetPrimaryMgmtdRsp::create(std::move(lease->primary));
|
||||
}
|
||||
auto handler = [&](kv::IReadOnlyTransaction &txn) -> CoTryTask<std::optional<flat::MgmtdLeaseInfo>> {
|
||||
co_return co_await state.store_.loadMgmtdLeaseInfo(txn);
|
||||
};
|
||||
auto res = co_await kv::WithTransaction(state.createRetryStrategy())
|
||||
.run(state.env_->kvEngine()->createReadonlyTransaction(), std::move(handler));
|
||||
CO_RETURN_ON_ERROR(res);
|
||||
if (res->has_value()) {
|
||||
co_return GetPrimaryMgmtdRsp::create(std::move(res->value().primary));
|
||||
}
|
||||
co_return GetPrimaryMgmtdRsp::create(std::nullopt);
|
||||
}
|
||||
} // namespace hf3fs::mgmtd
|
||||
Reference in New Issue
Block a user