~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/parameters_ms.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2010 PrimeBase Technologies GmbH, Germany
 
1
/* Copyright (C) 2010 PrimeBase Technologies GmbH, Germany
2
2
 *
3
3
 * PrimeBase Media Stream for MySQL
4
4
 *
30
30
#include <drizzled/common.h>
31
31
#include <drizzled/plugin.h>
32
32
#include <drizzled/session.h>
33
 
using namespace std;
34
 
using namespace drizzled;
35
 
using namespace drizzled::plugin;
 
33
 
36
34
 
37
35
#define my_strdup(a,b) strdup(a)
38
36
 
59
57
#include "database_ms.h"
60
58
#include "parameters_ms.h"
61
59
 
 
60
using namespace std;
 
61
using namespace drizzled;
 
62
using namespace drizzled::plugin;
 
63
 
 
64
#include <drizzled/module/option_map.h>
 
65
#include <boost/program_options.hpp>
 
66
namespace po= boost::program_options;
62
67
#ifndef PBMS_PORT
63
68
#define PBMS_PORT 8080
64
69
#endif
65
70
 
66
 
 
67
 
uint32_t pbms_port_number = PBMS_PORT;
 
71
/* Note: 'new' used here is NOT CSObject::new which is a DEBUG define*/
 
72
#ifdef new
 
73
#undef new
 
74
#endif
 
75
 
 
76
 
 
77
#ifdef DRIZZLED
 
78
static port_constraint pbms_port_number;
 
79
 
 
80
static std::string my_repository_threshold;
 
81
static std::string my_temp_log_threshold;
 
82
static std::string my_http_metadata_headers;
 
83
 
 
84
typedef drizzled::constrained_check<uint32_t, 100, 0> percent_constraint;
 
85
static percent_constraint my_garbage_threshold;
 
86
static uint32_nonzero_constraint my_temp_blob_timeout;
 
87
static uint32_nonzero_constraint my_max_keep_alive;
 
88
static uint32_nonzero_constraint my_backup_db_id;
 
89
 
 
90
static uint32_t my_server_id = 1;
 
91
#else
 
92
uint32_t pbms_port_number;
68
93
 
69
94
static char             *my_repository_threshold = NULL;
70
95
static char             *my_temp_log_threshold = NULL;
76
101
 
77
102
static u_long   my_backup_db_id = 1;
78
103
static uint32_t my_server_id = 1;
 
104
#endif
79
105
 
80
106
#ifdef DRIZZLED
81
107
static set<string> my_black_list;
83
109
static CSMutex my_table_list_lock;
84
110
 
85
111
typedef enum {MATCH_ALL, MATCH_DBS, MATCH_SOME, MATCH_NONE, MATCH_UNKNOWN, MATCH_ERROR} TableMatchState;
86
 
static char *my_table_list = NULL;
87
 
static const char *dflt_my_table_list = "*";
 
112
static std::string my_table_list;
88
113
 
89
114
static TableMatchState my_table_match = MATCH_UNKNOWN;
90
115
 
91
 
static int32_t my_before_insert_position= 1;      // Call this event observer first.
92
 
static int32_t my_before_update_position= 1;
 
116
typedef constrained_check<int32_t, INT32_MAX-1, 1> before_position_constraint;
 
117
static before_position_constraint my_before_insert_position;      // Call this event observer first.
 
118
static before_position_constraint my_before_update_position;
93
119
 
94
120
using namespace drizzled;
95
121
using namespace drizzled::plugin;
131
157
//--------------
132
158
uint64_t PBMSParameters::getRepoThreshold()
133
159
{
 
160
#ifdef DRIZZLED
 
161
  return (uint64_t) cs_byte_size_to_int8(my_repository_threshold.c_str());
 
162
#else
134
163
        if (my_repository_threshold)
135
164
                return((uint64_t) cs_byte_size_to_int8(my_repository_threshold));
136
165
 
137
166
        return((uint64_t) cs_byte_size_to_int8(MS_REPO_THRESHOLD_DEF));
 
167
#endif
138
168
}
139
169
 
140
170
//--------------
141
171
uint64_t PBMSParameters::getTempLogThreshold()
142
172
{
 
173
#ifdef DRIZZLED
 
174
  return (uint64_t) cs_byte_size_to_int8(my_temp_log_threshold.c_str());
 
175
#else
143
176
        if (my_temp_log_threshold)
144
177
                return((uint64_t) cs_byte_size_to_int8(my_temp_log_threshold));
145
178
 
146
179
        return((uint64_t) cs_byte_size_to_int8(MS_TEMP_LOG_THRESHOLD_DEF));
 
180
#endif
147
181
}
148
182
 
