Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] curvefs/client: add base module. #2917

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
29 changes: 29 additions & 0 deletions curvefs/src/client/base/configure.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2023 NetEase Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Project: Curve
* Created Date: 2023-11-20
* Author: Jingli Chen (Wine93)
*/

namespace curvefs {
namespace client {
namespace base {

} // namespace base
} // namespace client
} // namespace curvefs
38 changes: 38 additions & 0 deletions curvefs/src/client/base/configure.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2023 NetEase Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Project: Curve
* Created Date: 2023-11-20
* Author: Jingli Chen (Wine93)
*/

// 配置管理器:
// (1) 动态配置需要支持所有配置项,足够灵活
// (2) 目前该模块主要用来控制日志采集器

#ifndef CURVEFS_SRC_CLIENT_BASE_CONFIGURE_H_
#define CURVEFS_SRC_CLIENT_BASE_CONFIGURE_H_

namespace curvefs {
namespace client {
namespace base {

} // namespace base
} // namespace client
} // namespace curvefs

#endif // CURVEFS_SRC_CLIENT_BASE_CONFIGURE_H_
Empty file.
43 changes: 43 additions & 0 deletions curvefs/src/client/base/log_sender.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2023 NetEase Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Project: Curve
* Created Date: 2023-11-20
* Author: Jingli Chen (Wine93)
*/

// 日志的采集器:
// (1) 需要支持 buffer
// (2) 配置可以指定多个后端地址,采用轮询进行负载
// (3) 并且发送需要有 retry 机制
// (4) 需要采集比例的可配置,如 4/100、100/100
// (5) 由于采集器的逻辑经常变更,可以考虑以插件的形式实现,以 so 加载或者 lua
// (6) 需要和 access log 和 perf_context 结合起来,日志要同时发送到文件与 TCP
// 实现不允许有冗余代码, 所以 log 的输出逻辑需要足够灵活,考虑采用 multi-sender

#ifndef CURVEFS_SRC_CLIENT_BASE_LOG_SENDER_H_
#define CURVEFS_SRC_CLIENT_BASE_LOG_SENDER_H_

namespace curvefs {
namespace client {
namespace base {

} // namespace base
} // namespace client
} // namespace curvefs

#endif // CURVEFS_SRC_CLIENT_BASE_LOG_SENDER_H_
130 changes: 130 additions & 0 deletions curvefs/src/client/base/metric.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* Copyright (c) 2023 NetEase Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Project: Curve
* Created Date: 2023-11-20
* Author: Jingli Chen (Wine93)
*/

#ifndef CURVEFS_SRC_CLIENT_BASE_METRIC_H_
#define CURVEFS_SRC_CLIENT_BASE_METRIC_H_

#include <string>

#include "curvefs/src/common/metric_utils.h"

namespace curvefs {
namespace client {
namespace base {

#define DEFINE_METRICS(seq) END(A seq)
#define BODY(x) OpMetric x = OpMetric(#x);
#define A(x) BODY(x) B
#define B(x) BODY(x) A
#define A_END
#define B_END
#define END(...) END_(__VA_ARGS__)
#define END_(...) __VA_ARGS__##_END

struct OpMetric {
static const std::string prefix = "fuse_ll_"

explicit OpMetric(const std::string& name)
ninflight(prefix, name + "_ninflight"),
nerror(prefix, name + "_nerror"),
latency(prefix, name + "_latency") {}

bvar::Adder<int64_t> ninflight;
bvar::Adder<uint64_t> nerror;
bvar::LatencyRecorder latency;
};

// OpMetric lookup = OpMetric("lookup");
// OpMetric getattr = OpMetric("getattr");
// ...
struct FuseLLOpMetric {
DEFINE_METRICS(
(lookup)
(getattr)
(setattr)
(readlink)
(mknod)
(mkdir)
(unlink)
(rmdir)
(symlink)
(rename)
(link)
(open)
(read)
(write)
(flush)
(release)
(fsync)
(opendir)
(readdir)
(readdirplus)
(releasedir)
(statfs)
(setxattr)
(getxattr)
(listxattr)
(create)
(bmap)
)

FuseLLOpMetric GetInstance() {
static FuseLLOpMetric instance;
return instance;
}
};

struct CodeGuard {
CodeGuard(bvar::Adder<uint64_t>* nerror, CURVEFS_ERROR* code)
: nerror(nerror), code(code) {}

~CodeGuard() {
if (*code != CURVEFS_ERROR::OK) {
(*nerror) << 1;
}
}

bvar::Adder<uint64_t>* nerror;
CURVEFS_ERROR* code;
};

struct MetricGuards {
explicit MetricGuards(OpMetric* metric, CURVEFS_ERROR* code)
: iGuard(&metric->ninflight),
cGuard(&metric->nerror, code),
lGuard(&metric->latency) {}

~MetricGuards() = default;

InflightGuard iGuard;
CodeGuard cGuard;
LatencyUpdater lGuard;
};

// NOTE: param rc is implicit
#define MetricGuard(OP) MetricGuards(&FuseLLOpMetric::GetInstance().OP, &rc);

} // namespace base
} // namespace client
} // namespace curvefs

#endif // CURVEFS_SRC_CLIENT_BASE_METRIC_H_
Empty file.
39 changes: 39 additions & 0 deletions curvefs/src/client/base/perf_context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2023 NetEase Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Project: Curve
* Created Date: 2023-11-20
* Author: Jingli Chen (Wine93)
*/

// perf context
// (1) 整体设计参考 rocksdb,需要更灵活
// (2) IO 链路上的请求需要尽可能细的拆分: memory, diskcache, s3, memcache
// (3) 元数据操作主要是 rpc(如果可以拆分网络和磁盘等更好)

#ifndef CURVEFS_SRC_CLIENT_BASE_PERF_CONTEXT_H_
#define CURVEFS_SRC_CLIENT_BASE_PERF_CONTEXT_H_

namespace curvefs {
namespace client {
namespace base {

} // namespace base
} // namespace client
} // namespace curvefs

#endif // CURVEFS_SRC_CLIENT_BASE_PERF_CONTEXT_H_