~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/rabbitmq/rabbitmq_log.cc

  • Committer: Jay Pipes
  • Date: 2010-04-08 16:27:25 UTC
  • mfrom: (1405.6.10 replication-pairs)
  • mto: This revision was merged to the branch mainline in revision 1457.
  • Revision ID: jpipes@serialcoder-20100408162725-sugbgn38oxjqclq2
Merge trunk and replication-pairs with conflict resolution

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
 */
77
77
static bool sysvar_rabbitmq_log_enabled= false;
78
78
 
 
79
/**
 
80
 * The name of the replicator plugin
 
81
 * to pair the rabbitmq log's applier with.
 
82
 * Defaults to "default"
 
83
 */
 
84
static char *sysvar_rabbitmq_use_replicator= NULL;
 
85
static const char DEFAULT_USE_REPLICATOR[]= "default";
 
86
 
79
87
 
80
88
RabbitMQLog::RabbitMQLog(const string name_arg, 
81
89
                         RabbitMQHandler* mqHandler)
88
96
{
89
97
}
90
98
 
91
 
void RabbitMQLog::apply(const message::Transaction &to_apply)
 
99
plugin::ReplicationReturnCode
 
100
RabbitMQLog::apply(Session &, const message::Transaction &to_apply)
92
101
{
93
102
  size_t message_byte_length= to_apply.ByteSize();
94
103
  uint8_t* buffer= static_cast<uint8_t *>(malloc(message_byte_length));
96
105
  {
97
106
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate enough memory to transaction message\n"));
98
107
    deactivate();
99
 
    return;
 
108
    return plugin::UNKNOWN_ERROR;
100
109
  }
101
110
 
102
111
  to_apply.SerializeWithCachedSizesToArray(buffer);
111
120
  {
112
121
    errmsg_printf(ERRMSG_LVL_ERROR, _(e.what()));
113
122
    deactivate();
 
123
    return plugin::UNKNOWN_ERROR;
114
124
  }
115
125
  free(buffer);
 
126
  return plugin::SUCCESS;
116
127
}
117
128
 
118
 
RabbitMQLog *rabbitmqLogger; ///< the actual plugin
119
 
RabbitMQHandler* rabbitmqHandler; ///< the rabbitmq handler
 
129
static RabbitMQLog *rabbitmqLogger; ///< the actual plugin
 
130
static RabbitMQHandler* rabbitmqHandler; ///< the rabbitmq handler
120
131
 
121
132
/**
122
133
 * Initialize the rabbitmq logger - instanciates the dependencies (the handler)
123
134
 * and creates the log handler with the dependency - makes it easier to swap out
124
135
 * handler implementation
125
136
 */
126
 
static int init(plugin::Registry &registry)
 
137
static int init(drizzled::plugin::Context &context)
127
138
{
128
139
  if(sysvar_rabbitmq_log_enabled)
129
140
  {
143
154
    }
144
155
    try 
145
156
    {
146
 
      rabbitmqLogger= new RabbitMQLog("rabbit-log", rabbitmqHandler);
 
157
      rabbitmqLogger= new RabbitMQLog("rabbit_log_applier", rabbitmqHandler);
147
158
    } 
148
159
    catch (exception& e) 
149
160
    {
152
163
      return 1;
153
164
    }
154
165
 
155
 
    registry.add(rabbitmqLogger);
 
166
    context.add(rabbitmqLogger);
 
167
    ReplicationServices &replication_services= ReplicationServices::singleton();
 
168
    string replicator_name(sysvar_rabbitmq_use_replicator);
 
169
    replication_services.attachApplier(rabbitmqLogger, replicator_name);
156
170
    return 0;
157
171
  }
158
172
  return 0;
159
173
}
160
174
 
161
 
static int deinit(plugin::Registry &registry)
162
 
{
163
 
  /* Cleanup the logger itself - delete the logger first, then handler, to avoid NPEs */
164
 
  if (rabbitmqLogger)
165
 
  {
166
 
    registry.remove(rabbitmqLogger);
167
 
    delete rabbitmqLogger;
168
 
    delete rabbitmqHandler;
169
 
  }
170
 
 
171
 
  return 0;
172
 
}
173
 
 
174
 
 
175
175
 
176
176
static DRIZZLE_SYSVAR_BOOL(enable,
177
177
                           sysvar_rabbitmq_log_enabled,
242
242
                          NULL, /* update func*/
243
243
                          "ReplicationRoutingKey" /* default */);
244
244
 
 
245
static DRIZZLE_SYSVAR_STR(use_replicator,
 
246
                          sysvar_rabbitmq_use_replicator,
 
247
                          PLUGIN_VAR_READONLY,
 
248
                          N_("Name of the replicator plugin to use (default='default_replicator')"),
 
249
                          NULL, /* check func */
 
250
                          NULL, /* update func*/
 
251
                          DEFAULT_USE_REPLICATOR /* default */);
245
252
 
246
253
static drizzle_sys_var* system_variables[]= {
247
254
  DRIZZLE_SYSVAR(enable),
252
259
  DRIZZLE_SYSVAR(virtualhost),
253
260
  DRIZZLE_SYSVAR(exchange),
254
261
  DRIZZLE_SYSVAR(routingkey),
 
262
  DRIZZLE_SYSVAR(use_replicator),
255
263
  NULL
256
264
};
257
265
 
258
 
DRIZZLE_PLUGIN(init, deinit, NULL, system_variables);
 
266
DRIZZLE_PLUGIN(init, system_variables);
259
267