aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/bucketdb/bucketsessionbase.cpp
blob: b23fd69631e2aba4915ca0eec2381438df703a97 (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
38
39
// Copyright Vespa.ai. 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)
{
}

BucketSessionBase::~BucketSessionBase() {
    _bucketDB->restoreIntegrity();
}

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;
}

}