57
59
#include "database_ms.h"
58
60
#include "parameters_ms.h"
61
using namespace drizzled;
62
using namespace drizzled::plugin;
64
#include <drizzled/module/option_map.h>
65
#include <boost/program_options.hpp>
66
namespace po= boost::program_options;
68
63
#define PBMS_PORT 8080
71
/* Note: 'new' used here is NOT CSObject::new which is a DEBUG define*/
78
static port_constraint pbms_port_number;
80
static std::string my_repository_threshold;
81
static std::string my_temp_log_threshold;
82
static std::string my_http_metadata_headers;
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;
90
static uint32_t my_server_id = 1;
92
uint32_t pbms_port_number;
67
static int my_port_number = PBMS_PORT;
94
69
static char *my_repository_threshold = NULL;
95
70
static char *my_temp_log_threshold = NULL;
109
83
static CSMutex my_table_list_lock;
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 = "*";
114
89
static TableMatchState my_table_match = MATCH_UNKNOWN;
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;
120
94
using namespace drizzled;
121
95
using namespace drizzled::plugin;
158
132
uint64_t PBMSParameters::getRepoThreshold()
161
return (uint64_t) cs_byte_size_to_int8(my_repository_threshold.c_str());
163
134
if (my_repository_threshold)
164
135
return((uint64_t) cs_byte_size_to_int8(my_repository_threshold));
166
137
return((uint64_t) cs_byte_size_to_int8(MS_REPO_THRESHOLD_DEF));
171
141
uint64_t PBMSParameters::getTempLogThreshold()
174
return (uint64_t) cs_byte_size_to_int8(my_temp_log_threshold.c_str());
176
143
if (my_temp_log_threshold)
177
144
return((uint64_t) cs_byte_size_to_int8(my_temp_log_threshold));
179
146
return((uint64_t) cs_byte_size_to_int8(MS_TEMP_LOG_THRESHOLD_DEF));
184
uint32_t PBMSParameters::getTempBlobTimeout(){ return static_cast<uint32_t>(my_temp_blob_timeout);}
187
uint32_t PBMSParameters::getGarbageThreshold(){ return static_cast<uint32_t>(my_garbage_threshold);}
190
uint32_t PBMSParameters::getMaxKeepAlive(){ return static_cast<uint32_t>(my_max_keep_alive);}
150
uint32_t PBMSParameters::getTempBlobTimeout(){ return my_temp_blob_timeout;}
153
uint32_t PBMSParameters::getGarbageThreshold(){ return my_garbage_threshold;}
156
uint32_t PBMSParameters::getMaxKeepAlive(){ return my_max_keep_alive;}
193
159
const char * PBMSParameters::getDefaultMetaDataHeaders()
196
return my_http_metadata_headers.c_str();
198
161
if (my_http_metadata_headers)
199
162
return my_http_metadata_headers;
201
164
return MS_HTTP_METADATA_HEADERS_DEF;
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;}
208
170
//-----------------
209
171
void PBMSParameters::setBackupDatabaseID(uint32_t id) { my_backup_db_id = id;}
336
static void temp_blob_timeout_update(Session*, sql_var_t)
339
PBMSResultRec result;
341
if (MSEngine::enterConnectionNoThd(&self, &result))
344
MSDatabase::wakeTempLogThreads();
351
static int table_list_validate(Session*, set_var *var)
353
const char *list= var->value->str_value.ptr();
357
TableMatchState state = set_match_type(list);
358
if (state == MATCH_ERROR)
361
std::string new_list(list);
363
my_table_list_lock.lock();
364
my_table_list.swap(new_list);
365
my_table_match = state;
366
my_table_list_lock.unlock();
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.
378
void PBMSParameters::startUp(drizzled::module::Context &context)
380
void PBMSParameters::startup()
300
void PBMSParameters::startUp()
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;
389
context.registerVariable(new sys_var_constrained_value_readonly<in_port_t>("port",
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",
403
context.registerVariable(new sys_var_constrained_value<uint32_t>("next_backup_db_id",
405
context.registerVariable(new sys_var_std_string("watch_tables",
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));
416
302
my_table_match = set_match_type(my_table_list);
422
void PBMSParameters::initOptions(drizzled::module::option_context &context)
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"));
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"));
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"));
466
305
//-----------------
467
306
bool PBMSParameters::isBlackListedDB(const char *db)
710
528
"The next backup ID to use when backing up a PBMS database.",
711
529
NULL, NULL, 1, 1, UINT32_MAX, 1);
535
static int check_table_list(THD *, struct st_mysql_sys_var *, void *save, drizzle_value *value)
539
const char *list = value->val_str(value, buffer, &len);
540
TableMatchState state;
542
state = set_match_type(list);
543
if (state == MATCH_ERROR)
546
char *new_list = strdup(list);
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;
554
my_table_match = state;
555
my_table_list_lock.unlock();
557
*static_cast<const char**>(save)= my_table_list;
563
static void set_table_list(THD *, struct st_mysql_sys_var *, void *var_ptr, CONST_SAVE void *)
565
// Everything was done in check_table_list()
566
*static_cast<const char**>(var_ptr)= my_table_list;
571
static MYSQL_SYSVAR_STR(watch_tables,
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 */);
579
static MYSQL_SYSVAR_BOOL(watch_enable,
582
N_("Enable PBMS daemon Insert/Update/Delete event scanning"),
583
NULL, /* check func */
584
NULL, /* update func */
587
static MYSQL_SYSVAR_INT(before_insert_position,
588
my_before_insert_position,
590
N_("Before insert row event observer call position"),
591
NULL, /* check func */
592
NULL, /* update func */
595
INT32_MAX -1, /* max */
598
static MYSQL_SYSVAR_INT(before_update_position,
599
my_before_update_position,
601
N_("Before update row event observer call position"),
602
NULL, /* check func */
603
NULL, /* update func */
606
INT32_MAX -1, /* max */
713
611
struct st_mysql_sys_var* pbms_system_variables[] = {
714
612
MYSQL_SYSVAR(port),
715
613
MYSQL_SYSVAR(repository_threshold),