~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_gearman/logging_gearman.cc

  • Committer: Stewart Smith
  • Date: 2009-08-20 17:15:54 UTC
  • mto: (1119.2.2 merge)
  • mto: This revision was merged to the branch mainline in revision 1124.
  • Revision ID: stewart@flamingspork.com-20090820171554-72eo1tqlc4n64rak
Valgrind 3.5 requires --alignment to be a power of 2 between 16 and 4096. The specifying --alignment is not important for us, so remove it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
#include <drizzled/plugin/logging.h>
 
20
#include <drizzled/server_includes.h>
 
21
#include <drizzled/plugin/logging_handler.h>
22
22
#include <drizzled/gettext.h>
23
23
#include <drizzled/session.h>
24
24
 
25
25
#include <libgearman/gearman.h>
26
 
#include <limits.h>
27
 
#include <sys/time.h>
28
 
#include <sys/types.h>
29
 
#include <sys/stat.h>
30
 
#include <fcntl.h>
31
 
 
32
 
 
33
 
using namespace drizzled;
34
26
 
35
27
 
36
28
/* TODO make this dynamic as needed */
45
37
   until the Session has a good utime "now" we can use
46
38
   will have to use this instead */
47
39
 
 
40
#include <sys/time.h>
48
41
static uint64_t get_microtime()
49
42
{
50
43
#if defined(HAVE_GETHRTIME)
169
162
  return dst;
170
163
}
171
164
 
172
 
class LoggingGearman : public plugin::Logging
 
165
class LoggingGearman : public Logging_handler
173
166
{
174
167
 
175
168
  int gearman_client_ok;
177
170
 
178
171
public:
179
172
 
180
 
  LoggingGearman()
181
 
    : plugin::Logging("LoggingGearman"),
182
 
      gearman_client_ok(0)
 
173
  LoggingGearman() : Logging_handler("LoggingGearman"), gearman_client_ok(0)
183
174
  {
184
175
    gearman_return_t ret;
185
176
 
244
235
    unsigned char qs[255];
245
236
  
246
237
    // to avoid trying to printf %s something that is potentially NULL
247
 
    const char *dbs= session->db.empty() ? "" : session->db.c_str();
 
238
    const char *dbs= (session->db) ? session->db : "";
 
239
    int dbl= 0;
 
240
    if (dbs != NULL)
 
241
      dbl= session->db_length;
 
242
  
 
243
    // todo, add hostname, listener port, and server id to this
248
244
  
249
245
    msgbuf_len=
250
246
      snprintf(msgbuf, MAX_MSG_LEN,
251
247
               "%"PRIu64",%"PRIu64",%"PRIu64",\"%.*s\",\"%s\",\"%.*s\","
252
 
               "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64","
253
 
               "%"PRIu32",%"PRIu32",%"PRIu32",\"%s\"",
 
248
               "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64
 
249
               "%"PRIu32",%"PRIu32"",
254
250
               t_mark,
255
251
               session->thread_id,
256
 
               session->getQueryId(),
 
252
               session->query_id,
257
253
               // dont need to quote the db name, always CSV safe
258
 
               (int)session->db.length(), dbs,
 
254
               dbl, dbs,
259
255
               // do need to quote the query
260
 
               quotify((const unsigned char *)session->getQueryString().c_str(),
261
 
                       session->getQueryLength(), qs, sizeof(qs)),
 
256
               quotify((unsigned char *)session->query,
 
257
                       session->query_length, qs, sizeof(qs)),
262
258
               // command_name is defined in drizzled/sql_parse.cc
263
259
               // dont need to quote the command name, always CSV safe
264
260
               (int)command_name[session->command].length,
270
266
               session->sent_row_count,
271
267
               session->examined_row_count,
272
268
               session->tmp_table,
273
 
               session->total_warn_count,
274
 
               session->getServerId(),
275
 
               glob_hostname
276
 
               );
 
269
               session->total_warn_count);
277
270
  
278
271
    char job_handle[GEARMAN_JOB_HANDLE_SIZE];
279
272
  
288
281
  }
289
282
};
290
283
 
291
 
static LoggingGearman *handler= NULL;
 
284
static Logging_handler *handler= NULL;
292
285
 
293
 
static int logging_gearman_plugin_init(plugin::Context &context)
 
286
static int logging_gearman_plugin_init(drizzled::plugin::Registry &registry)
294
287
{
295
288
  handler= new LoggingGearman();
296
 
  context.add(handler);
 
289
  registry.add(handler);
 
290
 
 
291
  return 0;
 
292
}
 
293
 
 
294
static int logging_gearman_plugin_deinit(drizzled::plugin::Registry &registry)
 
295
{
 
296
  registry.remove(handler);
 
297
  delete(handler);
297
298
 
298
299
  return 0;
299
300
}
325
326
                          NULL, /* update func*/
326
327
                          "drizzlelog" /* default */);
327
328
 
328
 
static drizzle_sys_var* logging_gearman_system_variables[]= {
 
329
static struct st_mysql_sys_var* logging_gearman_system_variables[]= {
329
330
  DRIZZLE_SYSVAR(enable),
330
331
  DRIZZLE_SYSVAR(host),
331
332
  DRIZZLE_SYSVAR(function),
332
333
  NULL
333
334
};
334
335
 
335
 
DRIZZLE_DECLARE_PLUGIN
 
336
drizzle_declare_plugin(logging_gearman)
336
337
{
337
 
  DRIZZLE_VERSION_ID,
338
338
    "logging_gearman",
339
339
    "0.1",
340
340
    "Mark Atwood <mark@fallenpegasus.com>",
341
341
    N_("Log queries to a Gearman server"),
342
342
    PLUGIN_LICENSE_GPL,
343
343
    logging_gearman_plugin_init,
 
344
    logging_gearman_plugin_deinit,
 
345
    NULL,   /* status variables */
344
346
    logging_gearman_system_variables,
345
347
    NULL
346
348
}
347
 
DRIZZLE_DECLARE_PLUGIN_END;
 
349
drizzle_declare_plugin_end;