~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: Brian Aker
  • Date: 2010-01-18 19:39:12 UTC
  • mfrom: (1251.2.9 working)
  • Revision ID: brian@gaz-20100118193912-rf7ncdnrhvowyfo6
Merge Jay

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
#include "config.h"
47
47
#include "drizzled/my_getopt.h"
48
 
#include <plugin/myisam/myisam.h>
49
48
#include <drizzled/error.h>
50
49
#include <drizzled/gettext.h>
51
50
#include <drizzled/tztime.h>
71
70
using namespace drizzled;
72
71
 
73
72
extern plugin::StorageEngine *myisam_engine;
 
73
extern bool timed_mutexes;
74
74
 
75
75
extern struct my_option my_long_options[];
76
76
extern const CHARSET_INFO *character_set_filesystem;
101
101
static void fix_session_mem_root(Session *session, enum_var_type type);
102
102
static void fix_trans_mem_root(Session *session, enum_var_type type);
103
103
static void fix_server_id(Session *session, enum_var_type type);
104
 
static uint64_t fix_unsigned(Session *, uint64_t, const struct my_option *);
105
104
static bool get_unsigned32(Session *session, set_var *var);
106
105
static bool get_unsigned64(Session *session, set_var *var);
107
106
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
141
140
 
142
141
static sys_var_session_uint64_t sys_join_buffer_size(&vars, "join_buffer_size",
143
142
                                                     &SV::join_buff_size);
144
 
static sys_var_key_buffer_size  sys_key_buffer_size(&vars, "key_buffer_size");
145
 
static sys_var_key_cache_uint32_t  sys_key_cache_block_size(&vars, "key_cache_block_size",
146
 
                                                        offsetof(KEY_CACHE,
147
 
                                                                 param_block_size));
148
 
static sys_var_key_cache_uint32_t       sys_key_cache_division_limit(&vars, "key_cache_division_limit",
149
 
                                                           offsetof(KEY_CACHE,
150
 
                                                                    param_division_limit));
151
 
static sys_var_key_cache_uint32_t  sys_key_cache_age_threshold(&vars, "key_cache_age_threshold",
152
 
                                                           offsetof(KEY_CACHE,
153
 
                                                                    param_age_threshold));
154
143
static sys_var_session_uint32_t sys_max_allowed_packet(&vars, "max_allowed_packet",
155
144
                                                       &SV::max_allowed_packet);
156
145
static sys_var_uint64_t_ptr     sys_max_connect_errors(&vars, "max_connect_errors",
455
444
  return false;
456
445
}
457
446
 
458
 
