summaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/persistence/persistencehandler.h
blob: 9639b772a2871ca5dffd2fb6a4c051abd1862a57 (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
55
56
57
58
59
60
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "processallhandler.h"
#include "mergehandler.h"
#include "asynchandler.h"
#include "persistenceutil.h"
#include "splitjoinhandler.h"
#include "simplemessagehandler.h"
#include <vespa/storage/common/storagecomponent.h>
#include <vespa/vespalib/util/isequencedtaskexecutor.h>
#include <vespa/config-stor-filestor.h>
#include <atomic>

namespace storage {

class BucketOwnershipNotifier;

/**
 * Handle all messages destined for the persistence layer. The detailed handling
 * happens in other handlers, but is forked out after common setup has been done.
 * Currently metrics are updated so each thread should have its own instance.
 */
class PersistenceHandler : public Types
{
public:
    PersistenceHandler(vespalib::ISequencedTaskExecutor &, const ServiceLayerComponent & component,
                      const vespa::config::content::StorFilestorConfig &, spi::PersistenceProvider &,
                      FileStorHandler &, BucketOwnershipNotifier &, FileStorThreadMetrics&);
    ~PersistenceHandler();

    void processLockedMessage(FileStorHandler::LockedMessage lock) const;

    //TODO Rewrite tests to avoid this api leak
    const AsyncHandler & asyncHandler() const { return _asyncHandler; }
    const SplitJoinHandler & splitjoinHandler() const { return _splitJoinHandler; }
    const SimpleMessageHandler & simpleMessageHandler() const { return _simpleHandler; }

    void set_throttle_merge_feed_ops(bool throttle) noexcept;
    void set_use_per_document_throttled_delete_bucket(bool throttle) noexcept;
private:
    // Message handling functions
    MessageTracker::UP handleCommandSplitByType(api::StorageCommand&, MessageTracker::UP tracker) const;
    MessageTracker::UP handleReply(api::StorageReply&, MessageTracker::UP) const;

    MessageTracker::UP processMessage(api::StorageMessage& msg, MessageTracker::UP tracker) const;
    [[nodiscard]] bool use_per_op_throttled_delete_bucket() const noexcept;

    const framework::Clock  & _clock;
    PersistenceUtil           _env;
    ProcessAllHandler         _processAllHandler;
    MergeHandler              _mergeHandler;
    AsyncHandler              _asyncHandler;
    SplitJoinHandler          _splitJoinHandler;
    SimpleMessageHandler      _simpleHandler;
    std::atomic<bool>         _use_per_op_throttled_delete_bucket;
};

} // storage