Skip to content

Commit

Permalink
feat(fs): metaserver store applied index in kvstorage to prevent re-a…
Browse files Browse the repository at this point in the history
…pply

old metaserver snapshot that contain `inode` and `dentry` incompatible with new version

Signed-off-by: NaturalSelect <2145973003@qq.com>
  • Loading branch information
NaturalSelect committed Aug 18, 2023
1 parent 05993a9 commit e0d7fbf
Show file tree
Hide file tree
Showing 46 changed files with 3,161 additions and 1,899 deletions.
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ build --verbose_failures
build --define=with_glog=true --define=libunwind=true
build --copt -DHAVE_ZLIB=1 --copt -DGFLAGS_NS=google --copt -DUSE_BTHREAD_MUTEX
build --cxxopt -Wno-error=format-security
build:gcc7-later --cxxopt -faligned-new
build:gcc7-later --cxxopt -faligned-new --cxxopt -Wno-error=implicit-fallthrough
build --incompatible_blacklisted_protos_requires_proto_info=false
build --copt=-fdiagnostics-color=always

Expand Down
8 changes: 8 additions & 0 deletions curvefs/proto/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ message PartitionInfo {
optional bool manageFlag = 13; // if a partition has recyclebin inode, set this flag true
}

message AppliedIndex {
required int64 index = 1;
}

message ItemCount {
required uint64 count = 1;
}

message Peer {
optional uint64 id = 1;
optional string address = 2;
Expand Down
5 changes: 5 additions & 0 deletions curvefs/proto/metaserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ message PrepareRenameTxRequest {
repeated Dentry dentrys = 4;
}

message TransactionRequest {
required uint32 type = 1;
required string rawPayload = 2;
}

message PrepareRenameTxResponse {
required MetaStatusCode statusCode = 1;
optional uint64 appliedIndex = 2;
Expand Down
1 change: 1 addition & 0 deletions curvefs/src/metaserver/copyset/copyset_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ void CopysetNode::on_apply(braft::Iterator& iter) {
auto type = metaOperator->GetOperatorType();
auto task =
std::bind(&MetaOperator::OnApplyFromLog, metaOperator.release(),
iter.index(),
TimeUtility::GetTimeofDayUs());
applyQueue_->Push(hashcode, type, std::move(task));
timer.stop();
Expand Down
27 changes: 14 additions & 13 deletions curvefs/src/metaserver/copyset/meta_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,14 @@ void MetaOperator::FastApplyTask() {
auto task =
std::bind(&MetaOperator::OnApply, this, node_->GetAppliedIndex(),
new MetaOperatorClosure(this), TimeUtility::GetTimeofDayUs());
node_->GetApplyQueue()->Push(HashCode(),
GetOperatorType(), std::move(task));
node_->GetApplyQueue()->Push(HashCode(), GetOperatorType(),
std::move(task));
timer.stop();
g_concurrent_fast_apply_wait_latency << timer.u_elapsed();
}

#define OPERATOR_CAN_BY_PASS_PROPOSE(TYPE) \
bool TYPE##Operator::CanBypassPropose() const { \
return true; \
} \
bool TYPE##Operator::CanBypassPropose() const { return true; }

// below operator are readonly, so can enable lease read
OPERATOR_CAN_BY_PASS_PROPOSE(GetDentry);
Expand All @@ -154,7 +152,7 @@ OPERATOR_CAN_BY_PASS_PROPOSE(GetVolumeExtent);
timeUs - startTimeUs); \
auto status = node_->GetMetaStore()->TYPE( \
static_cast<const TYPE##Request *>(request_), \
static_cast<TYPE##Response *>(response_)); \
static_cast<TYPE##Response *>(response_), index); \
uint64_t executeTime = TimeUtility::GetTimeofDayUs() - timeUs; \
node_->GetMetric()->ExecuteLatency(OperatorType::TYPE, executeTime); \
if (status == MetaStatusCode::OK) { \
Expand Down Expand Up @@ -208,7 +206,8 @@ void GetOrModifyS3ChunkInfoOperator::OnApply(int64_t index,
{
brpc::ClosureGuard doneGuard(done);

rc = metastore->GetOrModifyS3ChunkInfo(request, response, &iterator);
rc = metastore->GetOrModifyS3ChunkInfo(request, response, &iterator,
index);
if (rc == MetaStatusCode::OK) {
node_->UpdateAppliedIndex(index);
response->set_appliedindex(
Expand Down Expand Up @@ -251,7 +250,7 @@ void GetVolumeExtentOperator::OnApply(int64_t index,
auto *response = static_cast<GetVolumeExtentResponse *>(response_);
auto *metaStore = node_->GetMetaStore();

auto st = metaStore->GetVolumeExtent(request, response);
auto st = metaStore->GetVolumeExtent(request, response, index);
node_->GetMetric()->OnOperatorComplete(
OperatorType::GetVolumeExtent,
TimeUtility::GetTimeofDayUs() - startTimeUs, st == MetaStatusCode::OK);
Expand Down Expand Up @@ -292,11 +291,11 @@ void GetVolumeExtentOperator::OnApply(int64_t index,
}

#define OPERATOR_ON_APPLY_FROM_LOG(TYPE) \
void TYPE##Operator::OnApplyFromLog(uint64_t startTimeUs) { \
void TYPE##Operator::OnApplyFromLog(int64_t index, uint64_t startTimeUs) { \
std::unique_ptr<TYPE##Operator> selfGuard(this); \
TYPE##Response response; \
auto status = node_->GetMetaStore()->TYPE( \
static_cast<const TYPE##Request *>(request_), &response); \
static_cast<const TYPE##Request *>(request_), &response, index); \
node_->GetMetric()->OnOperatorCompleteFromLog( \
OperatorType::TYPE, TimeUtility::GetTimeofDayUs() - startTimeUs, \
status == MetaStatusCode::OK); \
Expand All @@ -317,24 +316,26 @@ OPERATOR_ON_APPLY_FROM_LOG(UpdateDeallocatableBlockGroup);

#undef OPERATOR_ON_APPLY_FROM_LOG

void GetOrModifyS3ChunkInfoOperator::OnApplyFromLog(uint64_t startTimeUs) {
void GetOrModifyS3ChunkInfoOperator::OnApplyFromLog(int64_t index,
uint64_t startTimeUs) {
std::unique_ptr<GetOrModifyS3ChunkInfoOperator> selfGuard(this);
GetOrModifyS3ChunkInfoRequest request;
GetOrModifyS3ChunkInfoResponse response;
std::shared_ptr<Iterator> iterator;
request = *static_cast<const GetOrModifyS3ChunkInfoRequest *>(request_);
request.set_returns3chunkinfomap(false);
auto status = node_->GetMetaStore()->GetOrModifyS3ChunkInfo(
&request, &response, &iterator);
&request, &response, &iterator, index);
node_->GetMetric()->OnOperatorCompleteFromLog(
OperatorType::GetOrModifyS3ChunkInfo,
TimeUtility::GetTimeofDayUs() - startTimeUs,
status == MetaStatusCode::OK);
}

#define READONLY_OPERATOR_ON_APPLY_FROM_LOG(TYPE) \
void TYPE##Operator::OnApplyFromLog(uint64_t startTimeUs) { \
void TYPE##Operator::OnApplyFromLog(int64_t index, uint64_t startTimeUs) { \
(void)startTimeUs; \
(void)index; \
std::unique_ptr<TYPE##Operator> selfGuard(this); \
}

Expand Down
Loading

0 comments on commit e0d7fbf

Please sign in to comment.