ChunkManagerPtr DBConfig::shardCollection( const string& ns , ShardKeyPattern fieldsAndOrder , bool unique ) { uassert( 8042 , "db doesn't have sharding enabled" , _shardingEnabled ); scoped_lock lk( _lock ); CollectionInfo& ci = _collections[ns]; uassert( 8043 , "collection already sharded" , ! ci.isSharded() ); log() << "enable sharding on: " << ns << " with shard key: " << fieldsAndOrder << endl; // From this point on, 'ns' is going to be treated as a sharded collection. We assume this is the first // time it is seen by the sharded system and thus create the first chunk for the collection. All the remaining // chunks will be created as a by-product of splitting. ci.shard( ns , fieldsAndOrder , unique ); ChunkManagerPtr cm = ci.getCM(); uassert( 13449 , "collections already sharded" , (cm->numChunks() == 0) ); cm->createFirstChunk( getPrimary() ); _save(); try { cm->maybeChunkCollection(); } catch ( UserException& e ) { // failure to chunk is not critical enough to abort the command (and undo the _save()'d configDB state) log() << "couldn't chunk recently created collection: " << ns << " " << e << endl; } return cm; }
void DBConfig::getAllShards(set<Shard>& shards) const { shards.insert(getPrimary()); for (Collections::const_iterator it(_collections.begin()), end(_collections.end()); it != end; ++it) { if (it->second.isSharded()) { it->second.getCM()->getAllShards(shards); } // TODO: handle collections on non-primary shard } }
GtkClipboard* PasteboardHelperGtk::getCurrentTarget(Frame* frame) const { WebKitWebView* webView = webkit_web_frame_get_web_view(kit(frame)); if (webkit_web_view_use_primary_for_paste(webView)) return getPrimary(frame); else return getClipboard(frame); }
void FEM_Node::print(const char *type,const IDXL_Print_Map &l2g) { super::print(type,l2g); CkPrintf("Node global numbers: * marks primary, () surrounds local-only:\n"); for(int i=0;i<size();i++) { if (getPrimary(i)) CkPrintf("*"); l2g.map(i); } CkPrintf("\n"); }
int MockReplicaSet::getState(const std::string& hostAndPort) const { if (_replConfig.count(hostAndPort) < 1) { return static_cast<int>(MemberState::RS_SHUNNED); } else if (hostAndPort == getPrimary()) { return static_cast<int>(MemberState::RS_PRIMARY); } else { return static_cast<int>(MemberState::RS_SECONDARY); } }
void FEMchunk::reduce_field(int fid, const void *nodes, void *outbuf, int op) { check("reduce_field precondition"); // first reduce over local nodes const IDXL_Layout &dt = IDXL_Layout_List::get().get(fid,"FEM_Reduce_field"); const unsigned char *src = (const unsigned char *)nodes; reduction_initialize(dt,outbuf,op); reduction_combine_fn fn=reduction_combine(dt,op); int nNodes=getMesh("reduce_field")->node.size(); for(int i=0; i<nNodes; i++) { if(getPrimary(i)) { fn((unsigned char *)outbuf, src, &dt); } src += dt.userBytes(); } // and now reduce over partitions reduce(fid, outbuf, outbuf, op); check("reduce_field postcondition"); }
void MockReplicaSet::mockIsMasterCmd() { // Copied from ReplSetImpl::_fillIsMaster for (ReplNodeMap::iterator nodeIter = _nodeMap.begin(); nodeIter != _nodeMap.end(); ++nodeIter) { const string& hostAndPort = nodeIter->first; BSONObjBuilder builder; builder.append("setName", _setName); ReplConfigMap::const_iterator configIter = _replConfig.find(hostAndPort); if (configIter == _replConfig.end()) { builder.append("ismaster", false); builder.append("secondary", false); vector<string> hostList; builder.append("hosts", hostList); } else { const bool isPrimary = hostAndPort == getPrimary(); builder.append("ismaster", isPrimary); builder.append("secondary", !isPrimary); { // TODO: add passives & arbiters vector<string> hostList; hostList.push_back(getPrimary()); const vector<string> secondaries = getSecondaries(); for (vector<string>::const_iterator secIter = secondaries.begin(); secIter != secondaries.end(); ++secIter) { hostList.push_back(*secIter); } builder.append("hosts", hostList); } builder.append("primary", getPrimary()); const ReplSetConfig::MemberCfg& replConfig = configIter->second; if (replConfig.arbiterOnly) { builder.append("arbiterOnly", true); } if (replConfig.priority == 0 && !replConfig.arbiterOnly) { builder.append("passive", true); } if (replConfig.slaveDelay) { builder.append("slaveDelay", replConfig.slaveDelay); } if (replConfig.hidden) { builder.append("hidden", true); } if (!replConfig.buildIndexes) { builder.append("buildIndexes", false); } if(!replConfig.tags.empty()) { BSONObjBuilder tagBuilder; for(map<string, string>::const_iterator tagIter = replConfig.tags.begin(); tagIter != replConfig.tags.end(); tagIter++) { tagBuilder.append(tagIter->first, tagIter->second); } builder.append("tags", tagBuilder.done()); } } builder.append("me", hostAndPort); builder.append("ok", true); nodeIter->second->setCommandReply("ismaster", builder.done()); } }
QString getPrimary(QString sTable) { return getPrimary(CurrentDatabase, sTable); }