~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2010-10-28 17:12:01 UTC
  • mfrom: (1887.1.3 merge)
  • Revision ID: brian@tangent.org-20101028171201-baj6l1bnntn1s4ad
Merge in POTFILES changes.

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
 
 
 
33
using namespace std;
 
34
using namespace drizzled;
 
35
using namespace drizzled::plugin;
34
36
 
35
37
#define my_strdup(a,b) strdup(a)
36
38
 
57
59
#include "database_ms.h"
58
60
#include "parameters_ms.h"
59
61
 
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;
67
62
#ifndef PBMS_PORT
68
63
#define PBMS_PORT 8080
69
64
#endif
70
65
 
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;
 
66
 
 
67
static int my_port_number = PBMS_PORT;
93
68
 
94
69
static char             *my_repository_threshold = NULL;
95
70
static char             *my_temp_log_threshold = NULL;
101
76
 
102
77
static u_long   my_backup_db_id = 1;
103
78
static uint32_t my_server_id = 1;
104
 
#endif
105
79
 
106
80
#ifdef DRIZZLED
107
81
static set<string> my_black_list;
109
83
static CSMutex my_table_list_lock;
110
84
 
111
85
typedef enum {MATCH_ALL, MATCH_DBS, MATCH_SOME, MATCH_NONE, MATCH_UNKNOWN, MATCH_ERROR} TableMatchState;
112
 
static std::string my_table_list;
 
86
static char *my_table_list = NULL;
 
87
static const char *dflt_my_table_list = "*";
113
88
 
114
89
static TableMatchState my_table_match = MATCH_UNKNOWN;
115
90
 
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;
 
91
static int32_t my_before_insert_position= 1;      // Call this event observer first.
 
92
static int32_t my_before_update_position= 1;
119
93
 
120
94
using namespace drizzled;
121
95
using namespace drizzled::plugin;
149
123
#endif
150
124
 
151
125
//--------------
152
 
uint32_t PBMSParameters::getPortNumber(){ return pbms_port_number;}
 
126
uint32_t PBMSParameters::getPortNumber(){ return my_port_number;}
153
127
 
154
128
//--------------
155
129
uint32_t PBMSParameters::getServerID(){ return my_server_id;}
157
131
//--------------
158
132
uint64_t PBMSParameters::getRepoThreshold()
159
133
{
160
 
#ifdef DRIZZLED
161
 
  return (uint64_t) cs_byte_size_to_int8(my_repository_threshold.c_str());
162
 
#else
163
134
        if (my_repository_threshold)
164
135
                return((uint64_t) cs_byte_size_to_int8(my_repository_threshold));
165
136
 
166
137
        return((uint64_t) cs_byte_size_to_int8(MS_REPO_THRESHOLD_DEF));
167
 
#endif
168
138
}
169
139
 
170
140
//--------------
171
141
uint64_t PBMSParameters::getTempLogThreshold()
172
142
{
173
 
#ifdef DRIZZLED
174
 
  return (uint64_t) cs_byte_size_to_int8(my_temp_log_threshold.c_str());
175
 
#else
176
143
        if (my_temp_log_threshold)
177
144
                return((uint64_t) cs_byte_size_to_int8(my_temp_log_threshold));
178
145
 
179
146
        return((uint64_t) cs_byte_size_to_int8(MS_TEMP_LOG_THRESHOLD_DEF));
180
 
#endif
181
147
}
182
148
 
183
149
//--------------
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);}
 
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;}
191
157
 
192
158
//--------------
193
159
const char * PBMSParameters::getDefaultMetaDataHeaders()
194
160
{
195
 
#ifdef DRIZZLED
196
 
        return my_http_metadata_headers.c_str();
197
 
#else
198
161
        if (my_http_metadata_headers)
199
162
                return my_http_metadata_headers; 
200
163
                
201
164
        return MS_HTTP_METADATA_HEADERS_DEF; 
202
 
#endif
203
165
}
204
166
 
205
167
//-----------------
206
 
uint32_t PBMSParameters::getBackupDatabaseID() { return static_cast<uint32_t>(my_backup_db_id);}
 
168
uint32_t PBMSParameters::getBackupDatabaseID() { return my_backup_db_id;}
207
169
 
208
170
//-----------------
209
171
void PBMSParameters::setBackupDatabaseID(uint32_t id) { my_backup_db_id = id;}
332
294
        return NULL;
333
295
}
334
296
 
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
 
 
374
297
//--------------
375
298
// Parameter update functions are not called for parameters that are set on
376
299
// the command line. PBMSParameters::startUp() will perform any initialization required.
377
 
#ifdef DRIZZLED
378
 
void PBMSParameters::startUp(drizzled::module::Context &context)
379
 
#else
380
 
