mirror of
https://github.com/deepseek-ai/3FS
synced 2025-06-26 18:16:45 +00:00
Initial commit
This commit is contained in:
1
src/core/service/CMakeLists.txt
Normal file
1
src/core/service/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
target_add_lib(core-service core-service-fbs)
|
||||
14
src/core/service/CoreService.cc
Normal file
14
src/core/service/CoreService.cc
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "CoreService.h"
|
||||
|
||||
#include "core/service/ops/Include.h"
|
||||
#include "core/utils/runOp.h"
|
||||
|
||||
#define DEFINE_SERDE_SERVICE_METHOD_FULL(svc, name, Name, id, reqtype, rsptype) \
|
||||
CoTryTask<rsptype> svc##Service::name(serde::CallContext &ctx, const reqtype &req) { \
|
||||
Name##Operation op(std::move(req)); \
|
||||
CO_INVOKE_OP_INFO(op, ctx.peer()); \
|
||||
}
|
||||
|
||||
namespace hf3fs::core {
|
||||
#include "fbs/core/service/CoreServiceDef.h"
|
||||
} // namespace hf3fs::core
|
||||
14
src/core/service/CoreService.h
Normal file
14
src/core/service/CoreService.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/serde/CallContext.h"
|
||||
#include "fbs/core/service/CoreServiceBase.h"
|
||||
|
||||
namespace hf3fs::core {
|
||||
class CoreService : public serde::ServiceWrapper<CoreService, CoreServiceBase> {
|
||||
public:
|
||||
#define DEFINE_SERDE_SERVICE_METHOD_FULL(svc, name, Name, id, reqtype, rsptype) \
|
||||
CoTryTask<rsptype> name(serde::CallContext &ctx, const reqtype &req);
|
||||
|
||||
#include "fbs/core/service/CoreServiceDef.h"
|
||||
};
|
||||
} // namespace hf3fs::core
|
||||
19
src/core/service/ops/EchoOperation.h
Normal file
19
src/core/service/ops/EchoOperation.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "core/utils/ServiceOperation.h"
|
||||
#include "fbs/core/service/Rpc.h"
|
||||
|
||||
namespace hf3fs::core {
|
||||
|
||||
struct EchoOperation : ServiceOperationWithMetric<"CoreService", "Echo", "op"> {
|
||||
EchoMessage req;
|
||||
|
||||
explicit EchoOperation(EchoMessage r)
|
||||
: req(std::move(r)) {}
|
||||
|
||||
String toStringImpl() const final { return "Echo"; }
|
||||
|
||||
CoTryTask<EchoMessage> handle() { co_return req; }
|
||||
};
|
||||
|
||||
} // namespace hf3fs::core
|
||||
24
src/core/service/ops/GetConfigOperation.h
Normal file
24
src/core/service/ops/GetConfigOperation.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/app/ApplicationBase.h"
|
||||
#include "core/utils/ServiceOperation.h"
|
||||
#include "fbs/core/service/Rpc.h"
|
||||
|
||||
namespace hf3fs::core {
|
||||
|
||||
struct GetConfigOperation : ServiceOperationWithMetric<"CoreService", "GetConfig", "op"> {
|
||||
GetConfigReq req;
|
||||
|
||||
explicit GetConfigOperation(GetConfigReq r)
|
||||
: req(std::move(r)) {}
|
||||
|
||||
String toStringImpl() const final { return "GetConfig"; }
|
||||
|
||||
CoTryTask<GetConfigRsp> handle() {
|
||||
auto cfg = ApplicationBase::getConfigString(req.configKey);
|
||||
CO_RETURN_ON_ERROR(cfg);
|
||||
co_return GetConfigRsp::create(std::move(*cfg));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace hf3fs::core
|
||||
24
src/core/service/ops/GetLastConfigUpdateRecordOperation.h
Normal file
24
src/core/service/ops/GetLastConfigUpdateRecordOperation.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/app/ApplicationBase.h"
|
||||
#include "core/utils/ServiceOperation.h"
|
||||
#include "fbs/core/service/Rpc.h"
|
||||
|
||||
namespace hf3fs::core {
|
||||
|
||||
struct GetLastConfigUpdateRecordOperation
|
||||
: ServiceOperationWithMetric<"CoreService", "GetLastConfigUpdateRecord", "op"> {
|
||||
GetLastConfigUpdateRecordReq req;
|
||||
|
||||
explicit GetLastConfigUpdateRecordOperation(GetLastConfigUpdateRecordReq r)
|
||||
: req(std::move(r)) {}
|
||||
|
||||
String toStringImpl() const final { return "GetLastConfigUpdateRecord"; }
|
||||
|
||||
CoTryTask<GetLastConfigUpdateRecordRsp> handle() {
|
||||
auto res = ApplicationBase::getLastConfigUpdateRecord();
|
||||
co_return GetLastConfigUpdateRecordRsp::create(std::move(res));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace hf3fs::core
|
||||
24
src/core/service/ops/HotUpdateConfigOperation.h
Normal file
24
src/core/service/ops/HotUpdateConfigOperation.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/app/ApplicationBase.h"
|
||||
#include "core/utils/ServiceOperation.h"
|
||||
#include "fbs/core/service/Rpc.h"
|
||||
|
||||
namespace hf3fs::core {
|
||||
|
||||
struct HotUpdateConfigOperation : ServiceOperationWithMetric<"CoreService", "HotUpdateConfig", "op"> {
|
||||
HotUpdateConfigReq req;
|
||||
|
||||
explicit HotUpdateConfigOperation(HotUpdateConfigReq r)
|
||||
: req(std::move(r)) {}
|
||||
|
||||
String toStringImpl() const final { return "HotUpdateConfig"; }
|
||||
|
||||
CoTryTask<HotUpdateConfigRsp> handle() {
|
||||
auto res = ApplicationBase::hotUpdateConfig(req.update, req.render);
|
||||
CO_RETURN_ON_ERROR(res);
|
||||
co_return HotUpdateConfigRsp::create();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace hf3fs::core
|
||||
8
src/core/service/ops/Include.h
Normal file
8
src/core/service/ops/Include.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "EchoOperation.h"
|
||||
#include "GetConfigOperation.h"
|
||||
#include "GetLastConfigUpdateRecordOperation.h"
|
||||
#include "HotUpdateConfigOperation.h"
|
||||
#include "RenderConfigOperation.h"
|
||||
#include "ShutdownOperation.h"
|
||||
29
src/core/service/ops/RenderConfigOperation.h
Normal file
29
src/core/service/ops/RenderConfigOperation.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/app/ApplicationBase.h"
|
||||
#include "core/utils/ServiceOperation.h"
|
||||
#include "fbs/core/service/Rpc.h"
|
||||
|
||||
namespace hf3fs::core {
|
||||
|
||||
struct RenderConfigOperation : ServiceOperationWithMetric<"CoreService", "RenderConfig", "op"> {
|
||||
RenderConfigReq req;
|
||||
|
||||
explicit RenderConfigOperation(RenderConfigReq r)
|
||||
: req(std::move(r)) {}
|
||||
|
||||
String toStringImpl() const final { return "RenderConfig"; }
|
||||
|
||||
CoTryTask<RenderConfigRsp> handle() {
|
||||
auto res = ApplicationBase::renderConfig(req.configTemplate, req.testUpdate, req.isHotUpdate);
|
||||
CO_RETURN_ON_ERROR(res);
|
||||
auto &[content, updateRes] = *res;
|
||||
if (updateRes) {
|
||||
co_return RenderConfigRsp::create(std::move(content), Status(StatusCode::kOK), std::move(*updateRes));
|
||||
} else {
|
||||
co_return RenderConfigRsp::create(std::move(content), std::move(updateRes.error()));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace hf3fs::core
|
||||
24
src/core/service/ops/ShutdownOperation.h
Normal file
24
src/core/service/ops/ShutdownOperation.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/app/ApplicationBase.h"
|
||||
#include "common/utils/suicide.h"
|
||||
#include "core/utils/ServiceOperation.h"
|
||||
#include "fbs/core/service/Rpc.h"
|
||||
|
||||
namespace hf3fs::core {
|
||||
|
||||
struct ShutdownOperation : ServiceOperationWithMetric<"CoreService", "Shutdown", "op"> {
|
||||
ShutdownReq req_;
|
||||
|
||||
explicit ShutdownOperation(ShutdownReq req)
|
||||
: req_(std::move(req)) {}
|
||||
|
||||
String toStringImpl() const final { return "Shutdown"; }
|
||||
|
||||
CoTryTask<ShutdownRsp> handle() {
|
||||
CO_RETURN_ON_ERROR(suicide(req_.graceful));
|
||||
co_return ShutdownRsp::create();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace hf3fs::core
|
||||
Reference in New Issue
Block a user