~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/memory/ha_heap.cc

  • Committer: Brian Aker
  • Date: 2010-10-22 23:33:58 UTC
  • mfrom: (1869.1.7 refactor)
  • Revision ID: brian@tangent.org-20101022233358-kmtrpm1yvmmyaame
Merge in overhaul to how cursor and table are handled. Cursor now only knows
about table, and will always have a table and engine reference.

This cleans up a number of ownership issues, the biggest being that it now
creates the space needed for the next big refactor in locks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
    hp_panic(HA_PANIC_CLOSE);
61
61
  }
62
62
 
63
 
  virtual Cursor *create(TableShare &table)
 
63
  virtual Cursor *create(Table &table)
64
64
  {
65
65
    return new ha_heap(*this, table);
66
66
  }
158
158
*****************************************************************************/
159
159
 
160
160
ha_heap::ha_heap(plugin::StorageEngine &engine_arg,
161
 
                 TableShare &table_arg)
 
161
                 Table &table_arg)
162
162
  :Cursor(engine_arg, table_arg), file(0), records_changed(0), key_stat_version(0),
163
163
  internal_table(0)
164
164
{}
185
185
    HP_SHARE *internal_share= NULL;
186
186
    message::Table create_proto;
187
187
 
188
 
    if (not heap_storage_engine->heap_create_table(table->in_use,
 
188
    if (not heap_storage_engine->heap_create_table(getTable()->in_use,
189
189
                                                   identifier.getPath().c_str(),
190
 
                                                   table,
 
190
                                                   getTable(),
191
191
                                                   internal_table,
192
192
                                                   create_proto,
193
193
                                                   &internal_share))
240
240
 
241
241
Cursor *ha_heap::clone(memory::Root *)
242
242
{
243
 
  Cursor *new_handler= table->getMutableShare()->db_type()->getCursor(*(table->getMutableShare()));
244
 
  TableIdentifier identifier(table->getShare()->getSchemaName(),
245
 
                             table->getShare()->getTableName(),
246
 
                             table->getShare()->getPath());
 
243
  Cursor *new_handler= getTable()->getMutableShare()->db_type()->getCursor(*getTable());
 
244
  TableIdentifier identifier(getTable()->getShare()->getSchemaName(),
 
245
                             getTable()->getShare()->getTableName(),
 
246
                             getTable()->getShare()->getPath());
247
247
 
248
 
  if (new_handler && !new_handler->ha_open(identifier, table, table->db_stat,
 
248
  if (new_handler && !new_handler->ha_open(identifier, getTable()->db_stat,
249
249
                                           HA_OPEN_IGNORE_IF_LOCKED))
250
250
    return new_handler;
251
251
  return NULL;
281
281
 
282
282
void ha_heap::update_key_stats()
283
283
{
284
 
  for (uint32_t i= 0; i < table->getShare()->sizeKeys(); i++)
 
284
  for (uint32_t i= 0; i < getTable()->getShare()->sizeKeys(); i++)
285
285
  {
286
 
    KeyInfo *key= &table->key_info[i];
 
286
    KeyInfo *key= &getTable()->key_info[i];
287
287
 
288
288
    if (!key->rec_per_key)
289
289
      continue;
310
310
int ha_heap::doInsertRecord(unsigned char * buf)
311
311
{
312
312
  int res;
313
 
  if (table->next_number_field && buf == table->getInsertRecord())
 
313
  if (getTable()->next_number_field && buf == getTable()->getInsertRecord())
314
314
  {
315
315
    if ((res= update_auto_increment()))
316
316
      return res;
350
350
  int res;
351
351
 
352
352
  res= heap_delete(file,buf);
353
 
  if (!res && table->getShare()->getType() == message::Table::STANDARD &&
 
353
  if (!res && getTable()->getShare()->getType() == message::Table::STANDARD &&
354
354
      ++records_changed*MEMORY_STATS_UPDATE_THRESHOLD > file->getShare()->records)
355
355
  {
356
356
    /*
369
369
  assert(inited==INDEX);
370
370
  ha_statistic_increment(&system_status_var::ha_read_key_count);
371
371
  int error = heap_rkey(file,buf,active_index, key, keypart_map, find_flag);
372
 
  table->status = error ? STATUS_NOT_FOUND : 0;
 
372
  getTable()->status = error ? STATUS_NOT_FOUND : 0;
373
373
  return error;
374
374
}
375
375
 
380
380
  ha_statistic_increment(&system_status_var::ha_read_key_count);
381
381
  int error= heap_rkey(file, buf, active_index, key, keypart_map,
382
382
                       HA_READ_PREFIX_LAST);
383
 
  table->status= error ? STATUS_NOT_FOUND : 0;
 
383
  getTable()->status= error ? STATUS_NOT_FOUND : 0;
384
384
  return error;
385
385
}
386
386
 
390
390
{
391
391
  ha_statistic_increment(&system_status_var::ha_read_key_count);
392
392
  int error = heap_rkey(file, buf, index, key, keypart_map, find_flag);
393
 
  table->status = error ? STATUS_NOT_FOUND : 0;
 
393
  getTable()->status = error ? STATUS_NOT_FOUND : 0;
394
394
  return error;
395
395
}
396
396
 
399
399
  assert(inited==INDEX);
400
400
  ha_statistic_increment(&system_status_var::ha_read_next_count);
401
401
  int error=heap_rnext(file,buf);
402
 
  table->status=error ? STATUS_NOT_FOUND: 0;
 
402
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
403
403
  return error;
404
404
}
405
405
 
408
408
  assert(inited==INDEX);
409
409
  ha_statistic_increment(&system_status_var::ha_read_prev_count);
410
410
  int error=heap_rprev(file,buf);
411
 
  table->status=error ? STATUS_NOT_FOUND: 0;
 
411
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
412
412
  return error;
413
413
}
414
414
 
417
417
  assert(inited==INDEX);
418
418
  ha_statistic_increment(&system_status_var::ha_read_first_count);
419
419
  int error=heap_rfirst(file, buf, active_index);
420
 
  table->status=error ? STATUS_NOT_FOUND: 0;
 
420
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
421
421
  return error;
422
422
}
423
423
 
426
426
  assert(inited==INDEX);
427
427
  ha_statistic_increment(&system_status_var::ha_read_last_count);
428
428
  int error=heap_rlast(file, buf, active_index);
429
 
  table->status=error ? STATUS_NOT_FOUND: 0;
 
429
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
430
430
  return error;
431
431
}
432
432
 
439
439
{
440
440
  ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
441
441
  int error=heap_scan(file, buf);
442
 
  table->status=error ? STATUS_NOT_FOUND: 0;
 
442
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
443
443
  return error;
444
444
}
445
445
 
450
450
  ha_statistic_increment(&system_status_var::ha_read_rnd_count);
451
451
  memcpy(&heap_position, pos, sizeof(HEAP_PTR));
452
452
  error=heap_rrnd(file, buf, heap_position);
453
 
  table->status=error ? STATUS_NOT_FOUND: 0;
 
453
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
454
454
  return error;
455
455
}
456
456
 
499
499
int ha_heap::delete_all_rows()
500
500
{
501
501
  heap_clear(file);
502
 
  if (table->getShare()->getType() == message::Table::STANDARD)
 
502
  if (getTable()->getShare()->getType() == message::Table::STANDARD)
503
503
  {
504
504
    /*
505
505
       We can perform this safely since only one writer at the time is
634
634
ha_rows ha_heap::records_in_range(uint32_t inx, key_range *min_key,
635
635
                                  key_range *max_key)
636
636
{
637
 
  KeyInfo *key= &table->key_info[inx];
 
637
  KeyInfo *key= &getTable()->key_info[inx];
638
638
 
639
639
  if (!min_key || !max_key ||
640
640
      min_key->length != max_key->length ||