~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to sql/rpl_reporting.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef RPL_REPORTING_H
 
2
#define RPL_REPORTING_H
 
3
 
 
4
/**
 
5
   Maximum size of an error message from a slave thread.
 
6
 */
 
7
#define MAX_SLAVE_ERRMSG      1024
 
8
 
 
9
/**
 
10
   Mix-in to handle the message logging and reporting for relay log
 
11
   info and master log info structures.
 
12
 
 
13
   By inheriting from this class, the class is imbued with
 
14
   capabilities to do slave reporting.
 
15
 */
 
16
class Slave_reporting_capability
 
17
{
 
18
public:
 
19
  /** lock used to synchronize m_last_error on 'SHOW SLAVE STATUS' **/
 
20
  mutable pthread_mutex_t err_lock;
 
21
  /**
 
22
     Constructor.
 
23
 
 
24
     @param thread_name Printable name of the slave thread that is reporting.
 
25
   */
 
26
  Slave_reporting_capability(char const *thread_name)
 
27
    : m_thread_name(thread_name)
 
28
  {
 
29
      pthread_mutex_init(&err_lock, MY_MUTEX_INIT_FAST);
 
30
  }
 
31
 
 
32
  /**
 
33
     Writes a message and, if it's an error message, to Last_Error
 
34
     (which will be displayed by SHOW SLAVE STATUS).
 
35
 
 
36
     @param level       The severity level
 
37
     @param err_code    The error code
 
38
     @param msg         The message (usually related to the error
 
39
                        code, but can contain more information), in
 
40
                        printf() format.
 
41
  */
 
42
  void report(loglevel level, int err_code, const char *msg, ...) const
 
43
    ATTRIBUTE_FORMAT(printf, 4, 5);
 
44
 
 
45
  /**
 
46
     Clear errors. They will not show up under <code>SHOW SLAVE
 
47
     STATUS</code>.
 
48
   */
 
49
  void clear_error() {
 
50
    pthread_mutex_lock(&err_lock);
 
51
    m_last_error.clear();
 
52
    pthread_mutex_unlock(&err_lock);
 
53
  }
 
54
 
 
55
  /**
 
56
     Error information structure.
 
57
   */
 
58
  class Error {
 
59
    friend class Slave_reporting_capability;
 
60
  public:
 
61
    Error()
 
62
    {
 
63
      clear();
 
64
    }
 
65
 
 
66
    void clear()
 
67
    {
 
68
      number= 0;
 
69
      message[0]= '\0';
 
70
    }
 
71
 
 
72
    /** Error code */
 
73
    uint32 number;
 
74
    /** Error message */
 
75
    char message[MAX_SLAVE_ERRMSG];
 
76
  };
 
77
 
 
78
  Error const& last_error() const { return m_last_error; }
 
79
 
 
80
  virtual ~Slave_reporting_capability()= 0;
 
81
private:
 
82
  /**
 
83
     Last error produced by the I/O or SQL thread respectively.
 
84
   */
 
85
  mutable Error m_last_error;
 
86
 
 
87
  char const *const m_thread_name;
 
88
 
 
89
  // not implemented
 
90
  Slave_reporting_capability(const Slave_reporting_capability& rhs);
 
91
  Slave_reporting_capability& operator=(const Slave_reporting_capability& rhs);
 
92
};
 
93
 
 
94
#endif // RPL_REPORTING_H
 
95