本文整理汇总了C++中ReplicaSetConfig类的典型用法代码示例。如果您正苦于以下问题:C++ ReplicaSetConfig类的具体用法?C++ ReplicaSetConfig怎么用?C++ ReplicaSetConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ReplicaSetConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _dataReplicatorExternalState
OplogFetcher::OplogFetcher(executor::TaskExecutor* exec,
OpTimeWithHash lastFetched,
HostAndPort source,
NamespaceString oplogNSS,
ReplicaSetConfig config,
DataReplicatorExternalState* dataReplicatorExternalState,
EnqueueDocumentsFn enqueueDocumentsFn,
OnShutdownCallbackFn onShutdownCallbackFn)
: _dataReplicatorExternalState(dataReplicatorExternalState),
_fetcher(exec,
source,
oplogNSS.db().toString(),
makeFindCommandObject(dataReplicatorExternalState, oplogNSS, lastFetched.opTime),
stdx::bind(
&OplogFetcher::_callback, this, stdx::placeholders::_1, stdx::placeholders::_3),
uassertStatusOK(makeMetadataObject(config.getProtocolVersion() == 1LL)),
config.getElectionTimeoutPeriod()),
_enqueueDocumentsFn(enqueueDocumentsFn),
_awaitDataTimeout(calculateAwaitDataTimeout(config)),
_onShutdownCallbackFn(onShutdownCallbackFn),
_lastFetched(lastFetched) {
uassert(ErrorCodes::BadValue, "null last optime fetched", !lastFetched.opTime.isNull());
uassert(ErrorCodes::InvalidReplicaSetConfig,
"uninitialized replica set configuration",
config.isInitialized());
uassert(ErrorCodes::BadValue, "null enqueueDocuments function", enqueueDocumentsFn);
uassert(ErrorCodes::BadValue, "null onShutdownCallback function", onShutdownCallbackFn);
}
示例2: getReplCoord
void ReplCoordTest::simulateEnoughHeartbeatsForAllNodesUp() {
ReplicationCoordinatorImpl* replCoord = getReplCoord();
ReplicaSetConfig rsConfig = replCoord->getReplicaSetConfig_forTest();
NetworkInterfaceMock* net = getNet();
net->enterNetwork();
for (int i = 0; i < rsConfig.getNumMembers() - 1; ++i) {
const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest();
const RemoteCommandRequest& request = noi->getRequest();
log() << request.target.toString() << " processing " << request.cmdObj;
ReplSetHeartbeatArgsV1 hbArgs;
ReplSetHeartbeatArgs hbArgsPV0;
if (hbArgs.initialize(request.cmdObj).isOK() ||
hbArgsPV0.initialize(request.cmdObj).isOK()) {
ReplSetHeartbeatResponse hbResp;
hbResp.setSetName(rsConfig.getReplSetName());
hbResp.setState(MemberState::RS_SECONDARY);
hbResp.setConfigVersion(rsConfig.getConfigVersion());
hbResp.setAppliedOpTime(OpTime(Timestamp(100, 2), 0));
BSONObjBuilder respObj;
net->scheduleResponse(noi, net->now(), makeResponseStatus(hbResp.toBSON(true)));
} else {
error() << "Black holing unexpected request to " << request.target << ": "
<< request.cmdObj;
net->blackHole(noi);
}
net->runReadyNetworkOperations();
}
net->exitNetwork();
}
示例3: _setName
MockReplicaSet::MockReplicaSet(const string& setName, size_t nodes) : _setName(setName) {
BSONObjBuilder configBuilder;
configBuilder.append("_id", setName);
configBuilder.append("version", 1);
BSONArrayBuilder membersBuilder(configBuilder.subarrayStart("members"));
for (size_t n = 0; n < nodes; n++) {
std::stringstream str;
str << "$" << setName << n << ":27017";
const string hostName(str.str());
if (n == 0) {
_primaryHost = hostName;
}
MockRemoteDBServer* mockServer = new MockRemoteDBServer(hostName);
_nodeMap[hostName] = mockServer;
MockConnRegistry::get()->addServer(mockServer);
membersBuilder.append(BSON("_id" << static_cast<int>(n) << "host" << hostName));
}
membersBuilder.done();
ReplicaSetConfig replConfig;
fassert(28566, replConfig.initialize(configBuilder.obj()));
fassert(28573, replConfig.validate());
setConfig(replConfig);
}
示例4: getReplCoord
void ReplCoordTest::simulateSuccessfulV1Election() {
OperationContextReplMock txn;
ReplicationCoordinatorImpl* replCoord = getReplCoord();
NetworkInterfaceMock* net = getNet();
ReplicaSetConfig rsConfig = replCoord->getReplicaSetConfig_forTest();
ASSERT(replCoord->getMemberState().secondary()) << replCoord->getMemberState().toString();
while (!replCoord->getMemberState().primary()) {
log() << "Waiting on network in state " << replCoord->getMemberState();
getNet()->enterNetwork();
const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest();
const RemoteCommandRequest& request = noi->getRequest();
log() << request.target.toString() << " processing " << request.cmdObj;
ReplSetHeartbeatArgsV1 hbArgs;
Status status = hbArgs.initialize(request.cmdObj);
if (hbArgs.initialize(request.cmdObj).isOK()) {
ReplSetHeartbeatResponse hbResp;
hbResp.setSetName(rsConfig.getReplSetName());
hbResp.setState(MemberState::RS_SECONDARY);
hbResp.setConfigVersion(rsConfig.getConfigVersion());
net->scheduleResponse(noi, net->now(), makeResponseStatus(hbResp.toBSON(true)));
} else if (request.cmdObj.firstElement().fieldNameStringData() == "replSetRequestVotes") {
net->scheduleResponse(
noi,
net->now(),
makeResponseStatus(BSON("ok" << 1 << "reason"
<< ""
<< "term" << request.cmdObj["term"].Long()
<< "voteGranted" << true)));
} else if (request.cmdObj.firstElement().fieldNameStringData() ==
"replSetDeclareElectionWinner") {
net->scheduleResponse(
noi,
net->now(),
makeResponseStatus(BSON("ok" << 1 << "term" << request.cmdObj["term"].Long())));
} else {
error() << "Black holing unexpected request to " << request.target << ": "
<< request.cmdObj;
net->blackHole(noi);
}
net->runReadyNetworkOperations();
getNet()->exitNetwork();
}
ASSERT(replCoord->isWaitingForApplierToDrain());
ASSERT(replCoord->getMemberState().primary()) << replCoord->getMemberState().toString();
IsMasterResponse imResponse;
replCoord->fillIsMasterForReplSet(&imResponse);
ASSERT_FALSE(imResponse.isMaster()) << imResponse.toBSON().toString();
ASSERT_TRUE(imResponse.isSecondary()) << imResponse.toBSON().toString();
replCoord->signalDrainComplete(&txn);
replCoord->fillIsMasterForReplSet(&imResponse);
ASSERT_TRUE(imResponse.isMaster()) << imResponse.toBSON().toString();
ASSERT_FALSE(imResponse.isSecondary()) << imResponse.toBSON().toString();
ASSERT(replCoord->getMemberState().primary()) << replCoord->getMemberState().toString();
}
示例5: validateConfigForInitiate
StatusWith<int> validateConfigForInitiate(ReplicationCoordinatorExternalState* externalState,
const ReplicaSetConfig& newConfig) {
Status status = newConfig.validate();
if (!status.isOK()) {
return StatusWith<int>(status);
}
if (newConfig.getConfigVersion() != 1) {
return StatusWith<int>(ErrorCodes::NewReplicaSetConfigurationIncompatible,
str::stream() << "Configuration used to initiate a replica set must "
<< " have version 1, but found "
<< newConfig.getConfigVersion());
}
return findSelfInConfigIfElectable(externalState, newConfig);
}
示例6: _scheduleHeartbeatReconfig
void ReplicationCoordinatorImpl::_scheduleHeartbeatReconfig(const ReplicaSetConfig& newConfig) {
boost::lock_guard<boost::mutex> lk(_mutex);
if (_inShutdown) {
return;
}
switch (_rsConfigState) {
case kConfigStartingUp:
LOG(1) << "Ignoring new configuration with version " << newConfig.getConfigVersion() <<
" because still attempting to load local configuration information";
return;
case kConfigUninitialized:
case kConfigSteady:
LOG(1) << "Received new config via heartbeat with version " <<
newConfig.getConfigVersion();
break;
case kConfigInitiating:
case kConfigReconfiguring:
case kConfigHBReconfiguring:
LOG(1) << "Ignoring new configuration with version " << newConfig.getConfigVersion() <<
" because already in the midst of a configuration process";
return;
default:
severe() << "Reconfiguration request occurred while _rsConfigState == " <<
int(_rsConfigState) << "; aborting.";
fassertFailed(18807);
}
_setConfigState_inlock(kConfigHBReconfiguring);
invariant(!_rsConfig.isInitialized() ||
_rsConfig.getConfigVersion() < newConfig.getConfigVersion());
if (_freshnessChecker) {
_freshnessChecker->cancel(&_replExecutor);
if (_electCmdRunner) {
_electCmdRunner->cancel(&_replExecutor);
}
_replExecutor.onEvent(
_electionFinishedEvent,
stdx::bind(&ReplicationCoordinatorImpl::_heartbeatReconfigAfterElectionCanceled,
this,
stdx::placeholders::_1,
newConfig));
return;
}
_replExecutor.scheduleDBWork(stdx::bind(
&ReplicationCoordinatorImpl::_heartbeatReconfigStore,
this,
stdx::placeholders::_1,
newConfig));
}
示例7: validateConfigForStartUp
StatusWith<int> validateConfigForStartUp(ReplicationCoordinatorExternalState* externalState,
const ReplicaSetConfig& oldConfig,
const ReplicaSetConfig& newConfig) {
Status status = newConfig.validate();
if (!status.isOK()) {
return StatusWith<int>(status);
}
if (oldConfig.isInitialized()) {
status = validateOldAndNewConfigsCompatible(oldConfig, newConfig);
if (!status.isOK()) {
return StatusWith<int>(status);
}
}
return findSelfInConfig(externalState, newConfig);
}
示例8: checkQuorumForReconfig
Status checkQuorumForReconfig(ReplicationExecutor* executor,
const ReplicaSetConfig& rsConfig,
const int myIndex) {
invariant(rsConfig.getConfigVersion() > 1);
QuorumChecker checker(&rsConfig, myIndex);
return checker.run(executor);
}
示例9: _heartbeatReconfigStore
void ReplicationCoordinatorImpl::_heartbeatReconfigStore(const ReplicaSetConfig& newConfig) {
{
boost::scoped_ptr<OperationContext> txn(_externalState->createOperationContext());
Status status = _externalState->storeLocalConfigDocument(txn.get(), newConfig.toBSON());
if (!status.isOK()) {
error() << "Ignoring new configuration in heartbeat response because we failed to"
" write it to stable storage; " << status;
boost::lock_guard<boost::mutex> lk(_mutex);
invariant(_rsConfigState == kConfigHBReconfiguring);
if (_rsConfig.isInitialized()) {
_setConfigState_inlock(kConfigSteady);
}
else {
// This is the _only_ case where we can return to kConfigUninitialized from
// kConfigHBReconfiguring.
_setConfigState_inlock(kConfigUninitialized);
}
return;
}
}
const StatusWith<int> myIndex = validateConfigForHeartbeatReconfig(
_externalState.get(),
newConfig);
_replExecutor.scheduleWork(stdx::bind(&ReplicationCoordinatorImpl::_heartbeatReconfigFinish,
this,
stdx::placeholders::_1,
newConfig,
myIndex));
}
示例10: _heartbeatReconfigFinish
void ReplicationCoordinatorImpl::_heartbeatReconfigFinish(
const ReplicationExecutor::CallbackData& cbData,
const ReplicaSetConfig& newConfig,
StatusWith<int> myIndex) {
boost::lock_guard<boost::mutex> lk(_mutex);
invariant(_rsConfigState == kConfigHBReconfiguring);
invariant(!_rsConfig.isInitialized() ||
_rsConfig.getConfigVersion() < newConfig.getConfigVersion());
if (!myIndex.isOK()) {
switch (myIndex.getStatus().code()) {
case ErrorCodes::NoSuchKey:
log() << "Cannot find self in new replica set configuration; I must be removed; " <<
myIndex.getStatus();
break;
case ErrorCodes::DuplicateKey:
error() << "Several entries in new config represent this node; "
"Removing self until an acceptable configuration arrives; " <<
myIndex.getStatus();
break;
default:
error() << "Could not validate configuration received from remote node; "
"Removing self until an acceptable configuration arrives; " <<
myIndex.getStatus();
break;
}
myIndex = StatusWith<int>(-1);
}
_setCurrentRSConfig_inlock(newConfig, myIndex.getValue());
}
示例11: validateConfigForHeartbeatReconfig
StatusWith<int> validateConfigForHeartbeatReconfig(
ReplicationCoordinatorExternalState* externalState, const ReplicaSetConfig& newConfig) {
Status status = newConfig.validate();
if (!status.isOK()) {
return StatusWith<int>(status);
}
return findSelfInConfig(externalState, newConfig);
}
示例12: getNet
void ReplCoordTest::replyToReceivedHeartbeatV1() {
NetworkInterfaceMock* net = getNet();
net->enterNetwork();
const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest();
const RemoteCommandRequest& request = noi->getRequest();
const ReplicaSetConfig rsConfig = getReplCoord()->getReplicaSetConfig_forTest();
repl::ReplSetHeartbeatArgsV1 hbArgs;
ASSERT_OK(hbArgs.initialize(request.cmdObj));
repl::ReplSetHeartbeatResponse hbResp;
hbResp.setSetName(rsConfig.getReplSetName());
hbResp.setState(MemberState::RS_SECONDARY);
hbResp.setConfigVersion(rsConfig.getConfigVersion());
BSONObjBuilder respObj;
respObj << "ok" << 1;
hbResp.addToBSON(&respObj, false);
net->scheduleResponse(noi, net->now(), makeResponseStatus(respObj.obj()));
net->runReadyNetworkOperations();
getNet()->exitNetwork();
}
示例13: Algorithm
StatusWith<ReplicationExecutor::EventHandle> FreshnessChecker::start(
ReplicationExecutor* executor,
const Timestamp& lastOpTimeApplied,
const ReplicaSetConfig& currentConfig,
int selfIndex,
const std::vector<HostAndPort>& targets) {
_originalConfigVersion = currentConfig.getConfigVersion();
_algorithm.reset(new Algorithm(lastOpTimeApplied, currentConfig, selfIndex, targets));
_runner.reset(new ScatterGatherRunner(_algorithm.get(), executor));
return _runner->start();
}
示例14: _heartbeatReconfigFinish
void ReplicationCoordinatorImpl::_heartbeatReconfigFinish(
const ReplicationExecutor::CallbackArgs& cbData,
const ReplicaSetConfig& newConfig,
StatusWith<int> myIndex) {
if (cbData.status == ErrorCodes::CallbackCanceled) {
return;
}
stdx::unique_lock<stdx::mutex> lk(_mutex);
invariant(_rsConfigState == kConfigHBReconfiguring);
invariant(!_rsConfig.isInitialized() ||
_rsConfig.getConfigVersion() < newConfig.getConfigVersion());
if (_getMemberState_inlock().primary() && !cbData.txn) {
// Not having an OperationContext in the CallbackData means we definitely aren't holding
// the global lock. Since we're primary and this reconfig could cause us to stepdown,
// reschedule this work with the global exclusive lock so the stepdown is safe.
// TODO(spencer): When we *do* have an OperationContext, consult it to confirm that
// we are indeed holding the global lock.
_replExecutor.scheduleWorkWithGlobalExclusiveLock(
stdx::bind(&ReplicationCoordinatorImpl::_heartbeatReconfigFinish,
this,
stdx::placeholders::_1,
newConfig,
myIndex));
return;
}
if (!myIndex.isOK()) {
switch (myIndex.getStatus().code()) {
case ErrorCodes::NodeNotFound:
log() << "Cannot find self in new replica set configuration; I must be removed; "
<< myIndex.getStatus();
break;
case ErrorCodes::DuplicateKey:
error() << "Several entries in new config represent this node; "
"Removing self until an acceptable configuration arrives; "
<< myIndex.getStatus();
break;
default:
error() << "Could not validate configuration received from remote node; "
"Removing self until an acceptable configuration arrives; "
<< myIndex.getStatus();
break;
}
myIndex = StatusWith<int>(-1);
}
const PostMemberStateUpdateAction action =
_setCurrentRSConfig_inlock(cbData, newConfig, myIndex.getValue());
lk.unlock();
_resetElectionInfoOnProtocolVersionUpgrade(newConfig);
_performPostMemberStateUpdateAction(action);
}
示例15: validateConfigForReconfig
StatusWith<int> validateConfigForReconfig(ReplicationCoordinatorExternalState* externalState,
const ReplicaSetConfig& oldConfig,
const ReplicaSetConfig& newConfig,
bool force) {
Status status = newConfig.validate();
if (!status.isOK()) {
return StatusWith<int>(status);
}
status = validateOldAndNewConfigsCompatible(oldConfig, newConfig);
if (!status.isOK()) {
return StatusWith<int>(status);
}
if (force) {
return findSelfInConfig(externalState, newConfig);
}
return findSelfInConfigIfElectable(externalState, newConfig);
}