1 // 2 // Copyright (C) 2012-2018 Codership Oy <info@codership.com> 3 // 4 5 #ifndef GALERA_SAVED_STATE_HPP 6 #define GALERA_SAVED_STATE_HPP 7 8 #include "gu_atomic.hpp" 9 #include "gu_mutex.hpp" 10 #include "gu_lock.hpp" 11 12 #include "wsrep_api.h" 13 14 #include <string> 15 #include <cstdio> 16 17 namespace galera 18 { 19 20 class SavedState 21 { 22 public: 23 24 SavedState (const std::string& file); 25 ~SavedState (); 26 27 void get (wsrep_uuid_t& u, wsrep_seqno_t& s, bool& safe_to_bootstrap); 28 void set (const wsrep_uuid_t& u, wsrep_seqno_t s, bool safe_to_bootstrap); 29 30 void mark_unsafe(); 31 void mark_safe(); 32 void mark_corrupt(); 33 stats(long & marks,long & locks,long & writes)34 void stats(long& marks, long& locks, long& writes) 35 { 36 marks = total_marks_(); 37 locks = total_locks_; 38 writes = total_writes_; 39 } 40 41 private: 42 43 FILE* fs_; 44 const std::string filename_; 45 wsrep_uuid_t uuid_; 46 wsrep_seqno_t seqno_; 47 bool safe_to_bootstrap_; 48 gu::Atomic<long> unsafe_; 49 bool corrupt_; 50 51 /* this mutex is needed because mark_safe() and mark_corrupt() will be 52 * called outside local monitor, so race is possible */ 53 gu::Mutex mtx_; 54 wsrep_uuid_t written_uuid_; 55 ssize_t current_len_; 56 gu::Atomic<long> total_marks_; 57 long total_locks_; 58 long total_writes_; 59 60 void write_file (const wsrep_uuid_t& u, const wsrep_seqno_t s, 61 bool safe_to_bootstrap); 62 63 SavedState (const SavedState&); 64 SavedState& operator=(const SavedState&); 65 66 }; /* class SavedState */ 67 68 } /* namespace galera */ 69 70 #endif /* GALERA_SAVED_STATE_HPP */ 71