aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/distributor/maintenance/simplemaintenancescanner.h
blob: 58ca85e6bc0dfc10178ad209f1e656188e235557 (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
61
62
63
64
65
66
67
68
69
70
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "maintenancescanner.h"
#include "bucketprioritydatabase.h"
#include "maintenanceprioritygenerator.h"
#include "node_maintenance_stats_tracker.h"
#include <vespa/storage/distributor/distributor_bucket_space_repo.h>

namespace storage::distributor {

class SimpleMaintenanceScanner : public MaintenanceScanner
{
public:
    struct GlobalMaintenanceStats {
        std::array<uint64_t, MaintenanceOperation::OPERATION_COUNT> pending;

        GlobalMaintenanceStats() noexcept
            : pending()
        { }

        bool operator==(const GlobalMaintenanceStats& rhs) const noexcept;
        void merge(const GlobalMaintenanceStats& rhs) noexcept;
    };
    struct PendingMaintenanceStats {
        PendingMaintenanceStats() noexcept;
        PendingMaintenanceStats(const PendingMaintenanceStats &);
        PendingMaintenanceStats &operator = (const PendingMaintenanceStats &) = delete;
        PendingMaintenanceStats(PendingMaintenanceStats &&) noexcept;
        PendingMaintenanceStats &operator = (PendingMaintenanceStats &&) noexcept;
        ~PendingMaintenanceStats();
        [[nodiscard]] PendingMaintenanceStats fetch_and_reset();
        GlobalMaintenanceStats      global;
        NodeMaintenanceStatsTracker perNodeStats;

        void merge(const PendingMaintenanceStats& rhs);
    };
private:
    BucketPriorityDatabase&                                    _bucketPriorityDb;
    const MaintenancePriorityGenerator&                        _priorityGenerator;
    const DistributorBucketSpaceRepo&                          _bucketSpaceRepo;
    DistributorBucketSpaceRepo::BucketSpaceMap::const_iterator _bucketSpaceItr;
    document::BucketId                                         _bucketCursor;
    PendingMaintenanceStats                                    _pendingMaintenance;

    void countBucket(document::BucketSpace bucketSpace, const BucketInfo &info);
public:
    SimpleMaintenanceScanner(BucketPriorityDatabase& bucketPriorityDb,
                             const MaintenancePriorityGenerator& priorityGenerator,
                             const DistributorBucketSpaceRepo& bucketSpaceRepo);
    SimpleMaintenanceScanner(const SimpleMaintenanceScanner&) = delete;
    SimpleMaintenanceScanner& operator=(const SimpleMaintenanceScanner&) = delete;
    ~SimpleMaintenanceScanner() override;

    ScanResult scanNext() override;
    [[nodiscard]] PendingMaintenanceStats fetch_and_reset();

    // TODO: move out into own interface!
    void prioritizeBucket(const document::Bucket &id);

    // TODO Only for testing
    const PendingMaintenanceStats& getPendingMaintenanceStats() const noexcept {
        return _pendingMaintenance;
    }
};

std::ostream&
operator<<(std::ostream&, const SimpleMaintenanceScanner::GlobalMaintenanceStats&);

}