1 /*
2  * Copyright (C) 2010-2015 Codership Oy <info@codership.com>
3  */
4 
5 #ifndef GALERA_SERVICE_THD_HPP
6 #define GALERA_SERVICE_THD_HPP
7 
8 #include "galera_gcs.hpp"
9 #include <GCache.hpp>
10 
11 #include <gu_lock.hpp> // gu::Mutex and gu::Cond
12 
13 namespace galera
14 {
15     class ServiceThd
16     {
17     public:
18 
19         ServiceThd (GcsI& gcs, gcache::GCache& gcache);
20 
21         ~ServiceThd ();
22 
23         /*! flush all ongoing operations (before processing CC)
24          *  and install new group UUID */
25         void flush (const gu::UUID& uuid);
26 
27         /*! reset to initial state before gcs (re)connect */
28         void reset();
29 
30         /* !!!
31          * The following methods must be invoked only within a monitor,
32          * so that monitors drain during CC ensures that no outdated
33          * actions are scheduled with the service thread after that.
34          * !!! */
35 
36         /*! schedule seqno to be reported as last committed */
37         /* report = false is to disable sending duplicate in case of error voting
38          * that is done through a different, blocking channel */
39         void report_last_committed (gcs_seqno_t seqno, bool const report = true);
40 
41         /*! release write sets up to and including seqno */
42         void release_seqno (gcs_seqno_t seqno);
43 
44     private:
45 
46         static const uint32_t A_NONE;
47 
48         struct Data
49         {
50             gu::GTID    last_committed_;
51             gcs_seqno_t release_seqno_;
52             uint32_t    act_;
53 
Datagalera::ServiceThd::Data54             Data() :
55                 last_committed_(),
56                 release_seqno_ (0),
57                 act_           (A_NONE)
58             {}
59         };
60 
61         gcache::GCache& gcache_;
62         GcsI&           gcs_;
63         gu_thread_t     thd_;
64         gu::Mutex       mtx_;
65         gu::Cond        cond_;  // service request condition
66         gu::Cond        flush_; // flush condition
67         Data            data_;
68 
69         static void* thd_func (void*);
70 
71         ServiceThd (const ServiceThd&);
72         ServiceThd& operator= (const ServiceThd&);
73     };
74 }
75 
76 #endif /* GALERA_SERVICE_THD_HPP */
77