void PBMSParameters::startup()
381
 
#endif
 
300
void PBMSParameters::startUp()
382
301
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
416
302
        my_table_match = set_match_type(my_table_list);
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
 
303
}
465
304
 
466
305
//-----------------
467
306
bool PBMSParameters::isBlackListedDB(const char *db)
486
325
                lock_(&my_table_list_lock);     
487
326
                
488
327
                        
489
 
                *found = (locate_db(my_table_list.c_str(), db, strlen(db)) != NULL);
 
328
                *found = (locate_db(my_table_list, db, strlen(db)) != NULL);
490
329
                        
491
330
                unlock_(&my_table_list_lock);
492
331
                rtc = false;
500
339
//-----------------
501
340
bool PBMSParameters::isBLOBDatabase(const char *db)
502
341
{
503
 
        CSThread *self= NULL;
 
342
        CSThread *self;
504
343
        int             err;
505
344
        PBMSResultRec result;
506
345
        bool found = false;
509
348
                return false;
510
349
                
511
350
        if (my_table_match == MATCH_UNKNOWN)
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
 
        }
 
351
                my_table_match = set_match_type(my_table_list);
522
352
 
523
353
        if (my_table_match == MATCH_NONE)
524
354
                return false;
549
379
{
550
380
        volatile bool rtc = true;
551
381
        try_(a) {
 
382
                const char *ptr;
552
383
                int db_len, table_len, match_len;
553
384
                
554
385
                lock_(&my_table_list_lock);     
556
387
                db_len = strlen(db);
557
388
                table_len = strlen(table);
558
389
                
559
 
                const char *ptr = my_table_list.c_str();
 
390
                ptr = my_table_list;
560
391
                while (ptr) {
561
392
                        ptr = locate_db(ptr, db, db_len);
562
393
                        if (ptr) {
590
421
//-----------------
591
422
bool PBMSParameters::isBLOBTable(const char *db, const char *table)
592
423
{
593
 
        CSThread *self= NULL;
 
424
        CSThread *self;
594
425
        int             err;
595
426
        PBMSResultRec result;
596
427
        bool found = false;
599
430
                return false;
600
431
                
601
432
        if (my_table_match == MATCH_UNKNOWN)
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
 
        }
 
433
                my_table_match = set_match_type(my_table_list);
612
434
 
613
435
        if (my_table_match == MATCH_NONE)
614
436
                return false;
636
458
 
637
459
 
638
460
//-----------------
639
 
int32_t PBMSParameters::getBeforeUptateEventPosition() { return static_cast<int32_t>(my_before_update_position);}
 
461
int32_t PBMSParameters::getBeforeUptateEventPosition() { return my_before_update_position;}
640
462
 
641
463
//-----------------
642
 
int32_t PBMSParameters::getBeforeInsertEventPosition() { return static_cast<int32_t>(my_before_insert_position);}
 
464
int32_t PBMSParameters::getBeforeInsertEventPosition() { return my_before_insert_position;}
643
465
#endif // DRIZZLED
644
466
 
645
467
//-----------------
646
 
#ifndef DRIZZLED
647
468
static void pbms_temp_blob_timeout_func(THD *thd, struct st_mysql_sys_var *var, void *trg, CONST_SAVE void *save)
648
469
{
649
470
        CSThread                *self;
663
484
        catch_(a);
664
485
        cont_(a);
665
486
}
666
 
#endif
667
 
//-----------------
668
 
//-----------------
669
 
 
670
 
#ifndef DRIZZLED
671
 
 
672
 
static MYSQL_SYSVAR_UINT(port, pbms_port_number,
673
 
        PLUGIN_VAR_READONLY,
 
487
 
 
488
//-----------------
 
489
//-----------------
 
490
static MYSQL_SYSVAR_INT(port, my_port_number,
 
491
        PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
674
492
        "The port for the server stream-based communications.",
675
493
        NULL, NULL, PBMS_PORT, 0, 64*1024, 1);
676
494
 
710
528
        "The next backup ID to use when backing up a PBMS database.",
711
529
        NULL, NULL, 1, 1, UINT32_MAX, 1);
712
530
 
 
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
 
713
611
struct st_mysql_sys_var* pbms_system_variables[] = {
714
612
        MYSQL_SYSVAR(port),
715
613
        MYSQL_SYSVAR(repository_threshold),
719
617
        MYSQL_SYSVAR(http_metadata_headers),
720
618
        MYSQL_SYSVAR(max_keep_alive),
721
619
        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
  
722
629
        NULL
723
630
};
724
631
 
725
 
#endif // !DRIZZLED
726
 
 
727
 
 
728
 
// vim:noexpandtab:sts=8:sw=8:tabstop=8:smarttab:
 
632
 
 
633
 
 
634
 
 
635