本文整理汇总了C++中VersionType::toBSON方法的典型用法代码示例。如果您正苦于以下问题:C++ VersionType::toBSON方法的具体用法?C++ VersionType::toBSON怎么用?C++ VersionType::toBSON使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VersionType
的用法示例。
在下文中一共展示了VersionType::toBSON方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doUpgradeV0ToV7
/**
* Upgrade v0 to v7 described here
*
* This upgrade takes the config server from empty to an initial version.
*/
bool doUpgradeV0ToV7(CatalogManager* catalogManager,
const VersionType& lastVersionInfo,
string* errMsg) {
string dummy;
if (!errMsg)
errMsg = &dummy;
verify(lastVersionInfo.getCurrentVersion() == UpgradeHistory_EmptyVersion);
//
// Even though the initial config write is a single-document update, that single document
// is on multiple config servers and requests can interleave. The upgrade lock prevents
// this.
//
log() << "writing initial config version at v" << CURRENT_CONFIG_VERSION;
OID newClusterId = OID::gen();
VersionType versionInfo;
// Upgrade to new version
versionInfo.setMinCompatibleVersion(MIN_COMPATIBLE_CONFIG_VERSION);
versionInfo.setCurrentVersion(CURRENT_CONFIG_VERSION);
versionInfo.setClusterId(newClusterId);
verify(versionInfo.isValid(NULL));
// If the cluster has not previously been initialized, we need to set the version before
// using so subsequent mongoses use the config data the same way. This requires all three
// config servers online initially.
Status result = catalogManager->update(VersionType::ConfigNS,
BSON("_id" << 1),
versionInfo.toBSON(),
true, // upsert
false, // multi
NULL);
if (!result.isOK()) {
*errMsg = stream() << "error writing initial config version: " << result.reason();
return false;
}
return true;
}
示例2: if
/**
* Upgrade v3 to v4 described here.
*
* This upgrade takes a config server without collection epochs (potentially) and adds
* epochs to all mongo processes.
*
*/
bool doUpgradeV3ToV4(const ConnectionString& configLoc,
const VersionType& lastVersionInfo,
string* errMsg)
{
string dummy;
if (!errMsg) errMsg = &dummy;
verify(lastVersionInfo.getCurrentVersion() == UpgradeHistory_NoEpochVersion);
if (lastVersionInfo.isUpgradeIdSet() && lastVersionInfo.getUpgradeId().isSet()) {
//
// Another upgrade failed, so cleanup may be necessary
//
BSONObj lastUpgradeState = lastVersionInfo.getUpgradeState();
bool inCriticalSection;
if (!FieldParser::extract(lastUpgradeState,
inCriticalSectionField,
&inCriticalSection,
errMsg))
{
*errMsg = stream() << "problem reading previous upgrade state" << causedBy(errMsg);
return false;
}
if (inCriticalSection) {
// Manual intervention is needed here. Somehow our upgrade didn't get applied
// consistently across config servers.
*errMsg = cannotCleanupMessage;
return false;
}
if (!_cleanupUpgradeState(configLoc, lastVersionInfo.getUpgradeId(), errMsg)) {
// If we can't cleanup the old upgrade state, the user might have done it for us,
// not a fatal problem (we'll just end up with extra collections).
warning() << "could not cleanup previous upgrade state" << causedBy(errMsg) << endl;
*errMsg = "";
}
}
//
// Check the versions of other mongo processes in the cluster before upgrade.
// We can't upgrade if there are active pre-v2.2 processes in the cluster
//
Status mongoVersionStatus = checkClusterMongoVersions(configLoc,
string(minMongoProcessVersion));
if (!mongoVersionStatus.isOK()) {
*errMsg = stream() << "cannot upgrade with pre-v" << minMongoProcessVersion
<< " mongo processes active in the cluster"
<< causedBy(mongoVersionStatus);
return false;
}
VersionType newVersionInfo;
lastVersionInfo.cloneTo(&newVersionInfo);
// Set our upgrade id and state
OID upgradeId = OID::gen();
newVersionInfo.setUpgradeId(upgradeId);
newVersionInfo.setUpgradeState(BSONObj());
// Write our upgrade id and state
{
scoped_ptr<ScopedDbConnection> connPtr;
try {
connPtr.reset(ScopedDbConnection::getInternalScopedDbConnection(configLoc, 30));
ScopedDbConnection& conn = *connPtr;
verify(newVersionInfo.isValid(NULL));
conn->update(VersionType::ConfigNS,
BSON("_id" << 1 << VersionType::version_DEPRECATED(3)),
newVersionInfo.toBSON());
_checkGLE(conn);
}
catch (const DBException& e) {
*errMsg = stream() << "could not initialize version info for upgrade"
<< causedBy(e);
//.........这里部分代码省略.........
示例3: initConfigVersion
Status CatalogManagerReplicaSet::initConfigVersion(OperationContext* txn) {
for (int x = 0; x < kMaxConfigVersionInitRetry; x++) {
auto versionStatus = _getConfigVersion(txn);
if (!versionStatus.isOK()) {
return versionStatus.getStatus();
}
auto versionInfo = versionStatus.getValue();
if (versionInfo.getMinCompatibleVersion() > CURRENT_CONFIG_VERSION) {
return {ErrorCodes::IncompatibleShardingConfigVersion,
str::stream() << "current version v" << CURRENT_CONFIG_VERSION
<< " is older than the cluster min compatible v"
<< versionInfo.getMinCompatibleVersion()};
}
if (versionInfo.getCurrentVersion() == UpgradeHistory_EmptyVersion) {
VersionType newVersion;
newVersion.setClusterId(OID::gen());
newVersion.setMinCompatibleVersion(MIN_COMPATIBLE_CONFIG_VERSION);
newVersion.setCurrentVersion(CURRENT_CONFIG_VERSION);
BSONObj versionObj(newVersion.toBSON());
BatchedCommandResponse response;
auto upsertStatus = update(txn,
VersionType::ConfigNS,
versionObj,
versionObj,
true /* upsert*/,
false /* multi */,
&response);
if ((upsertStatus.isOK() && response.getN() < 1) ||
upsertStatus == ErrorCodes::DuplicateKey) {
// Do the check again as someone inserted a new config version document
// and the upsert neither inserted nor updated a config version document.
// Note: you can get duplicate key errors on upsert because of SERVER-14322.
continue;
}
return upsertStatus;
}
if (versionInfo.getCurrentVersion() == UpgradeHistory_UnreportedVersion) {
return {ErrorCodes::IncompatibleShardingConfigVersion,
"Assuming config data is old since the version document cannot be found in the "
"config server and it contains databases aside 'local' and 'admin'. "
"Please upgrade if this is the case. Otherwise, make sure that the config "
"server is clean."};
}
if (versionInfo.getCurrentVersion() < CURRENT_CONFIG_VERSION) {
return {ErrorCodes::IncompatibleShardingConfigVersion,
str::stream() << "need to upgrade current cluster version to v"
<< CURRENT_CONFIG_VERSION << "; currently at v"
<< versionInfo.getCurrentVersion()};
}
return Status::OK();
}
return {ErrorCodes::IncompatibleShardingConfigVersion,
str::stream() << "unable to create new config version document after "
<< kMaxConfigVersionInitRetry << " retries"};
}
示例4: storeConfigVersion
/**
* Stores a newer { version, minVersion, currentVersion, clusterId } config server entry
*/
void storeConfigVersion(const VersionType& versionInfo) {
DBDirectClient client(&_txn);
client.insert(VersionType::ConfigNS, versionInfo.toBSON());
}
示例5: storeConfigVersion
/**
* Stores a newer { version, minVersion, currentVersion, clusterId } config server entry
*/
void storeConfigVersion(const VersionType& versionInfo) {
client().insert(VersionType::ConfigNS, versionInfo.toBSON());
}