aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/common/content_bucket_space_repo.h
blob: 048c2c266f00fd82a5d870eb87e1dbb507e2bb39 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "content_bucket_space.h"
#include <vespa/document/bucket/bucketspace.h>
#include <unordered_map>

namespace storage {

/**
 * Class managing the set of bucket spaces (with associated bucket databases) on a content node.
 */
class ContentBucketSpaceRepo {
public:
    using BucketSpaceMap = std::unordered_map<document::BucketSpace, ContentBucketSpace::UP, document::BucketSpace::hash>;
    using BucketSpaces = std::vector<document::BucketSpace>;

private:
    BucketSpaceMap _map;

public:
    explicit ContentBucketSpaceRepo(const ContentBucketDbOptions&);
    ContentBucketSpace &get(document::BucketSpace bucketSpace) const;
    BucketSpaceMap::const_iterator begin() const noexcept { return _map.begin(); }
    BucketSpaceMap::const_iterator end() const noexcept { return _map.end(); }

    BucketSpaces getBucketSpaces() const;
    size_t getBucketMemoryUsage() const;

    template <typename Functor>
    void for_each_bucket(Functor functor) const {
        for (const auto& elem : _map) {
            elem.second->bucketDatabase().acquire_read_guard()->for_each(functor);
        }
    }

};

}