~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_gearman/logging_gearman.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 01:03:01 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913010301-tcvvezipx1124acy
Added calls to the dtrace delete begin/end probes.

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
 
248
244
  
249
245
    msgbuf_len=
250
246
      snprintf(msgbuf, MAX_MSG_LEN,
251
247
               "%"PRIu64",%"PRIu64",%"PRIu64",\"%.*s\",\"%s\",\"%.*s\","
252
248
               "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64","
253
 
               "%"PRIu32",%"PRIu32",%"PRIu32",\"%s\"",
 
249
               "%"PRIu32",%"PRIu32",%"PRIu32",\"%s\",%"PRIu32"",
254
250
               t_mark,
255
251
               session->thread_id,
256
252
               session->getQueryId(),
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(),
 
256
               quotify((unsigned char *)session->getQueryString(),
261
257
                       session->getQueryLength(), 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
272
268
               session->tmp_table,
273
269
               session->total_warn_count,
274
270
               session->getServerId(),
275
 
               glob_hostname
 
271
               glob_hostname,
 
272
               drizzled_tcp_port
276
273
               );
277
274
  
278
275
    char job_handle[GEARMAN_JOB_HANDLE_SIZE];
288
285
  }
289
286
};
290
287
 
291
 
static LoggingGearman *handler= NULL;
 
288
static Logging_handler *handler= NULL;
292
289
 
293
 
static int logging_gearman_plugin_init(plugin::Context &context)
 
290
static int logging_gearman_plugin_init(drizzled::plugin::Registry &registry)
294
291
{
295
292
  handler= new LoggingGearman();
296
 
  context.add(handler);
 
293
  registry.add(handler);
 
294
 
 
295
  return 0;
 
296
}
 
297
 
 
298
static int logging_gearman_plugin_deinit(drizzled::plugin::Registry &registry)
 
299
{
 
300
  registry.remove(handler);
 
301
  delete(handler);
297
302
 
298
303
  return 0;
299
304
}
325
330
                          NULL, /* update func*/
326
331
                          "drizzlelog" /* default */);
327
332
 
328
 
static drizzle_sys_var* logging_gearman_system_variables[]= {
 
333
static struct st_mysql_sys_var* logging_gearman_system_variables[]= {
329
334
  DRIZZLE_SYSVAR(enable),
330
335
  DRIZZLE_SYSVAR(host),
331
336
  DRIZZLE_SYSVAR(function),
332
337
  NULL
333
338
};
334
339
 
335
 
DRIZZLE_DECLARE_PLUGIN
 
340
drizzle_declare_plugin(logging_gearman)
336
341
{
337
 
  DRIZZLE_VERSION_ID,
338
342
    "logging_gearman",
339
343
    "0.1",
340
344
    "Mark Atwood <mark@fallenpegasus.com>",
341
345
    N_("Log queries to a Gearman server"),
342
346
    PLUGIN_LICENSE_GPL,
343
347
    logging_gearman_plugin_init,
 
348
    logging_gearman_plugin_deinit,
 
349
    NULL,   /* status variables */
344
350
    logging_gearman_system_variables,
345
351
    NULL
346
352
}
347
 
DRIZZLE_DECLARE_PLUGIN_END;
 
353
drizzle_declare_plugin_end;