~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/replication_services.h

  • Committer: Stewart Smith
  • Date: 2008-07-13 06:56:15 UTC
  • mto: (210.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 211.
  • Revision ID: stewart@flamingspork.com-20080713065615-vzok75kgnnviokl9
Move MD5() into a UDF

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 *  Copyright (c) 2009-2010 Jay Pipes <jaypipes@gmail.com>
6
 
 *
7
 
 *  Authors:
8
 
 *
9
 
 *    Jay Pipes <jaypipes@gmail.com>
10
 
 *
11
 
 *  This program is free software; you can redistribute it and/or modify
12
 
 *  it under the terms of the GNU General Public License as published by
13
 
 *  the Free Software Foundation; version 2 of the License.
14
 
 *
15
 
 *  This program is distributed in the hope that it will be useful,
16
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
 *  GNU General Public License for more details.
19
 
 *
20
 
 *  You should have received a copy of the GNU General Public License
21
 
 *  along with this program; if not, write to the Free Software
22
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23
 
 */
24
 
 
25
 
#ifndef DRIZZLED_REPLICATION_SERVICES_H
26
 
#define DRIZZLED_REPLICATION_SERVICES_H
27
 
 
28
 
#include "drizzled/atomics.h"
29
 
 
30
 
#include <vector>
31
 
 
32
 
namespace drizzled
33
 
{
34
 
 
35
 
/* some forward declarations needed */
36
 
class Session;
37
 
class Table;
38
 
 
39
 
namespace plugin
40
 
{
41
 
  class TransactionReplicator;
42
 
  class TransactionApplier;
43
 
}
44
 
namespace message
45
 
{
46
 
  class Transaction;
47
 
}
48
 
 
49
 
/**
50
 
 * This is a class which manages transforming internal 
51
 
 * transactional events into GPB messages and sending those
52
 
 * events out through registered replicators and appliers.
53
 
 */
54
 
class ReplicationServices
55
 
{
56
 
public:
57
 
  typedef uint64_t GlobalTransactionId;
58
 
  /**
59
 
   * Types of messages that can go in the transaction
60
 
   * log file.  Every time something is written into the
61
 
   * transaction log, it is preceded by a header containing
62
 
   * the type of message which follows.
63
 
   */
64
 
  enum MessageType
65
 
  {
66
 
    TRANSACTION= 1, /* A GPB Transaction Message */
67
 
    BLOB= 2 /* A BLOB value */
68
 
  };
69
 
  typedef std::vector<plugin::TransactionReplicator *> Replicators;
70
 
  typedef std::vector<plugin::TransactionApplier *> Appliers;
71
 
private:
72
 
  /** 
73
 
   * Atomic boolean set to true if any *active* replicators
74
 
   * or appliers are actually registered.
75
 
   */
76
 
  atomic<bool> is_active;
77
 
  /**
78
 
   * The timestamp of the last time a Transaction message was successfully
79
 
   * applied (sent to an Applier)
80
 
   */
81
 
  atomic<uint64_t> last_applied_timestamp;
82
 
  /** Our collection of replicator plugins */
83
 
  Replicators replicators;
84
 
  /** Our collection of applier plugins */
85
 
  Appliers appliers;
86
 
  /**
87
 
   * Helper method which is called after any change in the
88
 
   * registered appliers or replicators to evaluate whether
89
 
   * any remaining plugins are actually active.
90
 
   * 
91
 
   * This method properly sets the is_active member variable.
92
 
   */
93
 
  void evaluateActivePlugins();
94
 
public:
95
 
  /** 
96
 
   * Helper method which pushes a constructed message out to the registered
97
 
   * replicator and applier plugins.
98
 
   *
99
 
   * @param Message to push out
100
 
   */
101
 
  void pushTransactionMessage(message::Transaction &to_push);
102
 
  /**
103
 
   * Constructor
104
 
   */
105
 
  ReplicationServices();
106
 
 
107
 
  /**
108
 
   * Singleton method
109
 
   * Returns the singleton instance of ReplicationServices
110
 
   */
111
 
  static inline ReplicationServices &singleton()
112
 
  {
113
 
    static ReplicationServices replication_services;
114
 
    return replication_services;
115
 
  }
116
 
 
117
 
  /**
118
 
   * Returns whether the ReplicationServices object
119
 
   * is active.  In other words, does it have both
120
 
   * a replicator and an applier that are *active*?
121
 
   */
122
 
  bool isActive() const;
123
 
  /**
124
 
   * Attaches a replicator to our internal collection of
125
 
   * replicators.
126
 
   *
127
 
   * @param Pointer to a replicator to attach/register
128
 
   */
129
 
  void attachReplicator(plugin::TransactionReplicator *in_replicator);
130
 
  /**
131
 
   * Detaches/unregisters a replicator with our internal
132
 
   * collection of replicators.
133
 
   *
134
 
   * @param Pointer to the replicator to detach
135
 
   */
136
 
  void detachReplicator(plugin::TransactionReplicator *in_replicator);
137
 
  /**
138
 
   * Attaches a applier to our internal collection of
139
 
   * appliers.
140
 
   *
141
 
   * @param Pointer to a applier to attach/register
142
 
   */
143
 
  void attachApplier(plugin::TransactionApplier *in_applier);
144
 
  /**
145
 
   * Detaches/unregisters a applier with our internal
146
 
   * collection of appliers.
147
 
   *
148
 
   * @param Pointer to the applier to detach
149
 
   */
150
 
  void detachApplier(plugin::TransactionApplier *in_applier);
151
 
  /** Returns the timestamp of the last Transaction which was sent to an
152
 
   * applier.
153
 
   */
154
 
  uint64_t getLastAppliedTimestamp() const;
155
 
};
156
 
 
157
 
} /* namespace drizzled */
158
 
 
159
 
#endif /* DRIZZLED_REPLICATION_SERVICES_H */