~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/replicator.h

  • Committer: Brian Aker
  • Date: 2009-04-13 16:22:40 UTC
  • mfrom: (971.1.78 mordred)
  • Revision ID: brian@gaz-20090413162240-ugi3gvhofmcuglzl
Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3
 
  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
 
 
5
 
  *  Definitions required for Configuration Variables plugin
6
 
 
7
 
  *  Copyright (C) 2008 Mark Atwood
8
 
  *
9
 
  *  This program is free software; you can redistribute it and/or modify
10
 
  *  it under the terms of the GNU General Public License as published by
11
 
  *  the Free Software Foundation; version 2 of the License.
12
 
  *
13
 
  *  This program is distributed in the hope that it will be useful,
14
 
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
  *  GNU General Public License for more details.
17
 
  *
18
 
  *  You should have received a copy of the GNU General Public License
19
 
  *  along with this program; if not, write to the Free Software
20
 
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21
 
  */
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008-2009 Sun Microsystems
 
5
 *
 
6
 *  Authors:
 
7
 *
 
8
 *    Jay Pipes <joinfu@sun.com>
 
9
 *
 
10
 *  This program is free software; you can redistribute it and/or modify
 
11
 *  it under the terms of the GNU General Public License as published by
 
12
 *  the Free Software Foundation; version 2 of the License.
 
13
 *
 
14
 *  This program is distributed in the hope that it will be useful,
 
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *  GNU General Public License for more details.
 
18
 *
 
19
 *  You should have received a copy of the GNU General Public License
 
20
 *  along with this program; if not, write to the Free Software
 
21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
22
 */
22
23
 
23
24
#ifndef DRIZZLED_PLUGIN_REPLICATOR_H
24
25
#define DRIZZLED_PLUGIN_REPLICATOR_H
25
26
 
26
27
/**
27
 
 * @file
28
 
 *
29
 
 * Defines the API for Replication
 
28
 * @file Defines the API for a Replicator.  
 
29
 *
 
30
 * All a replicator does is replicate/reproduce
 
31
 * events, optionally transforming them before sending them off to an applier.
 
32
 *
 
33
 * An applier is responsible for applying events, not a replicator...
30
34
 */
31
35
 
 
36
/* some forward declarations needed */
 
37
namespace drizzled
 
38
{
 
39
  namespace message
 
40
  {
 
41
    class Command;
 
42
  }
 
43
  class Applier;
 
44
}
 
45
 
 
46
namespace drizzled
 
47
{
 
48
namespace plugin
 
49
{
 
50
 
32
51
/**
33
 
 * Base class for replication implementations.
34
 
 *
35
 
 *    if a method returns bool true, that means it failed.
 
52
 * Class which replicates Command messages
36
53
 */
37
54
class Replicator
38
55
{
39
 
private:
40
 
  bool enabled;
41
 
protected:
42
 
  virtual bool session_init_hook(Session *) { return false; }
43
 
  virtual bool row_insert_hook(Session *, Table *) { return false; }
44
 
  virtual bool row_update_hook(Session *, Table *,
45
 
                               const unsigned char *,
46
 
                               const unsigned char *) { return false; }
47
 
  virtual bool row_delete_hook(Session *, Table *) { return false; }
48
 
  virtual bool end_transaction_hook(Session *, bool, bool) { return false; }
49
 
  virtual bool statement_hook(Session *, const char *, size_t) { return false; }
50
56
public:
51
 
 
52
 
  Replicator() : enabled(true) {}
53
 
 
 
57
  Replicator() {}
54
58
  virtual ~Replicator() {}
55
59
  /**
56
 
   * Initialize session for replication
57
 
   */
58
 
  bool session_init(Session *session)
59
 
  {
60
 
    return session_init_hook(session);
61
 
  }
62
 
 
63
 
  /**
64
 
   * Row insert
65
 
   *
66
 
   * @param current Session
67
 
   * @param Table inserted
68
 
   */
69
 
  bool row_insert(Session *session, Table *table)
70
 
  {
71
 
    return row_insert_hook(session, table);
72
 
  }
73
 
 
74
 
  /**
75
 
   * Row update
76
 
   *
77
 
   * @param current Session
78
 
   * @param Table updated
79
 
   * @param before values
80
 
   * @param after values
81
 
   */
82
 
  bool row_update(Session *session, Table *table,
83
 
                          const unsigned char *before,
84
 
                          const unsigned char *after)
85
 
  {
86
 
    return row_update_hook(session, table, before, after);
87
 
  }
88
 
 
89
 
  /**
90
 
   * Row Delete
91
 
   *
92
 
   * @param current session
93
 
   * @param Table deleted from
94
 
   */
95
 
  bool row_delete(Session *session, Table *table)
96
 
  {
97
 
    return row_delete_hook(session, table);
98
 
  }
99
 
 
100
 
  /**
101
 
   * End Transaction
102
 
   *
103
 
   * @param current Session
104
 
   * @param is autocommit on?
105
 
   * @param did the transaction commit?
106
 
   */
107
 
  bool end_transaction(Session *session, bool autocommit, bool commit)
108
 
  {
109
 
    return end_transaction_hook(session, autocommit, commit);
110
 
  }
111
 
 
112
 
  /**
113
 
   * Raw statement
114
 
   *
115
 
   * @param current Session
116
 
   * @param query string
117
 
   * @param length of query string in bytes
118
 
   */
119
 
  bool statement(Session *session, const char *query, size_t query_length)
120
 
  {
121
 
    return statement_hook(session, query, query_length);
122
 
  }
 
60
   * Replicate a Command message to an Applier.
 
61
   *
 
62
   * @note
 
63
   *
 
64
   * It is important to note that memory allocation for the 
 
65
   * supplied pointer is not guaranteed after the completion 
 
66
   * of this function -- meaning the caller can dispose of the
 
67
   * supplied message.  Therefore, replicators and appliers 
 
68
   * implementing an asynchronous replication system must copy
 
69
   * the supplied message to their own controlled memory storage
 
70
   * area.
 
71
   *
 
72
   * @param Command message to be replicated
 
73
   */
 
74
  virtual void replicate(Applier *in_applier, drizzled::message::Command *to_replicate)= 0;
 
75
  /** 
 
76
   * A replicator plugin should override this with its
 
77
   * internal method for determining if it is active or not.
 
78
   */
 
79
  virtual bool isActive() {return false;}
123
80
};
124
81
 
 
82
} /* end namespace drizzled::plugin */
 
83
} /* end namespace drizzled */
 
84
 
125
85
#endif /* DRIZZLED_PLUGIN_REPLICATOR_H */