149
183
//--------------
150
 
uint32_t PBMSParameters::getTempBlobTimeout(){ return my_temp_blob_timeout;}
151
 
 
152
 
//--------------
153
 
uint32_t PBMSParameters::getGarbageThreshold(){ return my_garbage_threshold;}
154
 
 
155
 
//--------------
156
 
uint32_t PBMSParameters::getMaxKeepAlive(){ return my_max_keep_alive;}
 
184
uint32_t PBMSParameters::getTempBlobTimeout(){ return static_cast<uint32_t>(my_temp_blob_timeout);}
 
185
 
 
186
//--------------
 
187
uint32_t PBMSParameters::getGarbageThreshold(){ return static_cast<uint32_t>(my_garbage_threshold);}
 
188
 
 
189
//--------------
 
190
uint32_t PBMSParameters::getMaxKeepAlive(){ return static_cast<uint32_t>(my_max_keep_alive);}
157
191
 
158
192
//--------------
159
193
const char * PBMSParameters::getDefaultMetaDataHeaders()
160
194
{
 
195
#ifdef DRIZZLED
 
196
        return my_http_metadata_headers.c_str();
 
197
#else
161
198
        if (my_http_metadata_headers)
162
199
                return my_http_metadata_headers; 
163
200
                
164
201
        return MS_HTTP_METADATA_HEADERS_DEF; 
 
202
#endif
165
203
}
166
204
 
167
205
//-----------------
168
 
uint32_t PBMSParameters::getBackupDatabaseID() { return my_backup_db_id;}
 
206
uint32_t PBMSParameters::getBackupDatabaseID() { return static_cast<uint32_t>(my_backup_db_id);}
169
207
 
170
208
//-----------------
171
209
void PBMSParameters::setBackupDatabaseID(uint32_t id) { my_backup_db_id = id;}
294
332
        return NULL;
295
333
}
296
334
 
 
335
#ifdef DRIZZLED
 
336
static void temp_blob_timeout_update(Session*, sql_var_t)
 
337
{
 
338
        CSThread                *self;
 
339
        PBMSResultRec   result;
 
340
        
 
341
        if (MSEngine::enterConnectionNoThd(&self, &result))
 
342
                return;
 
343
        try_(a) {
 
344
                MSDatabase::wakeTempLogThreads();
 
345
        }
 
346
        
 
347
        catch_(a);
 
348
        cont_(a);
 
349
}
 
350
//----------
 
351
static int table_list_validate(Session*, set_var *var)
 
352
{
 
353
        const char *list= var->value->str_value.ptr();
 
354
        if (list == NULL)
 
355
                return 1;
 
356
 
 
357
        TableMatchState state = set_match_type(list);
 
358
        if (state == MATCH_ERROR)
 
359
                return 1;
 
360
                
 
361
        std::string new_list(list);
 
362
 
 
363
        my_table_list_lock.lock();
 
364
        my_table_list.swap(new_list);
 
365
        my_table_match = state;
 
366
        my_table_list_lock.unlock();
 
367
 
 
368
        return 0;
 
369
}
 
370
 
 
371
//----------
 
372
#endif
 
373
 
297
374
//--------------
298
375
// Parameter update functions are not called for parameters that are set on
299
376
// the command line. PBMSParameters::startUp() will perform any initialization required.
300
 
void PBMSParameters::startUp()
 
377
#ifdef DRIZZLED
 
378
void PBMSParameters::startUp(drizzled::module::Context &context)
 
379
#else
 
380
void PBMSParameters::startup()
 
381
#endif
301
382
 
383
 
 
384
#ifdef DRIZZLED
 
385
        my_table_match = set_match_type(my_table_list.c_str());
 
386
        const module::option_map &vm= context.getOptions();
 
387
        my_events_enabled= (vm.count("watch-disable")) ? false : true;
 
388
 
 
389
        context.registerVariable(new sys_var_constrained_value_readonly<in_port_t>("port",
 
390
                                                                         pbms_port_number));
 
391
        context.registerVariable(new sys_var_std_string("repository_threshold",
 
392
                                                        my_repository_threshold));
 