static uint64_t fix_unsigned(Session *session, uint64_t num,
 
447
uint64_t fix_unsigned(Session *session, uint64_t num,
459
448
                              const struct my_option *option_limits)
460
449
{
461
450
  bool fixed= false;
1227
1216
  return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
1228
1217
}
1229
1218
 
1230
 
 
1231
 
unsigned char *sys_var_key_cache_param::value_ptr(Session *, enum_var_type,
1232
 
                                                  const LEX_STRING *)
1233
 
{
1234
 
  return (unsigned char*) dflt_key_cache + offset ;
1235
 
}
1236
 
 
1237
 
/**
1238
 
  Resize key cache.
1239
 
*/
1240
 
static int resize_key_cache_with_lock(KEY_CACHE *key_cache)
1241
 
{
1242
 
  assert(key_cache->key_cache_inited);
1243
 
 
1244
 
  pthread_mutex_lock(&LOCK_global_system_variables);
1245
 
  long tmp_buff_size= (long) key_cache->param_buff_size;
1246
 
  long tmp_block_size= (long) key_cache->param_block_size;
1247
 
  uint32_t division_limit= key_cache->param_division_limit;
1248
 
  uint32_t age_threshold=  key_cache->param_age_threshold;
1249
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
1250
 
 
1251
 
  return(!resize_key_cache(key_cache, tmp_block_size,
1252
 
                           tmp_buff_size,
1253
 
                           division_limit, age_threshold));
1254
 
}
1255
 
 
1256
 
sys_var_key_buffer_size::sys_var_key_buffer_size(sys_var_chain *chain,
1257
 
                                                 const char *name_arg)
1258
 
  : sys_var_key_cache_param(chain, name_arg,
1259
 
                            offsetof(KEY_CACHE, param_buff_size))
1260
 
{}
1261
 
 
1262
 
bool sys_var_key_buffer_size::update(Session *session, set_var *var)
1263
 
{
1264
 
  uint64_t tmp= var->save_result.uint64_t_value;
1265
 
  KEY_CACHE *key_cache;
1266
 
  bool error= 0;
1267
 
 
1268
 
  pthread_mutex_lock(&LOCK_global_system_variables);
1269
 
  key_cache= dflt_key_cache;
1270
 
 
1271
 
  /*
1272
 
    Abort if some other thread is changing the key cache
1273
 
    TODO: This should be changed so that we wait until the previous
1274
 
    assignment is done and then do the new assign
1275
 
  */
1276
 
  if (key_cache->in_init)
1277
 
    goto end;
1278
 
 
1279
 
  if (tmp == 0)                                 // Zero size means delete
1280
 
  {
1281
 
    push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1282
 
                        ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
1283
 
                        ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
1284
 
    goto end;                                   // Ignore default key cache
1285
 
  }
1286
 
 
1287
 
  key_cache->param_buff_size=
1288
 
    (uint64_t) fix_unsigned(session, tmp, option_limits);
1289
 
 
1290
 
  /* If key cache didn't existed initialize it, else resize it */
1291
 
  key_cache->in_init= 1;
1292
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
1293
 
 
1294
 
  error= (bool)(resize_key_cache_with_lock(key_cache));
1295
 
 
1296
 
  pthread_mutex_lock(&LOCK_global_system_variables);
1297
 
  key_cache->in_init= 0;
1298
 
 
1299
 
end:
1300
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
1301
 
  return error;
1302
 
}
1303
 
 
1304
 
 
1305
 
/**
1306
 
  @todo
1307
 
  Abort if some other thread is changing the key cache.
1308
 
  This should be changed so that we wait until the previous
1309
 
  assignment is done and then do the new assign
1310
 
*/
1311
 
bool sys_var_key_cache_uint32_t::update(Session *session, set_var *var)
1312
 
{
1313
 
  uint64_t tmp= (uint64_t) var->value->val_int();
1314
 
  bool error= 0;
1315
 
 
1316
 
  pthread_mutex_lock(&LOCK_global_system_variables);
1317
 
 
1318
 
  /*
1319
 
    Abort if some other thread is changing the key cache
1320
 
    TODO: This should be changed so that we wait until the previous
1321
 
    assignment is done and then do the new assign
1322
 
  */
1323
 
  if (dflt_key_cache->in_init)
1324
 
    goto end;
1325
 
 
1326
 
  *((uint32_t*) (((char*) dflt_key_cache) + offset))=
1327
 
    (uint32_t) fix_unsigned(session, tmp, option_limits);
1328
 
 
1329
 
  /*
1330
 
    Don't create a new key cache if it didn't exist
1331
 
    (key_caches are created only when the user sets block_size)
1332
 
  */
1333
 
  dflt_key_cache->in_init= 1;
1334
 
 
1335
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
1336
 
 
1337
 
  error= (bool) (resize_key_cache_with_lock(dflt_key_cache));
1338
 
 
1339
 
  pthread_mutex_lock(&LOCK_global_system_variables);
1340
 
  dflt_key_cache->in_init= 0;
1341
 
 
1342
 
end:
1343
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
1344
 
  return error;
1345
 
}
1346
 
 
1347
 
 
1348
1219
/****************************************************************************/
1349
1220
 
1350
1221
bool sys_var_timestamp::update(Session *session,  set_var *var)
2209
2080
  else
2210
2081
    session->variables.*offset= global_system_variables.*offset;
2211
2082
}
2212
 
 
2213