Exemple #1
0
// TODO change the passed in function to be multiapply instead of apply inlock
void MultiApplier::_callback(const ReplicationExecutor::CallbackArgs& cbd) {
    if (!cbd.status.isOK()) {
        _finishCallback(cbd.status, _operations);
        return;
    }

    invariant(cbd.txn);

    // Refer to multiSyncApply() and multiInitialSyncApply() in sync_tail.cpp.
    cbd.txn->setReplicatedWrites(false);

    // allow us to get through the magic barrier
    cbd.txn->lockState()->setIsBatchWriter(true);

    StatusWith<OpTime> applyStatus(ErrorCodes::InternalError, "not mutated");

    invariant(!_operations.empty());
    try {
        // TODO restructure to support moving _operations into this call. Can't do it today since
        // _finishCallback gets _operations on failure.
        applyStatus = _multiApply(cbd.txn, _operations, _applyOperation);
    } catch (...) {
        applyStatus = exceptionToStatus();
    }
    if (!applyStatus.isOK()) {
        _finishCallback(applyStatus.getStatus(), _operations);
        return;
    }
    _finishCallback(applyStatus.getValue().getTimestamp(), Operations());
}
Exemple #2
0
void MultiApplier::_callback(const executor::TaskExecutor::CallbackArgs& cbd) {
    if (!cbd.status.isOK()) {
        _finishCallback(cbd.status, _operations);
        return;
    }

    invariant(!_operations.empty());

    StatusWith<OpTime> applyStatus(ErrorCodes::InternalError, "not mutated");
    try {
        auto txn = cc().makeOperationContext();

        // Refer to multiSyncApply() and multiInitialSyncApply() in sync_tail.cpp.
        txn->setReplicatedWrites(false);

        // allow us to get through the magic barrier
        txn->lockState()->setIsBatchWriter(true);

        applyStatus = _multiApply(txn.get(), _operations, _applyOperation);
    } catch (...) {
        applyStatus = exceptionToStatus();
    }
    if (!applyStatus.isOK()) {
        _finishCallback(applyStatus.getStatus(), _operations);
        return;
    }
    _finishCallback(applyStatus.getValue().getTimestamp(), _operations);
}
StatusWith<OpTime> OplogApplier::multiApply(OperationContext* opCtx, Operations ops) {
    _observer->onBatchBegin(ops);
    auto lastApplied = _multiApply(opCtx, std::move(ops));
    _observer->onBatchEnd(lastApplied, {});
    return lastApplied;
}