summaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/storageserver/opslogger.h
blob: cf39f51279d542c18a91f67dfe307346cfeabc84 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

/**
 * \class storage::OpsLogger
 *
 * \brief Storage link that can be configured to log all storage operations to
 * a file.
*/
#pragma once

#include <vespa/storage/common/storagelink.h>
#include <vespa/storage/common/storagecomponent.h>
#include <vespa/storageapi/messageapi/storagemessage.h>
#include <vespa/storageapi/message/state.h>
#include <vespa/storage/config/config-stor-opslogger.h>
#include <vespa/config/config.h>

namespace storage {

class OpsLogger : public StorageLink,
                  public config::IFetcherCallback<vespa::config::content::core::StorOpsloggerConfig> {
public:
    explicit OpsLogger(StorageComponentRegister&,
                       const config::ConfigUri & configUri);
    ~OpsLogger() override;

    void onClose() override;
    void print(std::ostream& out, bool verbose, const std::string& indent) const override;
    bool onPutReply(const std::shared_ptr<api::PutReply>& msg) override;
    bool onUpdateReply(const std::shared_ptr<api::UpdateReply>& msg) override;
    bool onRemoveReply(const std::shared_ptr<api::RemoveReply>& msg) override;
    bool onGetReply(const std::shared_ptr<api::GetReply>& msg) override;

    /** Ignore all replies on the way down the storage chain. */
    bool onDown(const std::shared_ptr<api::StorageMessage>&) override { return false; };
    void configure(std::unique_ptr<vespa::config::content::core::StorOpsloggerConfig> config) override;
private:
    std::mutex    _lock;
    std::string   _fileName;
    FILE        * _targetFile;
    framework::Component _component;

    config::ConfigFetcher _configFetcher;
};

}