int finalize() {
        invariant(!_finalized);
        _finalized = true;

        _numReaped += removeSessionsRecords(_opCtx, _sessionsCollection, _batch);
        return _numReaped;
    }
Exemple #2
0
    void handleLsid(const LogicalSessionId& lsid) {
        // There are some lifetime issues with when the reaper starts up versus when the grid is
        // available.  Moving routing info fetching until after we have a transaction moves us past
        // the problem.
        //
        // Also, we should only need the chunk case, but that'll wait until the sessions table is
        // actually sharded.
        if (!(_cm || _primary)) {
            auto routingInfo =
                uassertStatusOK(Grid::get(_opCtx)->catalogCache()->getCollectionRoutingInfo(
                    _opCtx, SessionsCollection::kSessionsNamespaceString));
            _cm = routingInfo.cm();
            _primary = routingInfo.db().primary();
        }

        ShardId shardId;
        if (_cm) {
            const auto chunk = _cm->findIntersectingChunkWithSimpleCollation(lsid.toBSON());
            shardId = chunk.getShardId();
        } else {
            shardId = _primary->getId();
        }

        auto& lsids = _shards[shardId];
        lsids.insert(lsid);

        if (lsids.size() > write_ops::kMaxWriteBatchSize) {
            _numReaped += removeSessionsRecords(_opCtx, _sessionsCollection, lsids);
            _shards.erase(shardId);
        }
    }
    void handleLsid(const LogicalSessionId& lsid) {
        _batch.insert(lsid);

        if (_batch.size() >= write_ops::kMaxWriteBatchSize) {
            _numReaped += removeSessionsRecords(_opCtx, _sessionsCollection, _batch);
            _batch.clear();
        }
    }
    int finalize() {
        invariant(!_finalized);
        _finalized = true;

        for (const auto& pair : _shards) {
            _numReaped += removeSessionsRecords(_opCtx, _sessionsCollection, pair.second);
        }

        return _numReaped;
    }
    void handleLsid(const LogicalSessionId& lsid) {
        invariant(_cm);
        const auto chunk = _cm->findIntersectingChunkWithSimpleCollation(lsid.toBSON());
        const auto shardId = chunk.getShardId();

        auto& lsids = _shards[shardId];
        lsids.insert(lsid);

        if (lsids.size() >= write_ops::kMaxWriteBatchSize) {
            _numReaped += removeSessionsRecords(_opCtx, _sessionsCollection, lsids);
            _shards.erase(shardId);
        }
    }