コード例 #1
0
Status ShardingCatalogClientImpl::updateShardingCatalogEntryForCollection(
    OperationContext* opCtx,
    const NamespaceString& nss,
    const CollectionType& coll,
    const bool upsert) {
    fassert(28634, coll.validate());

    auto status = _updateConfigDocument(opCtx,
                                        CollectionType::ConfigNS,
                                        BSON(CollectionType::fullNs(nss.ns())),
                                        coll.toBSON(),
                                        upsert,
                                        ShardingCatalogClient::kMajorityWriteConcern);
    return status.getStatus().withContext(str::stream() << "Collection metadata write failed");
}
コード例 #2
0
ファイル: catalog_manager.cpp プロジェクト: yongseoklee/mongo
Status CatalogManager::updateCollection(const std::string& collNs, const CollectionType& coll) {
    fassert(28634, coll.validate());

    BatchedCommandResponse response;
    Status status = update(CollectionType::ConfigNS,
                           BSON(CollectionType::fullNs(collNs)),
                           coll.toBSON(),
                           true,   // upsert
                           false,  // multi
                           &response);
    if (!status.isOK()) {
        return Status(status.code(),
                      str::stream() << "collection metadata write failed: " << response.toBSON()
                      << "; status: " << status.toString());
    }

    return Status::OK();
}
コード例 #3
0
    /**
     * Stores ranges for a particular collection and shard starting from some version
     */
    void storeCollectionRanges(const NamespaceString& nss,
                               const string& shardName,
                               const vector<KeyRange>& ranges,
                               const ChunkVersion& startVersion) {
        // Get key pattern from first range
        ASSERT_GREATER_THAN(ranges.size(), 0u);

        CollectionType coll;
        coll.setNs(nss);
        coll.setKeyPattern(ranges.begin()->keyPattern);
        coll.setEpoch(startVersion.epoch());
        coll.setUpdatedAt(Date_t::fromMillisSinceEpoch(1));
        ASSERT_OK(coll.validate());

        DBDirectClient client(&_txn);

        client.update(CollectionType::ConfigNS,
                      BSON(CollectionType::fullNs(coll.getNs().ns())),
                      coll.toBSON(),
                      true,
                      false);

        ChunkVersion nextVersion = startVersion;
        for (vector<KeyRange>::const_iterator it = ranges.begin(); it != ranges.end(); ++it) {
            ChunkType chunk;
            // TODO: We should not rely on the serialized ns, minkey being unique in the future,
            // causes problems since it links string serialization to correctness.
            chunk.setName(Chunk::genID(nss.ns(), it->minKey));
            chunk.setShard(shardName);
            chunk.setNS(nss.ns());
            chunk.setVersion(nextVersion);
            chunk.setMin(it->minKey);
            chunk.setMax(it->maxKey);
            nextVersion.incMajor();

            client.insert(ChunkType::ConfigNS, chunk.toBSON());
        }
    }