예제 #1
0
SessionKiller::Result killSessionsLocalKillOps(OperationContext* opCtx,
                                               const SessionKiller::Matcher& matcher) {
    for (ServiceContext::LockedClientsCursor cursor(opCtx->getClient()->getServiceContext());
         Client* client = cursor.next();) {
        invariant(client);
        stdx::unique_lock<Client> lk(*client);

        OperationContext* opCtxToKill = client->getOperationContext();
        if (opCtxToKill) {
            const auto& lsid = opCtxToKill->getLogicalSessionId();

            if (lsid) {
                if (const KillAllSessionsByPattern* pattern = matcher.match(*lsid)) {
                    ScopedKillAllSessionsByPatternImpersonator impersonator(opCtx, *pattern);

                    log() << "killing op: " << opCtxToKill->getOpID()
                          << " as part of killing session: " << lsid->toBSON();

                    opCtx->getServiceContext()->killOperation(opCtxToKill);
                }
            }
        }
    }

    return {std::vector<HostAndPort>{}};
}
예제 #2
0
bool ServiceContextMongoD::_killOperationsAssociatedWithClientAndOpId_inlock(Client* client,
                                                                             unsigned int opId) {
    OperationContext* opCtx = client->getOperationContext();
    if (!opCtx) {
        return false;
    }
    if (opCtx->getOpID() != opId) {
        return false;
    }
    _killOperation_inlock(opCtx);
    return true;
}
예제 #3
0
bool ServiceContextMongoD::killOperation(unsigned int opId) {
    for (LockedClientsCursor cursor(this); Client* client = cursor.next();) {
        stdx::lock_guard<Client> lk(*client);

        OperationContext* opCtx = client->getOperationContext();
        if (opCtx && opCtx->getOpID() == opId) {
            _killOperation_inlock(opCtx, ErrorCodes::Interrupted);
            return true;
        }
    }

    return false;
}
예제 #4
0
void ServiceContextMongoD::killAllUserOperations(const OperationContext* txn,
                                                 ErrorCodes::Error killCode) {
    for (LockedClientsCursor cursor(this); Client* client = cursor.next();) {
        if (!client->isFromUserConnection()) {
            // Don't kill system operations.
            continue;
        }

        stdx::lock_guard<Client> lk(*client);
        OperationContext* toKill = client->getOperationContext();

        // Don't kill ourself.
        if (toKill && toKill->getOpID() != txn->getOpID()) {
            _killOperation_inlock(toKill, killCode);
        }
    }
}
예제 #5
0
파일: kill_op.cpp 프로젝트: ChineseDr/mongo
    static StatusWith<std::tuple<stdx::unique_lock<Client>, OperationContext*>> _findOp(
        ClientBasic* client, unsigned int opId) {
        AuthorizationSession* authzSession = AuthorizationSession::get(client);

        for (ServiceContext::LockedClientsCursor cursor(client->getServiceContext());
             Client* opClient = cursor.next();) {
            stdx::unique_lock<Client> lk(*opClient);

            OperationContext* opCtx = opClient->getOperationContext();
            if (opCtx && opCtx->getOpID() == opId) {
                if (authzSession->isAuthorizedForActionsOnResource(
                        ResourcePattern::forClusterResource(), ActionType::killop) ||
                    authzSession->isCoauthorizedWithClient(opClient)) {
                    return {std::make_tuple(std::move(lk), opCtx)};
                }
                break;
            }
        }

        return Status(ErrorCodes::NoSuchKey, str::stream() << "Could not access opID: " << opId);
    }