forked from eBay/HomeBlocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvolume.cpp
More file actions
87 lines (75 loc) · 3.72 KB
/
volume.cpp
File metadata and controls
87 lines (75 loc) · 3.72 KB
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
/*********************************************************************************
* Modifications Copyright 2017-2019 eBay Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
*********************************************************************************/
#include "volume.hpp"
#include <homestore/replication_service.hpp>
namespace homeblocks {
// this API will be called by volume manager after volume sb is recovered and volume is created;
shared< VolumeIndexTable > Volume::init_index_table(bool is_recovery, shared< VolumeIndexTable > tbl) {
if (!is_recovery) {
index_cfg_t cfg(homestore::hs()->index_service().node_size());
cfg.m_leaf_node_type = homestore::btree_node_type::PREFIX;
cfg.m_int_node_type = homestore::btree_node_type::PREFIX;
// create index table;
auto uuid = hb_utils::gen_random_uuid();
// user_sb_size is not currently enabled in homestore;
// parent uuid is used during recovery in homeblks layer;
LOGI("Creating index table for volume: {}, index_uuid: {}, parent_uuid: {}", vol_info_->name,
boost::uuids::to_string(uuid), boost::uuids::to_string(id()));
indx_tbl_ = std::make_shared< VolumeIndexTable >(uuid, id() /*parent uuid*/, 0 /*user_sb_size*/, cfg);
} else {
indx_tbl_ = tbl;
}
homestore::hs()->index_service().add_index_table(indx_table());
return indx_table();
}
Volume::Volume(sisl::byte_view const& buf, void* cookie) : sb_{VOL_META_NAME} {
sb_.load(buf, cookie);
// generate volume info from sb;
vol_info_ = std::make_shared< VolumeInfo >(sb_->id, sb_->size, sb_->page_size, sb_->name);
LOGI("Volume superblock loaded from disk, vol_info : {}", vol_info_->to_string());
}
bool Volume::init(bool is_recovery) {
if (!is_recovery) {
// first time creation of the Volume, let's write the superblock;
sb_.create(sizeof(vol_sb_t));
sb_->init(vol_info_->page_size, vol_info_->size_bytes, vol_info_->id, vol_info_->name);
// write to disk;
sb_.write();
init_index_table(false /*is_recovery*/);
// create solo repl dev for volume;
// members left empty on purpose for solo repl dev
LOGI("Creating solo repl dev for volume: {}, uuid: {}", vol_info_->name, boost::uuids::to_string(id()));
auto ret = homestore::hs()->repl_service().create_repl_dev(id(), {} /*members*/).get();
if (ret.hasError()) {
LOGE("Failed to create solo repl dev for volume: {}, uuid: {}, error: {}", vol_info_->name,
boost::uuids::to_string(vol_info_->id), ret.error());
return false;
}
rd_ = ret.value();
} else {
// recovery path
LOGI("Getting repl dev for volume: {}, uuid: {}", vol_info_->name, boost::uuids::to_string(id()));
auto ret = homestore::hs()->repl_service().get_repl_dev(id());
if (ret.hasError()) {
LOGE("Failed to get repl dev for volume name: {}, uuid: {}, error: {}", vol_info_->name,
boost::uuids::to_string(vol_info_->id), ret.error());
DEBUG_ASSERT(false, "Failed to get repl dev for volume");
return false;
}
rd_ = ret.value();
}
return true;
}
} // namespace homeblocks