summaryrefslogtreecommitdiffstats
path: root/src/tools/cephfs_mirror/MirrorWatcher.h
blob: 54e185b95b04eed14b3f0dbc2dd36a09b1c98859 (plain)
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
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef CEPHFS_MIRROR_MIRROR_WATCHER_H
#define CEPHFS_MIRROR_MIRROR_WATCHER_H

#include <string_view>

#include "common/ceph_mutex.h"
#include "include/Context.h"
#include "include/rados/librados.hpp"
#include "Watcher.h"

class ContextWQ;
class Messenger;

namespace cephfs {
namespace mirror {

class FSMirror;

// watch for notifications via cephfs_mirror object (in metadata
// pool). this is used sending keepalived with keepalive payload
// being the rados instance address (used by the manager module
// to blocklist when needed).

class MirrorWatcher : public Watcher {
public:
  static MirrorWatcher *create(librados::IoCtx &ioctx, FSMirror *fs_mirror,
                               ContextWQ *work_queue) {
    return new MirrorWatcher(ioctx, fs_mirror, work_queue);
  }

  MirrorWatcher(librados::IoCtx &ioctx, FSMirror *fs_mirror,
                ContextWQ *work_queue);
  ~MirrorWatcher();

  void init(Context *on_finish);
  void shutdown(Context *on_finish);

  void handle_notify(uint64_t notify_id, uint64_t handle,
                     uint64_t notifier_id, bufferlist& bl) override;
  void handle_rewatch_complete(int r) override;

  bool is_blocklisted() {
    std::scoped_lock locker(m_lock);
    return m_blocklisted;
  }

  utime_t get_blocklisted_ts() {
    std::scoped_lock locker(m_lock);
    return m_blocklisted_ts;
  }

  bool is_failed() {
    std::scoped_lock locker(m_lock);
    return m_failed;
  }

  utime_t get_failed_ts() {
    std::scoped_lock locker(m_lock);
    return m_failed_ts;
  }

private:
  librados::IoCtx &m_ioctx;
  FSMirror *m_fs_mirror;
  ContextWQ *m_work_queue;

  ceph::mutex m_lock;
  std::string m_instance_id;

  Context *m_on_init_finish = nullptr;
  Context *m_on_shutdown_finish = nullptr;

  bool m_blocklisted = false;
  bool m_failed = false;

  utime_t m_blocklisted_ts;
  utime_t m_failed_ts;

  void register_watcher();
  void handle_register_watcher(int r);

  void unregister_watcher();
  void handle_unregister_watcher(int r);
};

} // namespace mirror
} // namespace cephfs

#endif // CEPHFS_MIRROR_MIRROR_WATCHER_H