summaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/bucketdb/bucketsessionbase.cpp
blob: 81ce49b5b694b2e7d184c51ec178037d2d3accfe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "bucketsessionbase.h"

namespace proton::bucketdb {

BucketSessionBase::BucketSessionBase(BucketDBOwner &bucketDB, IBucketCreateNotifier &bucketCreateNotifier)
    : _bucketDB(bucketDB.takeGuard()),
      _bucketCreateNotifier(bucketCreateNotifier)
{
}


bool
BucketSessionBase::extractInfo(const BucketId &bucket, BucketState *&state)
{
    if (bucket.valid()) {
        state = _bucketDB->getBucketStatePtr(bucket);
    }
    return state && state->isActive();
}


bool
BucketSessionBase::calcFixupNeed(BucketState *state, bool wantActive,
                                 bool fixup)
{
    if (state && state->isActive() != wantActive) {
        if (fixup) {
            state->setActive(wantActive);
        }
        return state->getReadyCount() != 0;
    }
    return false;
}

}