Skip to content

Commit d0ceff6

Browse files
committed
add offline check for ops
1 parent 3c088ac commit d0ceff6

File tree

6 files changed

+61
-6
lines changed

6 files changed

+61
-6
lines changed

conanfile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def build_requirements(self):
4646
self.test_requires("gtest/1.14.0")
4747

4848
def requirements(self):
49-
self.requires("homestore/[~6.20]@oss/master", transitive_headers=True)
49+
#self.requires("homestore/[~6.20]@oss/master", transitive_headers=True)
50+
self.requires("homestore/6.20.0", transitive_headers=True)
5051
self.requires("iomgr/[^11.3]@oss/master", transitive_headers=True)
5152
self.requires("sisl/[^12.2]@oss/master", transitive_headers=True)
5253
self.requires("lz4/1.9.4", override=True)

src/include/homeblks/volume_mgr.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace homeblocks {
1212

1313
ENUM(VolumeError, uint16_t, UNKNOWN = 1, INVALID_ARG, TIMEOUT, UNKNOWN_VOLUME, UNSUPPORTED_OP, CRC_MISMATCH,
14-
NO_SPACE_LEFT, DRIVE_WRITE_ERROR, INTERNAL_ERROR, INDEX_ERROR);
14+
NO_SPACE_LEFT, DRIVE_WRITE_ERROR, INTERNAL_ERROR, INDEX_ERROR, VOLUME_OFFLINE);
1515

1616
using lba_t = uint64_t;
1717
using lba_count_t = uint32_t;

