aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/bucketdb/joinbucketssession.h
blob: 543b281e8533dba0a034a7288594b60dcbfb3f74 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "bucketsessionbase.h"

namespace proton::bucketdb {

class BucketDeltaPair;

/**
 * The JoinBucketsSession class bundles some temporary variables used
 * during a join operation, allowing for a cleaner API when calling
 * methods to perform some of the steps in the join operation.
 *
 * It sets up variables in the constructor, contains a few methods that
 * are forwarded to BucketDB with appropriate argument shuffling, and
 * also removes empty source buckets after join.
 *
 */
class JoinBucketsSession : public BucketSessionBase
{
private:
    BucketState _source1Delta;
    BucketState _source2Delta;
    bool _wantTargetActive;
    bool _adjustSource1ActiveLids;
    bool _adjustSource2ActiveLids;
    bool _adjustTargetActiveLids;
    BucketId _source1;
    BucketId _source2;
    BucketId _target;

    bool
    applyDelta(const BucketState &delta, BucketId &srcBucket, BucketState *dst);

public:
    JoinBucketsSession(BucketDBOwner &bucketDB,
                       IBucketCreateNotifier &bucketCreateNotifier,
                       const BucketId &source1,
                       const BucketId &source2,
                       const BucketId &target);

    void applyDeltas(const BucketDeltaPair &deltas);
    bool getWantTargetActive() const { return _wantTargetActive; }
    bool mustFixupTargetActiveLids(bool movedSource1Docs, bool movedSource2Docs) const;
    void setup();
    void finish();
    const BucketId & getSource1() const { return _source1; }
    const BucketId & getSource2() const { return _source2; }
    const BucketId & getTarget() const { return _target;}
};

}