~drizzle-trunk/drizzle/development

1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
1
/* Copyright (c) 2010 PrimeBase Technologies GmbH, Germany
2
 *
3
 * PrimeBase Media Stream for MySQL
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
18
 *
19
 * Barry Leslie
20
 *
21
 * 2010-05-25
22
 *
23
 * PBMS daemon global parameters.
24
 *
25
 */
26
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
27
#ifdef DRIZZLED
28
#include "config.h"
29
#include <set>
30
#include <drizzled/common.h>
31
#include <drizzled/plugin.h>
32
#include <drizzled/session.h>
33
1976.2.1 by Monty Taylor
Updated PBMS.
34
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
35
#define my_strdup(a,b) strdup(a)
36
37
#include "cslib/CSConfig.h"
38
#else
39
#include "cslib/CSConfig.h"
40
#include "mysql_priv.h"
41
#include <mysql/plugin.h>
42
#include <my_dir.h>
43
#endif 
44
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
45
#include <inttypes.h>
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
46
#include <string.h>
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
47
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
48
#include "cslib/CSDefs.h"
49
#include "cslib/CSObject.h"
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
50
#include "cslib/CSGlobal.h"
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
51
#include "cslib/CSThread.h"
52
#include "cslib/CSStrUtil.h"
53
#include "cslib/CSPath.h"
54
#include "cslib/CSLog.h"
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
55
1548.2.10 by Barry.Leslie at PrimeBase
Merge from trunk.
56
#include "defs_ms.h"
57
#include "database_ms.h"
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
58
#include "parameters_ms.h"
59
1976.2.22 by Monty Taylor
Fixed the pbms debug build for now.
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;
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
67
#ifndef PBMS_PORT
68
#define PBMS_PORT 8080
69
#endif
70
1976.2.22 by Monty Taylor
Fixed the pbms debug build for now.
71
/* Note: 'new' used here is NOT CSObject::new which is a DEBUG define*/
72
#ifdef new
73
#undef new
74
#endif
75
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
76
1976.2.1 by Monty Taylor
Updated PBMS.
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;
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
93
94
static char		*my_repository_threshold = NULL;
95
static char		*my_temp_log_threshold = NULL;
96
static char		*my_http_metadata_headers = NULL;
97
98
static u_long	my_temp_blob_timeout = MS_DEFAULT_TEMP_LOG_WAIT;
99
static u_long	my_garbage_threshold = MS_DEFAULT_GARBAGE_LEVEL;
100
static u_long	my_max_keep_alive = MS_DEFAULT_KEEP_ALIVE;
101
1644.3.1 by Barry.Leslie at PrimeBase
Merged in changes from PBMS project.
102
static u_long	my_backup_db_id = 1;
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
103
static uint32_t my_server_id = 1;
1976.2.1 by Monty Taylor
Updated PBMS.
104
#endif
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
105
1548.2.11 by Barry.Leslie at PrimeBase
Removed libxml reqirement by using a home grown xml parser.
106
#ifdef DRIZZLED
107
static set<string> my_black_list;
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
108
static bool my_events_enabled = true;
109
static CSMutex my_table_list_lock;
110
111
typedef enum {MATCH_ALL, MATCH_DBS, MATCH_SOME, MATCH_NONE, MATCH_UNKNOWN, MATCH_ERROR} TableMatchState;
1976.2.1 by Monty Taylor
Updated PBMS.
112
static std::string my_table_list;
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
113
1548.2.6 by Barry.Leslie at PrimeBase
trunk merge plus more pbms updates for drizzle.
114
static TableMatchState my_table_match = MATCH_UNKNOWN;
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
115
1976.2.1 by Monty Taylor
Updated PBMS.
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;
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
119
120
using namespace drizzled;
121
using namespace drizzled::plugin;
122
123
#define st_mysql_sys_var drizzled::drizzle_sys_var
124
#else
125
126
struct st_mysql_sys_var
127
{
128
  MYSQL_PLUGIN_VAR_HEADER;
129
};
130
131
#endif
132
133
#if MYSQL_VERSION_ID < 60000
134
135
#if MYSQL_VERSION_ID >= 50124
136
#define CONST_SAVE const
137
#endif
138
139
#else
140
141
#if MYSQL_VERSION_ID >= 60005
142
#define CONST_SAVE const
143
#endif
144
145
#endif
146
147
#ifndef CONST_SAVE
148
#define CONST_SAVE 
149
#endif
150
151
//--------------
1909.4.4 by Stewart Smith
fix PBMS port variable to also be a command line option. Also add this to the master.opt for the PBMS test suite so that we'll start PBMS with our port number and won't conflict with 8080
152
uint32_t PBMSParameters::getPortNumber(){ return pbms_port_number;}
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
153
154
//--------------
155
uint32_t PBMSParameters::getServerID(){ return my_server_id;}
156
157
//--------------
158
uint64_t PBMSParameters::getRepoThreshold()
159
{
1976.2.1 by Monty Taylor
Updated PBMS.
160
#ifdef DRIZZLED
161
  return (uint64_t) cs_byte_size_to_int8(my_repository_threshold.c_str());
162
#else
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
163
	if (my_repository_threshold)
164
		return((uint64_t) cs_byte_size_to_int8(my_repository_threshold));
165
166
	return((uint64_t) cs_byte_size_to_int8(MS_REPO_THRESHOLD_DEF));
1976.2.1 by Monty Taylor
Updated PBMS.
167
#endif
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
168
}
169
170
//--------------
171
uint64_t PBMSParameters::getTempLogThreshold()
172
{
1976.2.1 by Monty Taylor
Updated PBMS.
173
#ifdef DRIZZLED
174
  return (uint64_t) cs_byte_size_to_int8(my_temp_log_threshold.c_str());
175
#else
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
176
	if (my_temp_log_threshold)
177
		return((uint64_t) cs_byte_size_to_int8(my_temp_log_threshold));
178
179
	return((uint64_t) cs_byte_size_to_int8(MS_TEMP_LOG_THRESHOLD_DEF));
1976.2.1 by Monty Taylor
Updated PBMS.
180
#endif
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
181
}
182
183
//--------------
1976.2.1 by Monty Taylor
Updated PBMS.
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);}
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
191
192
//--------------
193
const char * PBMSParameters::getDefaultMetaDataHeaders()
194
{
1976.2.1 by Monty Taylor
Updated PBMS.
195
#ifdef DRIZZLED
196
        return my_http_metadata_headers.c_str();
197
#else
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
198
	if (my_http_metadata_headers)
199
		return my_http_metadata_headers; 
200
		
201
	return MS_HTTP_METADATA_HEADERS_DEF; 
1976.2.1 by Monty Taylor
Updated PBMS.
202
#endif
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
203
}
204
205
//-----------------
1976.2.1 by Monty Taylor
Updated PBMS.
206
uint32_t PBMSParameters::getBackupDatabaseID() { return static_cast<uint32_t>(my_backup_db_id);}
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
207
208
//-----------------
1644.3.1 by Barry.Leslie at PrimeBase
Merged in changes from PBMS project.
209
void PBMSParameters::setBackupDatabaseID(uint32_t id) { my_backup_db_id = id;}
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
210
1548.2.11 by Barry.Leslie at PrimeBase
Removed libxml reqirement by using a home grown xml parser.
211
#ifdef DRIZZLED
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
212
//-----------------
213
bool PBMSParameters::isPBMSEventsEnabled() { return my_events_enabled;}
214
215
216
#define NEXT_IN_TABLE_LIST(list) {\
217
	while ((*list) && (*list != ',')) list++;\