src/lib/homeblks_impl.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ void HomeBlocksImpl::on_hb_meta_blk_found(sisl::byte_view const& buf, void* cook
373373
// if it is a gracefuln shutdown, this flag should be set again in shutdown routine;
374374
sb_->clear_flag(SB_FLAGS_GRACEFUL_SHUTDOWN);
375375
LOGI("System was shutdown gracefully");
376+
} else if (sb_->test_flag(SB_FLAGS_RESTRICTED)) {
377+
is_restricted_.store(true);
378+
LOGI("System is booted into restricted mode, reason: {}", sb_->flag);
376379
} else {
377380
LOGI("System experienced sudden crash since last boot");
378381
}
@@ -476,9 +479,12 @@ void HomeBlocksImpl::exit_fc(VolumePtr& vol) { vol->state_change(vol_state::ONLI
476479

477480
void HomeBlocksImpl::fault_containment(const VolumePtr vol, const std::string& reason) {
478481
if (vol == nullptr) {
479-
// TODO: Put entire HB into offline;
480-
assert(0);
481-
LOGE("Not implemented yet: putting HB into fault containment, reason: {}", reason);
482+
// Put entire HB into offline;
483+
std::scoped_lock lg(sb_lock_);
484+
sb_->set_flag(SB_FLAGS_RESTRICTED);
485+
is_restricted_.store(true);
486+
sb_.write();
487+
LOGE("Putting HB into restricted mode, reason: {}", reason);
482488
return;
483489
}
484490

src/lib/homeblks_impl.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,16 @@ class HomeBlocksImpl : public HomeBlocks, public VolumeManager, public std::enab
7373
std::unordered_map< std::string, shared< VolumeIndexTable > > idx_tbl_map_;
7474

7575
bool recovery_done_{false};
76+
std::mutex sb_lock_;
7677
superblk< homeblks_sb_t > sb_;
7778
peer_id_t our_uuid_;
7879
shared< VolumeChunkSelector > chunk_selector_;
7980
std::unique_ptr< sisl::IDReserver > ordinal_reserver_;
8081

8182
sisl::atomic_counter< uint64_t > outstanding_reqs_{0};
8283
bool shutdown_started_{false};
84+
std::atomic< bool > is_restricted_{false}; // avoid taking lock in IO path;
85+
8386
folly::Promise< folly::Unit > shutdown_promise_;
8487
iomgr::io_fiber_t reaper_fiber_;
8588
iomgr::timer_handle_t vol_gc_timer_hdl_{iomgr::null_timer_handle};
@@ -151,6 +154,7 @@ class HomeBlocksImpl : public HomeBlocks, public VolumeManager, public std::enab
151154
void fault_containment(const VolumePtr vol, const std::string& reason = "");
152155
bool fc_on() const;
153156
void exit_fc(VolumePtr& vol);
157+
bool is_restricted() const { return is_restricted_.load(); }
154158

155159
public:
156160
// public static APIs;

src/lib/volume/volume.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ class Volume : public std::enable_shared_from_this< Volume > {
167167

168168
bool is_destroying() const { return m_state_.load() == vol_state::DESTROYING; }
169169
bool is_destroy_started() const { return destroy_started_.load(); }
170+
bool is_offline() const { return m_state_.load() == vol_state::OFFLINE; }
170171

171172
//
172173
// This API will be called to set the volume state and persist to disk;
@@ -226,7 +227,7 @@ class Volume : public std::enable_shared_from_this< Volume > {
226227
sisl::atomic_counter< uint64_t > outstanding_reqs_{0}; // number of outstanding requests
227228
std::atomic< bool > destroy_started_{
228229
false}; // indicates if volume destroy has started, avoid destroy to be executed more than once.
229-
std::atomic< vol_state > m_state_; // in-memory sb state;
230+
std::atomic< vol_state > m_state_; // in-memory sb state, avoid taking lock in IO path;
230231
};
231232

232233
struct vol_repl_ctx : public homestore::repl_req_ctx {

src/lib/volume_mgr.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ shared< hs_index_table_t > HomeBlocksImpl::recover_index_table(homestore::superb
7575
// cause crash;
7676
//
7777
VolumeManager::NullAsyncResult HomeBlocksImpl::create_volume(VolumeInfo&& vol_info) {
78+
if (is_restricted()) {
79+
LOGE("Can't serve volume create, System is in restricted mode.");
80+
return folly::makeUnexpected(VolumeError::UNSUPPORTED_OP);
81+
}
82+
7883
inc_ref();
7984
auto id = vol_info.id;
8085

@@ -115,6 +120,20 @@ VolumeManager::NullAsyncResult HomeBlocksImpl::create_volume(VolumeInfo&& vol_in
115120
// vol in destroying state already indicates an outstanding volume which consumed in no_outstanding_vols() API;
116121
//
117122
VolumeManager::NullAsyncResult HomeBlocksImpl::remove_volume(const volume_id_t& id) {
123+
if (is_restricted()) {
124+
LOGE("Can't serve volume remove, System is in restricted mode.");
125+
return folly::makeUnexpected(VolumeError::UNSUPPORTED_OP);
126+
}
127+
128+
auto vol = lookup_volume(id);
129+
if (vol == nullptr) {
130+
LOGE("Volume with id {} not found, cannot remove", boost::uuids::to_string(id));
131+
return folly::makeUnexpected(VolumeError::INVALID_ARG);
132+
} else if (vol->is_offline()) {
133+
LOGE("Volume {} is offline, cannot remove", vol->id_str());
134+
return folly::makeUnexpected(VolumeError::VOLUME_OFFLINE);
135+
}
136+
118137
LOGINFO("remove_volume with input id: {}", boost::uuids::to_string(id));
119138
iomanager.run_on_forget(iomgr::reactor_regex::random_worker, [this, id]() {
120139
// 1. get the volume ptr from the map;
@@ -208,6 +227,14 @@ void HomeBlocksImpl::get_volume_ids(std::vector< volume_id_t >& vol_ids) const {
208227
}
209228

210229
VolumeManager::NullAsyncResult HomeBlocksImpl::write(const VolumePtr& vol, const vol_interface_req_ptr& req) {
230+
if (is_restricted()) {
231+
LOGE("Can't serve write, System is in restricted mode.");
232+
return folly::makeUnexpected(VolumeError::UNSUPPORTED_OP);
233+
} else if (vol->is_offline()) {
234+
LOGE("Can't serve write, Volume {} is offline.", vol->id_str());
235+
return folly::makeUnexpected(VolumeError::VOLUME_OFFLINE);
236+
}
237+
211238
if (vol->is_destroying() || is_shutting_down()) {
212239
LOGE(
213240
"Can't serve write, Volume {} is_destroying: {} is either in destroying state or System is shutting down. ",
@@ -226,6 +253,14 @@ VolumeManager::NullAsyncResult HomeBlocksImpl::write(const VolumePtr& vol, const
226253
}
227254

228255
VolumeManager::NullAsyncResult HomeBlocksImpl::read(const VolumePtr& vol, const vol_interface_req_ptr& req) {
256+
if (is_restricted()) {
257+
LOGE("Can't serve read, System is in restricted mode.");
258+
return folly::makeUnexpected(VolumeError::UNSUPPORTED_OP);
259+
} else if (vol->is_offline()) {
260+
LOGE("Can't serve read, Volume {} is offline.", vol->id_str());
261+
return folly::makeUnexpected(VolumeError::VOLUME_OFFLINE);
262+
}
263+
229264
if (vol->is_destroying() || is_shutting_down()) {
230265
LOGE("Can't serve read, Volume {} is_destroying: {} is either in destroying state or System is shutting down. ",
231266
vol->id_str(), vol->is_destroying());
@@ -245,6 +280,14 @@ VolumeManager::NullAsyncResult HomeBlocksImpl::read(const VolumePtr& vol, const
245280
VolumeManager::NullAsyncResult HomeBlocksImpl::unmap(const VolumePtr& vol, const vol_interface_req_ptr& req) {
246281
LOGWARN("Unmap to vol: {} not implemented", vol->id_str());
247282

283+
if (is_restricted()) {
284+
LOGE("Can't serve unmap, System is in restricted mode.");
285+
return folly::makeUnexpected(VolumeError::UNSUPPORTED_OP);
286+
} else if (vol->is_offline()) {
287+
LOGE("Can't serve unmap, Volume {} is offline.", vol->id_str());
288+
return folly::makeUnexpected(VolumeError::VOLUME_OFFLINE);
289+
}
290+
248291
if (vol->is_destroying() || is_shutting_down()) {
249292
LOGE(
250293
"Can't serve unmap, Volume {} is_destroying: {} is either in destroying state or System is shutting down. ",

0 commit comments

Comments
 (0)