aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/bucketdb/storbucketdb.cpp
blob: b295ebac0dcdda28a77f15c4d06e11e8ab771696 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "storbucketdb.h"
#include "btree_lockable_map.h"
#include "striped_btree_lockable_map.h"
#include <vespa/storage/common/content_bucket_db_options.h>

#include <vespa/log/log.h>
LOG_SETUP(".storage.bucketdb.stor_bucket_db");

using document::BucketId;

namespace storage {
namespace bucketdb {

void
StorageBucketInfo::
print(std::ostream& out, bool, const std::string&) const
{
    out << info;
}

std::ostream&
operator<<(std::ostream& out, const StorageBucketInfo& info) {
    info.print(out, false, "");
    return out;
}

namespace {

std::unique_ptr<AbstractBucketMap<StorageBucketInfo>> make_btree_db_impl() {
    return std::make_unique<BTreeLockableMap<StorageBucketInfo>>();
}

std::unique_ptr<AbstractBucketMap<StorageBucketInfo>> make_striped_btree_db_impl(uint8_t n_stripes) {
    return std::make_unique<StripedBTreeLockableMap<StorageBucketInfo>>(n_stripes);
}

}

} // bucketdb

StorBucketDatabase::StorBucketDatabase(const ContentBucketDbOptions& opts)
    : _impl((opts.n_stripe_bits > 0) ? bucketdb::make_striped_btree_db_impl(opts.n_stripe_bits)
                                     : bucketdb::make_btree_db_impl())
{}

void
StorBucketDatabase::insert(const document::BucketId& bucket,
                           const bucketdb::StorageBucketInfo& entry,
                           const char* clientId)
{
    bool preExisted;
    return _impl->insert(bucket.toKey(), entry, clientId, false, preExisted);
}

bool
StorBucketDatabase::erase(const document::BucketId& bucket,
                          const char* clientId)
{
    return _impl->erase(bucket.stripUnused().toKey(), clientId, false);
}

StorBucketDatabase::WrappedEntry
StorBucketDatabase::get(const document::BucketId& bucket,
                        const char* clientId,
                        Flag flags)
{
    bool createIfNonExisting = (flags & CREATE_IF_NONEXISTING);
    return _impl->get(bucket.stripUnused().toKey(), clientId, createIfNonExisting);
}

size_t StorBucketDatabase::size() const {
    return _impl->size();
}

size_t StorBucketDatabase::getMemoryUsage() const {
    return _impl->getMemoryUsage();
}

vespalib::MemoryUsage StorBucketDatabase::detailed_memory_usage() const noexcept {
    return _impl->detailed_memory_usage();
}

void StorBucketDatabase::showLockClients(vespalib::asciistream& out) const {
    _impl->showLockClients(out);
}

StorBucketDatabase::EntryMap
StorBucketDatabase::getAll(const BucketId& bucketId, const char* clientId) {
    return _impl->getAll(bucketId, clientId);
}

StorBucketDatabase::EntryMap
StorBucketDatabase::getContained(const BucketId& bucketId, const char* clientId) {
    return _impl->getContained(bucketId, clientId);
}

bool StorBucketDatabase::isConsistent(const WrappedEntry& entry) {
    return _impl->isConsistent(entry);
}

void StorBucketDatabase::for_each_chunked(
        std::function<Decision(uint64_t, const bucketdb::StorageBucketInfo&)> func,
        const char* clientId,
        vespalib::duration yieldTime,
        uint32_t chunkSize)
{
    _impl->for_each_chunked(std::move(func), clientId, yieldTime, chunkSize);
}

void StorBucketDatabase::for_each_mutable_unordered(
        std::function<Decision(uint64_t, bucketdb::StorageBucketInfo&)> func,
        const char* clientId)
{
    _impl->for_each_mutable_unordered(std::move(func), clientId);
}

void StorBucketDatabase::for_each(
        std::function<Decision(uint64_t, const bucketdb::StorageBucketInfo&)> func,
        const char* clientId)
{
    _impl->for_each(std::move(func), clientId);
}

std::unique_ptr<bucketdb::ReadGuard<StorBucketDatabase::Entry>>
StorBucketDatabase::acquire_read_guard() const {
    return _impl->acquire_read_guard();
}

} // storage