218
	if (*list) list++;\
219
}
220
	
221
static TableMatchState set_match_type(const char *list)
222
{
223
	const char *ptr = list;
224
	const char *name;
225
	int name_len;
226
	TableMatchState match_state;
227
228
	if (!list)
229
		return MATCH_ALL;
230
		
231
	if (!ptr) {
232
		return MATCH_NONE;
233
	}
234
	
235
	while ((*ptr) && isspace(*ptr)) ptr++;
236
	if (!*ptr) {
237
		return MATCH_NONE;
238
	}
239
	
240
	match_state = MATCH_UNKNOWN;
241
242
	while (*ptr) {
243
	
244
		// Check database name
245
		name = ptr;
246
		name_len = 0;
247
		while ((*ptr) && (!isspace(*ptr)) && (*ptr != ',') && (*ptr != '.')) {ptr++;name_len++;}
248
		while ((*ptr) && isspace(*ptr)) ptr++;
249
		
250
		if (*ptr != '.') {
251
			if ((name_len == 1) && (*name == '*'))
252
				match_state = MATCH_ALL;
253
			else
254
				goto bad_list; // Missing table
255
		} else {
256
		
257
			if ((match_state > MATCH_DBS) && (name_len == 1) && (*name == '*'))
258
				match_state = MATCH_DBS;
259
				
260
			ptr++; // Skip the '.'
261
			
262
			// Find the start of the table name.
263
			while ((*ptr) && isspace(*ptr)) ptr++;
264
			if ((!*ptr) || (*ptr == ',') || (*ptr == '.'))
265
				goto bad_list; // Missing table
266
				
267
			// Find the end of the table name.
268
			while ((*ptr) && (!isspace(*ptr)) && (*ptr != ',') && (*ptr != '.')) ptr++;
269
		}
270
		
271
		// Locate the end of the element.
272
		while ((*ptr) && isspace(*ptr)) ptr++;
273
				
274
		if ((*ptr) && (*ptr != ','))
275
			goto bad_list; // Bad table name
276
			
277
		if (match_state > MATCH_SOME)
278
			match_state = MATCH_SOME;
279
			
280
		if (*ptr) ptr++;
281
		while ((*ptr) && isspace(*ptr)) ptr++;
282
	}
283
	
284
	return match_state;
285
bad_list:
286
287
	char info[120];
288
	snprintf(info, 120, "pbms_watch_tables format error near character position %d", (int) (ptr - list));
289
	CSL.logLine(NULL, CSLog::Error, info);
290
	CSL.logLine(NULL, CSLog::Error, list);
291
	
292
	return MATCH_ERROR;
293
}
294
295
//-----------------
296
static const char* locate_db(const char *list, const char *db, int len)
297
{
298
	int match_len;
299
	
300
	while (*list) {
301
		while ((*list) && isspace(*list)) list++;
302
		if ((*list == 0) || (*(list+1) == 0) || (*(list+2) == 0)) // We need at least 3 characters
303
			return NULL;
304
		
305
		match_len = 0;
306
		if (*list == '*') 
307
			match_len = 1;
308
		else if (strncmp(list, db, len) == 0) 
309
			match_len = len;
310
		
311
		if (match_len) {
312
			list += match_len;
313
			
314
			// Find the '.'
315
			while ((*list) && isspace(*list)) list++;
316
			if ((*list == 0) || (*(list+1) == 0) ) // We need at least 2 characters
317
				return NULL;
318
						
319
			if (*list == '.') { 
320
				list++;
321
				while ((*list) && isspace(*list)) list++;
322
				if (*list == 0)
323
					 return NULL;
324
					 
325
				return list; // We have gound a table that could belong to this database;
326
			}
327
		}
328
		
329
		NEXT_IN_TABLE_LIST(list);
330
	}
331
	
332
	return NULL;
333
}
334
1976.2.1 by Monty Taylor
Updated PBMS.
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
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
374
//--------------
375
// Parameter update functions are not called for parameters that are set on
376
// the command line. PBMSParameters::startUp() will perform any initialization required.
1976.2.1 by Monty Taylor
Updated PBMS.
377
#ifdef DRIZZLED
378
void PBMSParameters::startUp(drizzled::module::Context &context)
379
#else
380
void PBMSParameters::startup()
381
#endif
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
382
{ 
1976.2.1 by Monty Taylor
Updated PBMS.
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
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
416
	my_table_match = set_match_type(my_table_list);
1976.2.1 by Monty Taylor
Updated PBMS.
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
                N_("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
                N_("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
                N_("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
                N_("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
                N_("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
		N_("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
		N_("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
		N_("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
		N_("A comma delimited list of tables to watch of the format: <database>.<table>, ..."));
452
	context("watch-disable",
453
		N_("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
		N_("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
		N_("Before update row event observer call position"));
462
463
}
464
#endif
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
465
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
466
//-----------------
467
bool PBMSParameters::isBlackListedDB(const char *db)
468
{
469
	if (my_black_list.find(string(db)) == my_black_list.end())
470
		return false;
471
		
472
	return true;
473
}		
474
475
//-----------------
476
void PBMSParameters::blackListedDB(const char *db)
477
{
478
	my_black_list.insert(string(db));
479
}		
480
481
//-----------------
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
482
bool PBMSParameters::try_LocateDB(CSThread *self, const char *db, bool *found)
483
{
484
	volatile bool rtc = true;
485
	try_(a) {
486
		lock_(&my_table_list_lock);	
487
		
488
			
1976.2.1 by Monty Taylor
Updated PBMS.
489
		*found = (locate_db(my_table_list.c_str(), db, strlen(db)) != NULL);
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
490
			
491
		unlock_(&my_table_list_lock);
492
		rtc = false;
493
	}
494
	
495
	catch_(a)
496
	cont_(a);
497
	return rtc;
498
}
499
500
//-----------------
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
501
bool PBMSParameters::isBLOBDatabase(const char *db)
502
{
1976.2.20 by Monty Taylor
Hopefully fix debug build and ICC warnings.
503
	CSThread *self= NULL;
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
504
	int		err;
505
	PBMSResultRec result;
506
	bool found = false;
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
507
	
508
	if (isBlackListedDB(db))
509
		return false;
510
		
511
	if (my_table_match == MATCH_UNKNOWN)
1976.2.1 by Monty Taylor
Updated PBMS.
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
	}
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
522
523
	if (my_table_match == MATCH_NONE)
524
		return false;
525
526
	if (my_table_match <= MATCH_DBS)
527
		return true;
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
528
	
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
529
	if ((err = MSEngine::enterConnectionNoThd(&self, &result)) == 0) {
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
530
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
531
		inner_();
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
532
		if (try_LocateDB(self, db, &found)) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
533
			err = MSEngine::exceptionToResult(&self->myException, &result);
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
534
		}		
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
535
		outer_();
536
	
537
	}
538
	
539
	if (err) {
540
		fprintf(stderr, "PBMSParameters::isBLOBDatabase(\"%s\") error (%d):'%s'\n", 
541
			db, result.mr_code,  result.mr_message);
542
	}
543
	
544
	return found;
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
545
}
546
	
547
//-----------------
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
548
bool PBMSParameters::try_LocateTable(CSThread *self, const char *db, const char *table, bool *found)
549
{
550
	volatile bool rtc = true;
551
	try_(a) {
552
		int db_len, table_len, match_len;
553
		
554
		lock_(&my_table_list_lock);	
555
				
556
		db_len = strlen(db);
557
		table_len = strlen(table);
558
		
1976.2.1 by Monty Taylor
Updated PBMS.
559
		const char *ptr = my_table_list.c_str();
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
560
		while (ptr) {
561
			ptr = locate_db(ptr, db, db_len);
562
			if (ptr) {
563
				match_len = 0;
564
				if (*ptr == '*')
565
					match_len = 1;
566
				else if (strncmp(ptr, table, table_len) == 0)
567
					match_len = table_len;
568
					
569
				if (match_len) {
570
					ptr += match_len;
571
					if ((!*ptr) || (*ptr == ',') || isspace(*ptr)) {
572
						*found = true;
573
						break;
574
					}
575
				}
576
				
577
				NEXT_IN_TABLE_LIST(ptr);
578
			}
579
		}
580
			
581
		unlock_(&my_table_list_lock);
582
		rtc = false;
583
	}
584
	
585
	catch_(a)
586
	cont_(a);
587
	return rtc;
588
}
589
590
//-----------------
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
591
bool PBMSParameters::isBLOBTable(const char *db, const char *table)
592
{
1976.2.20 by Monty Taylor
Hopefully fix debug build and ICC warnings.
593
	CSThread *self= NULL;
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
594
	int		err;
595
	PBMSResultRec result;
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
596
	bool found = false;
597
	
598
	if (isBlackListedDB(db))
599
		return false;
600
		
601
	if (my_table_match == MATCH_UNKNOWN)
1976.2.1 by Monty Taylor
Updated PBMS.
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
	}
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
612
613
	if (my_table_match == MATCH_NONE)
614
		return false;
615
616
	if (my_table_match <= MATCH_ALL)
617
		return true;
618
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
619
	if ((err = MSEngine::enterConnectionNoThd(&self, &result)) == 0) {
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
620
621
		inner_();
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
622
		if (try_LocateTable(self, db, table, &found)) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
623
			err = MSEngine::exceptionToResult(&self->myException, &result);
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
624
		}		
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
625
		outer_();
626
	
627
	}
628
	
629
	if (err) {
630
		fprintf(stderr, "PBMSParameters::isBLOBTable(\"%s\", \"%s\") error (%d):'%s'\n", 
631
			db, table, result.mr_code,  result.mr_message);
632
	}
633
	
634
	return found;
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
635
}
636
637
638
//-----------------
1976.2.1 by Monty Taylor
Updated PBMS.
639
int32_t PBMSParameters::getBeforeUptateEventPosition() { return static_cast<int32_t>(my_before_update_position);}
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
640
641
//-----------------
1976.2.1 by Monty Taylor
Updated PBMS.
642
int32_t PBMSParameters::getBeforeInsertEventPosition() { return static_cast<int32_t>(my_before_insert_position);}
1548.2.11 by Barry.Leslie at PrimeBase
Removed libxml reqirement by using a home grown xml parser.
643
#endif // DRIZZLED
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
644
645
//-----------------
1976.2.1 by Monty Taylor
Updated PBMS.
646
#ifndef DRIZZLED
1644.3.1 by Barry.Leslie at PrimeBase
Merged in changes from PBMS project.
647
static void pbms_temp_blob_timeout_func(THD *thd, struct st_mysql_sys_var *var, void *trg, CONST_SAVE void *save)
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
648
{
649
	CSThread		*self;
650
	PBMSResultRec	result;
651
1644.3.1 by Barry.Leslie at PrimeBase
Merged in changes from PBMS project.
652
	(void)thd;
653
	(void)var;
654
	
655
	*(u_long *)trg= *(u_long *) save;
656
	
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
657
	if (MSEngine::enterConnectionNoThd(&self, &result))
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
658
		return;
659
	try_(a) {
660
		MSDatabase::wakeTempLogThreads();
661
	}
662
	
663
	catch_(a);
664
	cont_(a);
665
}
1976.2.1 by Monty Taylor
Updated PBMS.
666
#endif
667
//-----------------
668
//-----------------
669
670
#ifndef DRIZZLED
671
1909.4.4 by Stewart Smith
fix PBMS port variable to also be a command line option. Also add this to the master.opt for the PBMS test suite so that we'll start PBMS with our port number and won't conflict with 8080
672
static MYSQL_SYSVAR_UINT(port, pbms_port_number,
673
	PLUGIN_VAR_READONLY,
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
674
	"The port for the server stream-based communications.",
675
	NULL, NULL, PBMS_PORT, 0, 64*1024, 1);
676
677
static MYSQL_SYSVAR_STR(repository_threshold, my_repository_threshold,
678
	PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_MEMALLOC,
679
	"The maximum size of a BLOB repository file.",
680
	NULL, NULL, MS_REPO_THRESHOLD_DEF);
681
682
static MYSQL_SYSVAR_STR(temp_log_threshold, my_temp_log_threshold,
683
	PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_MEMALLOC,
684
	"The maximum size of a temorary BLOB log file.",
685
	NULL, NULL, MS_TEMP_LOG_THRESHOLD_DEF);
686
687
static MYSQL_SYSVAR_STR(http_metadata_headers, my_http_metadata_headers,
688
	PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
689
	"A ':' delimited list of metadata header names to be used to initialize the pbms_metadata_header table when a database is created.",
690
	NULL, NULL , MS_HTTP_METADATA_HEADERS_DEF);
691
692
static MYSQL_SYSVAR_ULONG(temp_blob_timeout, my_temp_blob_timeout,
693
	PLUGIN_VAR_OPCMDARG,
694
	"The timeout, in seconds, for temporary BLOBs. Uploaded blob data is removed after this time, unless committed to the database.",
695
	NULL, pbms_temp_blob_timeout_func, MS_DEFAULT_TEMP_LOG_WAIT, 1, ~0L, 1);
696
697
static MYSQL_SYSVAR_ULONG(garbage_threshold, my_garbage_threshold,
698
	PLUGIN_VAR_OPCMDARG,
699
	"The percentage of garbage in a repository file before it is compacted.",
700
	NULL, NULL, MS_DEFAULT_GARBAGE_LEVEL, 0, 100, 1);
701
702
703
static MYSQL_SYSVAR_ULONG(max_keep_alive, my_max_keep_alive,
704
	PLUGIN_VAR_OPCMDARG,
705
	"The timeout, in milli-seconds, before the HTTP server will close an inactive HTTP connection.",
706
	NULL, NULL, MS_DEFAULT_KEEP_ALIVE, 1, UINT32_MAX, 1);
707
1644.3.1 by Barry.Leslie at PrimeBase
Merged in changes from PBMS project.
708
static MYSQL_SYSVAR_ULONG(next_backup_db_id, my_backup_db_id,
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
709
	PLUGIN_VAR_OPCMDARG,
710
	"The next backup ID to use when backing up a PBMS database.",
1644.3.1 by Barry.Leslie at PrimeBase
Merged in changes from PBMS project.
711
	NULL, NULL, 1, 1, UINT32_MAX, 1);
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
712
713
struct st_mysql_sys_var* pbms_system_variables[] = {
714
	MYSQL_SYSVAR(port),
715
	MYSQL_SYSVAR(repository_threshold),
716
	MYSQL_SYSVAR(temp_log_threshold),
717
	MYSQL_SYSVAR(temp_blob_timeout),
718
	MYSQL_SYSVAR(garbage_threshold),
719
	MYSQL_SYSVAR(http_metadata_headers),
720
	MYSQL_SYSVAR(max_keep_alive),
721
	MYSQL_SYSVAR(next_backup_db_id),
722
	NULL
723
};
724
1976.2.1 by Monty Taylor
Updated PBMS.
725
#endif // !DRIZZLED
726
727
728
// vim:noexpandtab:sts=8:sw=8:tabstop=8:smarttab: