aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/storageserver/service_layer_error_listener.h
blob: ae90ad8f71107b03ce9e29699403cdfa03e2ef12 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/storage/persistence/provider_error_wrapper.h>
#include <atomic>

namespace storage {

class StorageComponent;
class MergeThrottler;

/*
 * Listener implementation for SPI errors that require action beyond simply
 * responding to the command that generated them.
 *
 * - Fatal errors will trigger a process shutdown.
 * - Resource exhaustion errors will trigger merge back-pressure.
 */
class ServiceLayerErrorListener : public ProviderErrorListener {
    StorageComponent& _component;
    MergeThrottler&   _merge_throttler;
    std::atomic<bool> _shutdown_initiated;
public:
    ServiceLayerErrorListener(StorageComponent& component,
                              MergeThrottler& merge_throttler) noexcept
        : _component(component),
          _merge_throttler(merge_throttler),
          _shutdown_initiated(false)
    {}

    void on_fatal_error(vespalib::stringref message) override;
    void on_resource_exhaustion_error(vespalib::stringref message) override;
};

}