Skip to content

Commit 588d573

Browse files
authored
Merge pull request #359 from cruzdb/init-stripes
Init stripes
2 parents 8bdf157 + 330dc3f commit 588d573

File tree

6 files changed

+48
-13
lines changed

6 files changed

+48
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Pending
22

3+
* separate view and epoch-versioned-view abstractions
4+
* use a scalable view / objectmap implementation
5+
* moved away from protocol buffers to use only flatbuffers
6+
* implemented a large set of unit test coverage for views
7+
* initialize first stripe for new logs
8+
39
# v0.5.0
410

511
* be/ceph: added support for controlling omap vs bytestream storage

src/include/zlog/options.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ struct Options {
2626
bool create_if_missing = false;
2727
bool error_if_exists = false;
2828

29+
// add stripes to the initial view for new logs.
30+
bool create_initial_view_stripes = true;
31+
2932
// schedule a background task to initialize stripe objects whenever a new
3033
// stripe is created. this should always be set to true, and is only false for
3134
// in testing scenarios (e.g. synchronous object init in i/o path).
@@ -37,8 +40,6 @@ struct Options {
3740

3841
uint32_t max_inflight_ops = 1024;
3942

40-
bool create_initial_view_stripes = true;
41-
4243
///////////////////////////////////////////////////////////////////
4344

4445
// number of I/O threads

src/libzlog/log.cc

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Log::~Log() {}
1515

1616
int create_or_open(const Options& options,
1717
Backend *backend, const std::string& name,
18-
std::string *hoid_out, std::string *prefix_out)
18+
std::string *hoid_out, std::string *prefix_out,
19+
bool *created)
1920
{
2021
std::string hoid;
2122
std::string prefix;
@@ -54,7 +55,9 @@ int create_or_open(const Options& options,
5455
return ret;
5556
}
5657
}
57-
58+
if (created) {
59+
*created = true;
60+
}
5861
break;
5962
}
6063

@@ -81,10 +84,11 @@ int Log::Open(const Options& options,
8184
}
8285
}
8386

87+
bool created = false;
8488
std::string hoid;
8589
std::string prefix;
8690
int ret = create_or_open(options, backend.get(),
87-
name, &hoid, &prefix);
91+
name, &hoid, &prefix, &created);
8892
if (ret) {
8993
return ret;
9094
}
@@ -110,8 +114,14 @@ int Log::Open(const Options& options,
110114
// gh#343
111115
impl->striper.update_current_view(0);
112116

113-
// TODO: initialize the first stripe so that cost isn't incurred by clients
114-
// when they start performing I/O.
117+
// kick start initialization of the first stripe
118+
if (options.init_stripe_on_create && created) {
119+
// if there actually is a stripe. this is controlled by the
120+
// create_init_view_stripes option
121+
if (!impl->striper.view()->object_map().empty()) {
122+
impl->striper.async_init_stripe(0);
123+
}
124+
}
115125

116126
*logpp = impl.release();
117127

src/libzlog/log_impl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ class LogImpl : public Log {
253253

254254
int create_or_open(const Options& options,
255255
Backend *backend, const std::string& name,
256-
std::string *hoid_out, std::string *prefix_out);
256+
std::string *hoid_out, std::string *prefix_out,
257+
bool *created);
257258

258259
}

src/libzlog/view.cc

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,27 @@ std::string View::create_initial(const Options& options)
2727
{
2828
flatbuffers::FlatBufferBuilder fbb;
2929

30-
// - next_stripe_id = 0
31-
// - no stripes
32-
// TODO: if (options.create_initial_view_stripes) ...
33-
const auto object_map = zlog::fbs::CreateObjectMapDirect(fbb, 0, nullptr, 0);
30+
// below the prefix is discarded when the object map is encoded
31+
// TODO: it would be nice to reformulate the abstractions to avoid needing to
32+
// use a placeholder prefix here. the multistripe defines a layout, but
33+
// shouldn't define a static object naming implied by requiring this prefix
34+
// parameter.
35+
std::map<uint64_t, MultiStripe> stripes;
36+
if (options.create_initial_view_stripes) {
37+
stripes.emplace(0,
38+
MultiStripe(
39+
"<<UNUSED PREFIX>>",
40+
0,
41+
options.stripe_width,
42+
options.stripe_slots,
43+
0,
44+
1,
45+
options.stripe_width * options.stripe_slots - 1));
46+
}
47+
48+
const auto object_map = stripes.empty() ?
49+
zlog::fbs::CreateObjectMapDirect(fbb, 0, nullptr, 0) :
50+
ObjectMap(1, stripes, 0).encode(fbb);
3451

3552
auto builder = zlog::fbs::ViewBuilder(fbb);
3653
builder.add_object_map(object_map);

src/zlog.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ int handle_log(std::vector<std::string> command, std::shared_ptr<zlog::Backend>
159159
options.create_if_missing = true;
160160
std::string hoid, prefix;
161161
int ret = zlog::create_or_open(options, backend.get(), command[1],
162-
&hoid, &prefix);
162+
&hoid, &prefix, nullptr);
163163
switch (ret) {
164164
case 0:
165165
break;

0 commit comments

Comments
 (0)