393
        context.registerVariable(new sys_var_std_string("temp_log_threshold",
 
394
                                                        my_temp_log_threshold));
 
395
        context.registerVariable(new sys_var_const_string("http_metadata_headers",
 
396
                                                          my_http_metadata_headers));
 
397
        context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("garbage_threshold", my_garbage_threshold));
 
398
        context.registerVariable(new sys_var_constrained_value<uint32_t>("temp_blob_timeout",
 
399
                                                                         my_temp_blob_timeout,
 
400
                                                                         temp_blob_timeout_update));
 
401
        context.registerVariable(new sys_var_constrained_value<uint32_t>("max_keep_alive",
 
402
                                                                         my_max_keep_alive));
 
403
        context.registerVariable(new sys_var_constrained_value<uint32_t>("next_backup_db_id",
 
404
                                                                         my_backup_db_id));
 
405
        context.registerVariable(new sys_var_std_string("watch_tables",
 
406
                                                        my_table_list,
 
407
                                                        table_list_validate));
 
408
        context.registerVariable(new sys_var_bool_ptr("watch_enable",
 
409
                                                      &my_events_enabled));
 
410
        context.registerVariable(new sys_var_constrained_value<int32_t>("before_insert_position",
 
411
                                                                        my_before_insert_position));
 
412
        context.registerVariable(new sys_var_constrained_value<int32_t>("before_update_position",
 
413
                                                                        my_before_update_position));
 
414
 
 
415
#else
302
416
        my_table_match = set_match_type(my_table_list);
303
 
}
 
417
#endif
 
418
}
 
419
 
 
420
 
 
421
#ifdef DRIZZLED
 
422
void PBMSParameters::initOptions(drizzled::module::option_context &context)
 
423
{
 
424
        context("port",
 
425
                po::value<port_constraint>(&pbms_port_number)->default_value(DEFAULT_PBMS_PORT),
 
426
                _("Port number to use for connection or 0 for default PBMS port "));
 
427
        context("repository-threshold",
 
428
                po::value<std::string>(&my_repository_threshold)->default_value(MS_REPO_THRESHOLD_DEF),
 
429
                _("The maximum size of a BLOB repository file."));
 
430
        context("temp-log-threshold",
 
431
                po::value<std::string>(&my_temp_log_threshold)->default_value(MS_TEMP_LOG_THRESHOLD_DEF),
 
432
                _("The maximum size of a temorary BLOB log file."));
 
433
        context("http-metadata-headers",
 
434
                po::value<std::string>(&my_http_metadata_headers)->default_value(MS_HTTP_METADATA_HEADERS_DEF),
 
435
                _("A ':' delimited list of metadata header names to be used to initialize "
 
436
                   "the pbms_metadata_header table when a database is created."));
 
437
        context("garbage-threshold",
 
438
                po::value<percent_constraint>(&my_garbage_threshold)->default_value(MS_DEFAULT_GARBAGE_LEVEL),
 
439
                _("The percentage of garbage in a repository file before it is compacted."));
 
440
        context("temp-blob-timeout",
 
441
                po::value<uint32_nonzero_constraint>(&my_temp_blob_timeout)->default_value(MS_DEFAULT_TEMP_LOG_WAIT),
 
442
                _("The timeout, in seconds, for temporary BLOBs. Uploaded blob data is removed after this time, unless committed to the database."));
 
443
        context("max-keep-alive",
 
444
                po::value<uint32_nonzero_constraint>(&my_temp_blob_timeout)->default_value(MS_DEFAULT_KEEP_ALIVE),
 
445
                _("The timeout, in milli-seconds, before the HTTP server will close an inactive HTTP connection."));
 
446
        context("next-backup-db-id",
 
447
                po::value<uint32_nonzero_constraint>(&my_backup_db_id)->default_value(1),
 
448
                _("The next backup ID to use when backing up a PBMS database."));
 
449
        context("watch-tables",
 
450
                po::value<std::string>(&my_table_list)->default_value("*"),
 
451
                _("A comma delimited list of tables to watch of the format: <database>.<table>, ..."));
 
452
        context("watch-disable",
 
453
                _("Enable PBMS daemon Insert/Update/Delete event scanning"));
 
454
 
 
455
        context("before-insert-position",
 
456
                po::value<before_position_constraint>(&my_before_insert_position)->default_value(1),
 
457
                _("Before insert row event observer call position"));
 
458
 
 
459
        context("before-update-position",
 
460
                po::value<before_position_constraint>(&my_before_update_position)->default_value(1),
 
461
                _("Before update row event observer call position"));
 
462
 
 
463
}
 
