forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextensions.hh
155 lines (132 loc) · 4.99 KB
/
extensions.hh
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Modified by ScyllaDB
* Copyright (C) 2017-present ScyllaDB
*/
/*
* SPDX-License-Identifier: (LicenseRef-ScyllaDB-Source-Available-1.0 and Apache-2.0)
*/
#pragma once
#include <set>
#include <functional>
#include <map>
#include <variant>
#include <vector>
#include <unordered_set>
#include <exception>
#include <seastar/core/sstring.hh>
#include "bytes_fwd.hh"
#include "schema/schema_fwd.hh"
namespace sstables {
class file_io_extension;
}
namespace db {
class commitlog_file_extension;
class extensions {
public:
extensions();
~extensions();
using map_type = std::map<sstring, sstring>;
using schema_ext_config = std::variant<sstring, map_type, bytes>;
using schema_ext_create_func = std::function<seastar::shared_ptr<schema_extension>(schema_ext_config)>;
using sstable_file_io_extension = std::unique_ptr<sstables::file_io_extension>;
using commitlog_file_extension_ptr = std::unique_ptr<db::commitlog_file_extension>;
/**
* Registered extensions
*/
const std::map<sstring, schema_ext_create_func>& schema_extensions() const {
return _schema_extensions;
}
/**
* Returns iterable range of registered sstable IO extensions (see sstable.hh#sstable_file_io_extension)
* For any sstables wanting to call these on file open...
*/
std::vector<sstables::file_io_extension*> sstable_file_io_extensions() const;
/**
* Returns iterable range of registered commitlog IO extensions (see commitlog_extensions.hh#commitlog_file_extension)
* For any commitlogs wanting to call these on file open or descriptor scan...
*/
std::vector<db::commitlog_file_extension*> commitlog_file_extensions() const;
/**
* Registered extensions keywords, i.e. custom properties/property sets
* for schema extensions
*/
std::set<sstring> schema_extension_keywords() const;
/**
* Init time method to add schema extension.
*/
void add_schema_extension(sstring w, schema_ext_create_func f) {
_schema_extensions.emplace(std::move(w), std::move(f));
}
/**
* A shorthand for the add_schema_extension. Adds a function that adds
* the extension to a schema with appropriate constructor overload.
*/
template<typename Extension>
void add_schema_extension(sstring w) {
add_schema_extension(std::move(w), [] (db::extensions::schema_ext_config cfg) {
return std::visit([] (auto v) {
return ::make_shared<Extension>(v);
}, cfg);
});
}
/**
* Init time method to add sstable extension
*/
void add_sstable_file_io_extension(sstring n, sstable_file_io_extension);
/**
* Init time method to add sstable extension
*/
void add_commitlog_file_extension(sstring n, commitlog_file_extension_ptr);
/**
* Allows forcible modification of schema extensions of a schema. This should
* not be done lightly however. In fact, it should only be done on startup
* at most, and thus this method is non-const, i.e. you can only use it on
* config apply.
*/
void add_extension_to_schema(schema_ptr, const sstring&, shared_ptr<schema_extension>);
/**
* Adds a keyspace to "extension internal" set.
*
* Such a keyspace must be loaded before/destroyed after any "normal" user keyspace.
* Thus a psuedo-system/internal keyspce.
* This has little to no use in open source version, and is temporarily bridged with
* the static version of same functionality in distributed loader. It is however (or will
* be), essential to enterprise code. Do not remove.
*/
void add_extension_internal_keyspace(std::string);
/**
* Checks if a keyspace is a registered load priority one.
*/
bool is_extension_internal_keyspace(const std::string&) const;
private:
std::map<sstring, schema_ext_create_func> _schema_extensions;
std::map<sstring, sstable_file_io_extension> _sstable_file_io_extensions;
std::map<sstring, commitlog_file_extension_ptr> _commitlog_file_extensions;
std::unordered_set<std::string> _extension_internal_keyspaces;
};
class extension_storage_exception : public std::exception {
private:
std::string _message;
public:
extension_storage_exception(std::string message) noexcept
: _message(std::move(message))
{}
extension_storage_exception(extension_storage_exception&&) = default;
extension_storage_exception(const extension_storage_exception&) = default;
const char* what() const noexcept override {
return _message.c_str();
}
};
class extension_storage_resource_unavailable : public extension_storage_exception {
public:
using extension_storage_exception::extension_storage_exception;
};
class extension_storage_permission_error : public extension_storage_exception {
public:
using extension_storage_exception::extension_storage_exception;
};
class extension_storage_misconfigured : public extension_storage_exception {
public:
using extension_storage_exception::extension_storage_exception;
};
}