aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/server/forcecommitcontext.h
blob: f79ccccd1bdf2aae205ef3eda39c458a8b67954d (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/searchcore/proton/common/pendinglidtracker.h>
#include <vespa/vespalib/util/idestructorcallback.h>

namespace vespalib { class Executor; }

namespace proton {

class ForceCommitDoneTask;
struct IDocumentMetaStore;
class DocIdLimit;
class IPendingGidToLidChanges;

/**
 * Context class for forced commits that schedules a task when
 * instance is destroyed. Typically a shared pointer to an instance is
 * passed around to multiple worker threads that performs portions of
 * a larger task before dropping the shared pointer, triggering the
 * callback when all worker threads have completed.
 */
class ForceCommitContext : public vespalib::IDestructorCallback
{
    using IDestructorCallback = vespalib::IDestructorCallback;
    vespalib::Executor                   &_executor;
    std::unique_ptr<ForceCommitDoneTask>  _task;
    uint32_t                              _committedDocIdLimit;
    DocIdLimit                           *_docIdLimit;
    std::shared_ptr<IDestructorCallback>  _onDone;
    PendingLidTrackerBase::Snapshot       _lidsToCommit;

public:
    ForceCommitContext(vespalib::Executor &executor,
                       IDocumentMetaStore &documentMetaStore,
                       PendingLidTrackerBase::Snapshot lidsToCommit,
                       std::unique_ptr<IPendingGidToLidChanges> pending_gid_to_lid_changes,
                       std::shared_ptr<IDestructorCallback> onDone);

    ~ForceCommitContext() override;

    void reuseLids(std::vector<uint32_t> &&lids);
    void holdUnblockShrinkLidSpace();
    void registerCommittedDocIdLimit(uint32_t committedDocIdLimit, DocIdLimit *docIdLimit);
};

}  // namespace proton