464
#endif
304
465
 
305
466
//-----------------
306
467
bool PBMSParameters::isBlackListedDB(const char *db)
325
486
                lock_(&my_table_list_lock);     
326
487
                
327
488
                        
328
 
                *found = (locate_db(my_table_list, db, strlen(db)) != NULL);
 
489
                *found = (locate_db(my_table_list.c_str(), db, strlen(db)) != NULL);
329
490
                        
330
491
                unlock_(&my_table_list_lock);
331
492
                rtc = false;
339
500
//-----------------
340
501
bool PBMSParameters::isBLOBDatabase(const char *db)
341
502
{
342
 
        CSThread *self;
 
503
        CSThread *self= NULL;
343
504
        int             err;
344
505
        PBMSResultRec result;
345
506
        bool found = false;
348
509
                return false;
349
510
                
350
511
        if (my_table_match == MATCH_UNKNOWN)
351
 
                my_table_match = set_match_type(my_table_list);
 
512
        {
 
513
                try_(a) {
 
514
                        lock_(&my_table_list_lock);     
 
515
                        my_table_match = set_match_type(my_table_list.c_str());
 
516
                        unlock_(&my_table_list_lock);
 
517
                }
 
518
 
 
519
                catch_(a)
 
520
                cont_(a);
 
521
        }
352
522
 
353
523
        if (my_table_match == MATCH_NONE)
354
524
                return false;
379
549
{
380
550
        volatile bool rtc = true;
381
551
        try_(a) {
382
 
                const char *ptr;
383
552
                int db_len, table_len, match_len;
384
553
                
385
554
                lock_(&my_table_list_lock);     
387
556
                db_len = strlen(db);
388
557
                table_len = strlen(table);
389
558
                
390
 
                ptr = my_table_list;
 
559
                const char *ptr = my_table_list.c_str();
391
560
                while (ptr) {
392
561
                        ptr = locate_db(ptr, db, db_len);
393
562
                        if (ptr) {
421
590
//-----------------
422
591
bool PBMSParameters::isBLOBTable(const char *db, const char *table)
423
592
{
424
 
        CSThread *self;
 
593
        CSThread *self= NULL;
425
594
        int             err;
426
595
        PBMSResultRec result;
427
596
        bool found = false;
430
599
                return false;
431
600
                
432
601
        if (my_table_match == MATCH_UNKNOWN)
433
 
                my_table_match = set_match_type(my_table_list);
 
602
        {
 
603
                try_(a) {
 
604
                        lock_(&my_table_list_lock);     
 
605
                        my_table_match = set_match_type(my_table_list.c_str());
 
606
                        unlock_(&my_table_list_lock);
 
607
                }
 
608
 
 
609
                catch_(a)
 
610
                cont_(a);
 
611
        }
434
612
 
435
613
        if (my_table_match == MATCH_NONE)
436
614
                return false;
458
636
 
459
637
 
460
638
//-----------------
461
 
int32_t PBMSParameters::getBeforeUptateEventPosition() { return my_before_update_position;}
 
639
int32_t PBMSParameters::getBeforeUptateEventPosition() { return static_cast<int32_t>(my_before_update_position);}
462
640
 
463
641
//-----------------
464
 
int32_t PBMSParameters::getBeforeInsertEventPosition() { return my_before_insert_position;}
 
642
int32_t PBMSParameters::getBeforeInsertEventPosition() { return static_cast<int32_t>(my_before_insert_position);}
465
643
#endif // DRIZZLED
466
644
 
467
645
//-----------------
 
646
#ifndef DRIZZLED
468
647
static void pbms_temp_blob_timeout_func(THD *thd, struct st_mysql_sys_var *var, void *trg, CONST_SAVE void *save)
469
648
{
470
649
        CSThread                *self;
484
663
        catch_(a);
485
664
        cont_(a);
486
665
}
487
 
 
488
 
//-----------------
489
 
//-----------------
 
666
#endif
 
667
//-----------------
 
668
//-----------------
 
669
 
 
670
#ifndef DRIZZLED
 
671
 
490
672
static MYSQL_SYSVAR_UINT(port, pbms_port_number,
491
673
        PLUGIN_VAR_READONLY,
492
674
        "The port for the server stream-based communications.",
528
710
        "The next backup ID to use when backing up a PBMS database.",
529
711
        NULL, NULL, 1, 1, UINT32_MAX, 1);
530
712
 
531
 
 
532
 
#ifdef DRIZZLED
533
 
 
534
 
//----------
535
 
static int check_table_list(THD *, struct st_mysql_sys_var *, void *save, drizzle_value *value)
536
 
{
537
 
        char buffer[100];
538
 
        int len = 100;
539
 
        const char *list = value->val_str(value, buffer, &len);
540
 
        TableMatchState state;
541
 
        
542
 
        state = set_match_type(list);
543
 
        if (state == MATCH_ERROR)
544
 
                return 1;
545
 
                
546
 
        char *new_list = strdup(list);
547
 
        if (!new_list)
548
 
                return 1;
549
 
        
550
 
        my_table_list_lock.lock();
551
 
        if (my_table_list && (my_table_list != dflt_my_table_list)) free(my_table_list);
552
 
        my_table_list = new_list;
553
 
        
554
 
        my_table_match = state;
555
 
        my_table_list_lock.unlock();
556
 
 
557
 
   *static_cast<const char**>(save)= my_table_list;
558
 
 
559
 
        return 0;
560
 
}
561
 
 
562
 
//----------
563
 
static void set_table_list(THD *, struct st_mysql_sys_var *, void *var_ptr, CONST_SAVE void *)
564
 
{
565
 
        // Everything was done in check_table_list()
566
 
  *static_cast<const char**>(var_ptr)= my_table_list;
567
 
}
568
 
 
569
 
//----------
570
 
 
571
 
static MYSQL_SYSVAR_STR(watch_tables,
572
 
                           my_table_list,
573
 
                           PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_MEMALLOC,
574
 
                           N_("A comma delimited list of tables to watch of the format: <database>.<table>, ..."),
575
 
                           check_table_list, /* check func */
576
 
                           set_table_list, /* update func */
577
 
                           dflt_my_table_list /* default */);
578
 
 
579
 
static MYSQL_SYSVAR_BOOL(watch_enable,
580
 
                           my_events_enabled,
581
 
                           PLUGIN_VAR_OPCMDARG,
582
 
                           N_("Enable PBMS daemon Insert/Update/Delete event scanning"),
583
 
                           NULL, /* check func */
584
 
                           NULL, /* update func */
585
 
                           true /* default */);
586
 
 
587
 
static MYSQL_SYSVAR_INT(before_insert_position,
588
 
                           my_before_insert_position,
589
 
                           PLUGIN_VAR_OPCMDARG,
590
 
                           N_("Before insert row event observer call position"),
591
 
                           NULL, /* check func */
592
 
                           NULL, /* update func */
593
 
                           1, /* default */
594
 
                           1, /* min */
595
 
                           INT32_MAX -1, /* max */
596
 
                           0 /* blk */);
597
 
 
598
 
static MYSQL_SYSVAR_INT(before_update_position,
599
 
                           my_before_update_position,
600
 
                           PLUGIN_VAR_OPCMDARG,
601
 
                           N_("Before update row event observer call position"),
602
 
                           NULL, /* check func */
603
 
                           NULL, /* update func */
604
 
                           1, /* default */
605
 
                           1, /* min */
606
 
                           INT32_MAX -1, /* max */
607
 
                           0 /* blk */);
608
 
 
609
 
#endif // DRIZZLED
610
 
 
611
713
struct st_mysql_sys_var* pbms_system_variables[] = {
612
714
        MYSQL_SYSVAR(port),
613
715
        MYSQL_SYSVAR(repository_threshold),
617
719
        MYSQL_SYSVAR(http_metadata_headers),
618
720
        MYSQL_SYSVAR(max_keep_alive),
619
721
        MYSQL_SYSVAR(next_backup_db_id),
620
 
        
621
 
#ifdef DRIZZLED
622
 
        MYSQL_SYSVAR(watch_tables),
623
 
        MYSQL_SYSVAR(watch_enable),
624
 
        
625
 
        MYSQL_SYSVAR(before_insert_position),
626
 
        MYSQL_SYSVAR(before_update_position),
627
 
#endif
628
 
  
629
722
        NULL
630
723
};
631
724
 
632
 
 
633
 
 
634
 
 
635
 
 
 
725
#endif // !DRIZZLED
 
726
 
 
727
 
 
728
// vim:noexpandtab:sts=8:sw=8:tabstop=8:smarttab: