Status reloadShardRegistryUntilSuccess(OperationContext* txn) { if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) { return Status::OK(); } while (!inShutdown()) { auto stopStatus = txn->checkForInterruptNoAssert(); if (!stopStatus.isOK()) { return stopStatus; } try { auto clusterIdentity = ClusterIdentityLoader::get(txn); auto clusterId = clusterIdentity->getClusterId(txn); if (!clusterId.isOK()) { warning() << "Error initializing sharding state, sleeping for 2 seconds and trying again" << causedBy(clusterId.getStatus()); sleepmillis(2000); continue; } grid.shardRegistry()->reload(txn); return Status::OK(); } catch (const DBException& ex) { Status status = ex.toStatus(); if (status == ErrorCodes::ReplicaSetNotFound) { // ReplicaSetNotFound most likely means we've been waiting for the config replica // set to come up for so long that the ReplicaSetMonitor stopped monitoring the set. // Rebuild the config shard to force the monitor to resume monitoring the config // servers. grid.shardRegistry()->rebuildConfigShard(); } warning() << "Error initializing sharding state, sleeping for 2 seconds and trying again" << causedBy(status); sleepmillis(2000); continue; } } return {ErrorCodes::ShutdownInProgress, "aborting shard loading attempt"}; }
std::unique_ptr<BatchedUpdateRequest> ShardIdentityType::createUpsertForAddShard() const { invariant(validate().isOK()); std::unique_ptr<BatchedUpdateDocument> updateDoc(new BatchedUpdateDocument()); BSONObjBuilder query; query.append("_id", "shardIdentity"); query.append("shardName", getShardName()); query.append("clusterId", getClusterId()); updateDoc->setQuery(query.obj()); BSONObjBuilder update; BSONObjBuilder setConfigBuilder(update.subobjStart("$set")); setConfigBuilder.append(configsvrConnString(), getConfigsvrConnString().toString()); setConfigBuilder.doneFast(); updateDoc->setUpdateExpr(update.obj()); updateDoc->setUpsert(true); std::unique_ptr<BatchedUpdateRequest> updateRequest(new BatchedUpdateRequest()); updateRequest->addToUpdates(updateDoc.release()); return updateRequest; }
void AnnotatedCluster::addParent(node* parentnode, AnnotatedClusterAbstraction* aca) { if(parentnode->getParentCluster() != -1) { if(parentnode->getParentCluster() != this->getClusterId()) throw NodeIsAlreadyAssignedToClusterException(parentnode, this); else { std::cout << "\nWARNING: skipping parent node @ ("<<parentnode->getLabelL(kFirstData)<<","<<parentnode->getLabelL(kFirstData+1)<<"); already belongs to cluster "<<getClusterId()<<std::endl; return; } } else parentnode->setParentCluster(this->getClusterId()); this->connectEntranceEndpoints(parentnode,aca); Cluster::addParent(parentnode); }