Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

feat: add partition guardian to keep one primary and two secondaries #847

Merged
merged 2 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 79 additions & 0 deletions src/meta/partition_guardian.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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.

#include "partition_guardian.h"
namespace dsn {
namespace replication {
partition_guardian::partition_guardian(meta_service *svc) : _svc(svc) {}

pc_status partition_guardian::cure(meta_view view,
const dsn::gpid &gpid,
configuration_proposal_action &action)
{
if (from_proposals(view, gpid, action))
return pc_status::ill;

std::shared_ptr<app_state> &app = (*view.apps)[gpid.get_app_id()];
const partition_configuration &pc = *get_config(*(view.apps), gpid);
const proposal_actions &acts = get_config_context(*view.apps, gpid)->lb_actions;

dassert(app->is_stateful, "");
dassert(acts.empty(), "");

pc_status status;
if (pc.primary.is_invalid())
status = on_missing_primary(view, gpid);
else if (static_cast<int>(pc.secondaries.size()) + 1 < pc.max_replica_count)
status = on_missing_secondary(view, gpid);
else if (static_cast<int>(pc.secondaries.size()) >= pc.max_replica_count)
status = on_redundant_secondary(view, gpid);
else
status = pc_status::healthy;

if (!acts.empty()) {
action = *acts.front();
}
return status;
}

bool partition_guardian::from_proposals(meta_view &view,
const dsn::gpid &gpid,
configuration_proposal_action &action)
{
// TBD(zlw)
return false;
}

pc_status partition_guardian::on_missing_primary(meta_view &view, const dsn::gpid &gpid)
{
// TBD(zlw)
return pc_status::invalid;
}

pc_status partition_guardian::on_missing_secondary(meta_view &view, const dsn::gpid &gpid)
{
// TBD(zlw)
return pc_status::invalid;
}

pc_status partition_guardian::on_redundant_secondary(meta_view &view, const dsn::gpid &gpid)
{
// TBD(zlw)
return pc_status::invalid;
}
} // namespace replication
} // namespace dsn
45 changes: 45 additions & 0 deletions src/meta/partition_guardian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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.

#pragma once

#include "meta_data.h"

namespace dsn {
namespace replication {
class meta_service;

class partition_guardian
{
public:
explicit partition_guardian(meta_service *svc);
~partition_guardian() = default;

pc_status cure(meta_view view, const dsn::gpid &gpid, configuration_proposal_action &action);

private:
bool
from_proposals(meta_view &view, const dsn::gpid &gpid, configuration_proposal_action &action);
pc_status on_missing_primary(meta_view &view, const dsn::gpid &gpid);
pc_status on_missing_secondary(meta_view &view, const dsn::gpid &gpid);
pc_status on_redundant_secondary(meta_view &view, const dsn::gpid &gpid);

meta_service *_svc;
};

} // namespace replication
} // namespace dsn