Exemplo n.º 1
0
void fillWriterVectors(const std::deque<BSONObj>& ops,
                       std::vector<std::vector<BSONObj>>* writerVectors) {
    for (std::deque<BSONObj>::const_iterator it = ops.begin(); it != ops.end(); ++it) {
        const BSONElement e = it->getField("ns");
        verify(e.type() == String);
        const char* ns = e.valuestr();
        int len = e.valuestrsize();
        uint32_t hash = 0;
        MurmurHash3_x86_32(ns, len, 0, &hash);

        const char* opType = it->getField("op").valuestrsafe();

        if (getGlobalServiceContext()->getGlobalStorageEngine()->supportsDocLocking() &&
            isCrudOpType(opType)) {
            BSONElement id;
            switch (opType[0]) {
                case 'u':
                    id = it->getField("o2").Obj()["_id"];
                    break;
                case 'd':
                case 'i':
                    id = it->getField("o").Obj()["_id"];
                    break;
            }

            const size_t idHash = BSONElement::Hasher()(id);
            MurmurHash3_x86_32(&idHash, sizeof(idHash), hash, &hash);
        }

        (*writerVectors)[hash % writerVectors->size()].push_back(*it);
    }
}
Exemplo n.º 2
0
BSONElement OplogEntry::getIdElement() const {
    invariant(isCrudOpType());
    if (getOpType() == OpTypeEnum::kUpdate) {
        // We cannot use getOperationToApply() here because the BSONObj will go out out of scope
        // after we return the BSONElement.
        return getObject2()->getField("_id");
    } else {
        return getObject()["_id"];
    }
}
Exemplo n.º 3
0
BSONElement OplogEntry::getIdElement() const {
    invariant(isCrudOpType());
    switch (opType[0]) {
        case 'u':
            return o2.Obj()["_id"];
        case 'd':
        case 'i':
            return o.Obj()["_id"];
    }
    MONGO_UNREACHABLE;
}
Exemplo n.º 4
0
bool OplogEntry::isCrudOpType() const {
    return isCrudOpType(getOpType());
}