forked from eBay/HomeBlocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomeblks_impl.hpp
More file actions
149 lines (115 loc) · 5.14 KB
/
homeblks_impl.hpp
File metadata and controls
149 lines (115 loc) · 5.14 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
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
/*********************************************************************************
* 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.
*
*********************************************************************************/
#pragma once
#include <map>
#include <string>
#include <sisl/logging/logging.h>
#include <homestore/homestore.hpp>
#include <homestore/index/index_table.hpp>
#include <homestore/superblk_handler.hpp>
#include <homeblks/home_blks.hpp>
#include <homeblks/volume_mgr.hpp>
#include <homeblks/common.hpp>
#include "volume/volume.hpp"
namespace homeblocks {
class Volume;
class HomeBlocksImpl : public HomeBlocks, public VolumeManager, public std::enable_shared_from_this< HomeBlocksImpl > {
struct homeblks_sb_t {
uint64_t magic;
uint32_t version;
uint32_t flag;
uint64_t boot_cnt;
peer_id_t svc_id;
void init_flag(uint32_t f) { flag = f; }
void set_flag(uint32_t bit) { flag |= bit; }
void clear_flag(uint32_t bit) { flag &= ~bit; }
bool test_flag(uint32_t bit) { return flag & bit; }
};
private:
inline static auto const HB_META_NAME = std::string("HomeBlks2");
static constexpr uint64_t HB_SB_MAGIC{0xCEEDDEEB};
static constexpr uint32_t HB_SB_VER{0x1};
static constexpr uint64_t HS_CHUNK_SIZE = 2 * Gi;
static constexpr uint32_t DATA_BLK_SIZE = 4096;
static constexpr uint32_t SB_FLAGS_GRACEFUL_SHUTDOWN{0x00000001};
static constexpr uint32_t SB_FLAGS_RESTRICTED{0x00000002};
private:
/// Our SvcId retrieval and SvcId->IP mapping
std::weak_ptr< HomeBlocksApplication > _application;
folly::Executor::KeepAlive<> executor_;
///
mutable std::shared_mutex vol_lock_;
std::map< volume_id_t, VolumePtr > vol_map_;
// index table map which only used during recovery;
mutable std::shared_mutex index_lock_;
std::unordered_map< std::string, shared< VolumeIndexTable > > idx_tbl_map_;
bool recovery_done_{false};
superblk< homeblks_sb_t > sb_;
peer_id_t our_uuid_;
public:
explicit HomeBlocksImpl(std::weak_ptr< HomeBlocksApplication >&& application);
~HomeBlocksImpl() override;
HomeBlocksImpl(const HomeBlocksImpl&) = delete;
HomeBlocksImpl(HomeBlocksImpl&&) noexcept = delete;
HomeBlocksImpl& operator=(const HomeBlocksImpl&) = delete;
HomeBlocksImpl& operator=(HomeBlocksImpl&&) noexcept = delete;
shared< VolumeManager > volume_manager() final;
/// HomeBlocks
/// Returns the UUID of this HomeBlocks.
HomeBlocksStats get_stats() const final;
iomgr::drive_type data_drive_type() const final;
peer_id_t our_uuid() const final { return our_uuid_; }
/// VolumeManager
NullAsyncResult create_volume(VolumeInfo&& vol_info) final;
NullAsyncResult remove_volume(const volume_id_t& id) final;
VolumePtr lookup_volume(const volume_id_t& id) final;
NullAsyncResult write(const VolumePtr& vol, const vol_interface_req_ptr& req, bool part_of_batch = false) final;
NullAsyncResult read(const VolumePtr& vol, const vol_interface_req_ptr& req, bool part_of_batch = false) final;
NullAsyncResult unmap(const VolumePtr& vol, const vol_interface_req_ptr& req) final;
void submit_io_batch() final;
// see api comments in base class;
bool get_stats(volume_id_t id, VolumeStats& stats) const final;
void get_volume_ids(std::vector< volume_id_t >& vol_ids) const final;
// Index
shared< VolumeIndexTable > recover_index_table(homestore::superblk< homestore::index_table_sb >&& sb);
// HomeStore
void init_homestore();
void init_cp();
uint64_t get_current_timestamp();
void on_init_complete();
private:
// Should only be called for first-time-boot
void superblk_init();
void register_metablk_cb();
void get_dev_info(shared< HomeBlocksApplication > app, std::vector< homestore::dev_info >& device_info,
bool& has_data_dev, bool& has_fast_dev);
DevType get_device_type(std::string const& devname);
auto defer() const { return folly::makeSemiFuture().via(executor_); }
// recovery apis
void on_hb_meta_blk_found(sisl::byte_view const& buf, void* cookie);
void on_vol_meta_blk_found(sisl::byte_view const& buf, void* cookie);
};
class HBIndexSvcCB : public homestore::IndexServiceCallbacks {
public:
HBIndexSvcCB(HomeBlocksImpl* hb) : hb_(hb) {}
shared< homestore::IndexTableBase >
on_index_table_found(homestore::superblk< homestore::index_table_sb >&& sb) override {
LOGI("Recovered index table to index service");
return hb_->recover_index_table(std::move(sb));
}
private:
HomeBlocksImpl* hb_;
};
} // namespace homeblocks