]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/common/exception.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / crimson / common / exception.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #pragma once
5
6 #include <exception>
7 #include <seastar/core/future.hh>
8 #include <seastar/core/future-util.hh>
9
10 #include "crimson/common/log.h"
11
12 namespace crimson::common {
13
14 class system_shutdown_exception final : public std::exception{
15 public:
16 const char* what() const noexcept final {
17 return "system shutting down";
18 }
19 };
20
21 class actingset_changed final : public std::exception {
22 public:
23 actingset_changed(bool sp) : still_primary(sp) {}
24 const char* what() const noexcept final {
25 return "acting set changed";
26 }
27 bool is_primary() const {
28 return still_primary;
29 }
30 private:
31 const bool still_primary;
32 };
33
34 template<typename Func, typename... Args>
35 inline seastar::future<> handle_system_shutdown(Func&& func, Args&&... args)
36 {
37 return seastar::futurize_invoke(std::forward<Func>(func),
38 std::forward<Args>(args)...)
39 .handle_exception([](std::exception_ptr eptr) {
40 if (*eptr.__cxa_exception_type() ==
41 typeid(crimson::common::system_shutdown_exception)) {
42 crimson::get_logger(ceph_subsys_osd).debug(
43 "operation skipped, system shutdown");
44 return seastar::now();
45 }
46 std::rethrow_exception(eptr);
47 });
48 }
49
50 }