]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/common/exception.h
import quincy beta 17.1.0
[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 #include "crimson/common/interruptible_future.h"
12
13 namespace crimson::common {
14
15 class interruption : public std::exception
16 {};
17
18 class system_shutdown_exception final : public interruption{
19 public:
20 const char* what() const noexcept final {
21 return "system shutting down";
22 }
23 };
24
25 class actingset_changed final : public interruption {
26 public:
27 actingset_changed(bool sp) : still_primary(sp) {}
28 const char* what() const noexcept final {
29 return "acting set changed";
30 }
31 bool is_primary() const {
32 return still_primary;
33 }
34 private:
35 const bool still_primary;
36 };
37
38 template<typename Func, typename... Args>
39 inline seastar::future<> handle_system_shutdown(Func&& func, Args&&... args)
40 {
41 return seastar::futurize_invoke(std::forward<Func>(func),
42 std::forward<Args>(args)...)
43 .handle_exception([](std::exception_ptr eptr) {
44 if (*eptr.__cxa_exception_type() ==
45 typeid(crimson::common::system_shutdown_exception)) {
46 crimson::get_logger(ceph_subsys_osd).debug(
47 "operation skipped, system shutdown");
48 return seastar::now();
49 }
50 std::rethrow_exception(eptr);
51 });
52 }
53
54 }