~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/definition/table.h

Merge Revision revid:marko.makela@oracle.com-20100601140355-u3kxl0yl0ljl5tx9 from MySQL InnoDB

Original revid:marko.makela@oracle.com-20100601140355-u3kxl0yl0ljl5tx9

Original Authors: Marko Mäkelä <marko.makela@oracle.com>
Original commit message:
Merge a change from mysql-5.1-innodb:

  ------------------------------------------------------------
  revno: 3491
  revision-id: marko.makela@oracle.com-20100601134335-ccthwwru23kn09qw
  parent: marko.makela@oracle.com-20100601120751-1uq7bbta5n7ts0qr
  committer: Marko Mäkelä <marko.makela@oracle.com>
  branch nick: 5.1-innodb
  timestamp: Tue 2010-06-01 16:43:35 +0300
  message:
    Bug#48197: Concurrent rw_lock_free may cause assertion failure

    rw_lock_t: Remove magic_n unless UNIV_DEBUG is defined.
    rw_lock_free(): Invalidate magic_n only after removing from rw_lock_list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2009 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
23
23
  instance of table share per one table in the database.
24
24
*/
25
25
 
26
 
#ifndef DRIZZLED_TABLE_INSTANCE_BASE_H
27
 
#define DRIZZLED_TABLE_INSTANCE_BASE_H
 
26
#ifndef DRIZZLED_DEFINITION_TABLE_H
 
27
#define DRIZZLED_DEFINITION_TABLE_H
28
28
 
29
29
#include <string>
30
30
 
32
32
#include <boost/thread/condition_variable.hpp>
33
33
#include <boost/dynamic_bitset.hpp>
34
34
#include <boost/shared_ptr.hpp>
35
 
#include <boost/scoped_ptr.hpp>
36
 
 
37
 
#include <drizzled/memory/root.h>
38
 
#include <drizzled/message.h>
39
 
#include <drizzled/util/string.h>
40
 
 
41
 
#include <drizzled/lex_string.h>
42
 
#include <drizzled/key_map.h>
43
 
 
44
 
#include <drizzled/table/cache.h>
45
 
 
46
 
#include <drizzled/field.h>
47
 
 
 
35
 
 
36
#include "drizzled/typelib.h"
 
37
#include "drizzled/memory/root.h"
 
38
#include "drizzled/message/table.pb.h"
 
39
#include "drizzled/util/string.h"
 
40
 
 
41
#include "drizzled/table/cache.h"
 
42
#include "drizzled/definition/cache.h"
48
43
 
49
44
namespace drizzled
50
45
{
51
46
 
 
47
extern uint64_t refresh_version;
 
48
 
 
49
typedef boost::shared_ptr<TableShare> TableSharePtr;
 
50
 
 
51
const static std::string STANDARD_STRING("STANDARD");
 
52
const static std::string TEMPORARY_STRING("TEMPORARY");
 
53
const static std::string INTERNAL_STRING("INTERNAL");
 
54
const static std::string FUNCTION_STRING("FUNCTION");
52
55
const static std::string NO_PROTOBUFFER_AVAILABLE("NO PROTOBUFFER AVAILABLE");
53
56
 
54
57
namespace plugin
55
58
{
56
59
class EventObserverList;
57
 
class StorageEngine;
58
 
}
59
 
 
60
 
namespace table {
61
 
class Singular;
62
60
}
63
61
 
64
62
class Field_blob;
66
64
class TableShare
67
65
{
68
66
  typedef std::vector<std::string> StringVector;
69
 
 
70
67
public:
71
 
  typedef boost::shared_ptr<TableShare> shared_ptr;
72
 
  typedef std::vector <shared_ptr> vector;
73
 
 
74
 
  TableShare(const identifier::Table::Type type_arg);
75
 
 
76
 
  TableShare(const identifier::Table &identifier, const identifier::Table::Key &key); // Used by placeholder
77
 
 
78
 
  TableShare(const identifier::Table &identifier); // Just used during createTable()
79
 
 
80
 
  TableShare(const identifier::Table::Type type_arg,
81
 
             const identifier::Table &identifier,
 
68
  TableShare(TableIdentifier::Type type_arg);
 
69
 
 
70
  TableShare(TableIdentifier &identifier, const TableIdentifier::Key &key); // Used by placeholder
 
71
 
 
72
  TableShare(const TableIdentifier &identifier); // Just used during createTable()
 
73
 
 
74
  TableShare(TableIdentifier::Type type_arg,
 
75
             TableIdentifier &identifier,
82
76
             char *path_arg= NULL, uint32_t path_length_arg= 0); // Shares for cache
83
77
 
84
 
  virtual ~TableShare();
 
78
  ~TableShare();
85
79
 
86
80
private:
87
81
  /** Category of this table. */
88
82
  enum_table_category table_category;
89
83
 
90
84
public:
 
85
 
91
86
  bool isTemporaryCategory() const
92
87
  {
93
88
    return (table_category == TABLE_CATEGORY_TEMPORARY);
100
95
 
101
96
  /* The following is copied to each Table on OPEN */
102
97
  typedef std::vector<Field *> Fields;
103
 
 
104
98
private:
105
 
  Fields _fields;
106
 
 
 
99
  Fields field;
107
100
public:
108
101
  const Fields getFields() const
109
102
  {
110
 
    return _fields;
111
 
  }
112
 
 
113
 
  Fields getFields()
114
 
  {
115
 
    return _fields;
 
103
    return field;
116
104
  }
117
105
 
118
106
  Field ** getFields(bool)
119
107
  {
120
 
    return &_fields[0];
 
108
    return &field[0];
121
109
  }
122
110
 
123
111
  void setFields(uint32_t arg)
124
112
  {
125
 
    _fields.resize(arg);
 
113
    field.resize(arg);
126
114
  }
127
115
 
128
116
  uint32_t positionFields(Field **arg) const
129
117
  {
130
 
    return (arg - (Field **)&_fields[0]);
 
118
    return (arg - (Field **)&field[0]);
131
119
  }
132
120
 
133
121
  void pushField(Field *arg)
134
122
  {
135
 
    _field_size++;
136
 
    _fields.push_back(arg);
 
123
    fields++;
 
124
    field.push_back(arg);
137
125
  }
138
126
 
 
127
 
139
128
  Field **found_next_number_field;
140
 
 
141
129
private:
142
130
  Field *timestamp_field;               /* Used only during open */
143
 
 
144
131
public:
145
132
 
146
133
  Field *getTimestampField() const               /* Used only during open */
156
143
 
157
144
private:
158
145
  KeyInfo  *key_info;                   /* data of keys in database */
159
 
 
160
146
public:
161
147
  KeyInfo &getKeyInfo(uint32_t arg) const
162
148
  {
164
150
  }
165
151
  std::vector<uint>     blob_field;                     /* Index to blobs in Field arrray*/
166
152
 
167
 
private:
168
153
  /* hash of field names (contains pointers to elements of field array) */
 
154
private:
169
155
  typedef boost::unordered_map < std::string, Field **, util::insensitive_hash, util::insensitive_equal_to> FieldMap;
170
156
  typedef std::pair< std::string, Field ** > FieldMapPair;
171
157
  FieldMap name_hash; /* hash of field names */
172
 
 
173
158
public:
174
159
  size_t getNamedFieldSize() const
175
160
  {
212
197
                   arg.begin(), ::toupper);
213
198
    _keynames.push_back(arg);
214
199
  }
215
 
 
216
200
public:
217
201
  bool doesKeyNameExist(const char *name_arg, uint32_t name_length, uint32_t &position) const
218
202
  {
240
224
private:
241
225
  std::vector<TYPELIB> intervals;                       /* pointer to interval info */
242
226
 
243
 
public:
244
 
  virtual void lock()
245
 
  { }
246
 
 
247
 
  virtual void unlock()
248
 
  { }
249
 
 
250
 
private:
 
227
  boost::mutex mutex;                /* For locking the share  */
 
228
  boost::condition_variable cond;                       /* To signal that share is ready */
 
229
 
 
230
 
 
231
  void lock()
 
232
  {
 
233
    mutex.lock();
 
234
  }
 
235
 
 
236
  void unlock()
 
237
  {
 
238
    mutex.unlock();
 
239
  }
 
240
 
251
241
  std::vector<unsigned char> default_values;            /* row with default values */
252
 
 
253
242
public:
254
243
  // @note This needs to be made to be const in the future
255
244
  unsigned char *getDefaultValues()
261
250
    default_values.resize(arg);
262
251
  }
263
252
 
264
 
  const charset_info_st *table_charset; /* Default charset of string fields */
 
253
  const CHARSET_INFO *table_charset; /* Default charset of string fields */
265
254
 
266
255
  boost::dynamic_bitset<> all_set;
267
256
 
276
265
    To ensure this one can use set_table_cache() methods.
277
266
  */
278
267
private:
279
 
  identifier::Table::Key private_key_for_cache; // This will not exist in the final design.
 
268
  TableIdentifier::Key private_key_for_cache; // This will not exist in the final design.
280
269
  std::vector<char> private_normalized_path; // This will not exist in the final design.
281
270
  LEX_STRING db;                        /* Pointer to db */
282
271
  LEX_STRING table_name;                /* Table name (for open) */
283
272
  LEX_STRING path;      /* Path to table (from datadir) */
284
273
  LEX_STRING normalized_path;           /* unpack_filename(path) */
285
 
 
286
274
public:
287
275
 
288
276
  const char *getNormalizedPath() const
295
283
    return path.str;
296
284
  }
297
285
 
298
 
  const identifier::Table::Key& getCacheKey() const // This should never be called when we aren't looking at a cache.
 
286
  const TableIdentifier::Key& getCacheKey() const // This should never be called when we aren't looking at a cache.
299
287
  {
300
288
    assert(private_key_for_cache.size());
301
289
    return private_key_for_cache;
318
306
    normalized_path.str= str_arg;
319
307
    normalized_path.length= size_arg;
320
308
  }
321
 
 
322
309
public:
323
310
 
324
311
  const char *getTableName() const
356
343
 
357
344
private:
358
345
  uint64_t   version;
359
 
 
360
346
public:
361
347
  uint64_t getVersion() const
362
348
  {
363
349
    return version;
364
350
  }
365
351
 
366
 
  void refreshVersion();
 
352
  void refreshVersion()
 
353
  {
 
354
   version= refresh_version;
 
355
  }
367
356
 
368
357
  void resetVersion()
369
358
  {
370
359
    version= 0;
371
360
  }
372
361
 
373
 
private:
374
362
  uint32_t   timestamp_offset;          /* Set to offset+1 of record */
375
 
 
376
 
  uint32_t reclength;                   /* Recordlength */
377
 
  uint32_t stored_rec_length;         /* Stored record length*/
378
 
 
 
363
private:
 
364
  uint32_t   reclength;                 /* Recordlength */
379
365
public:
380
 
  uint32_t sizeStoredRecord() const
381
 
  {
382
 
    return stored_rec_length;
383
 
  }
 
366
  uint32_t   stored_rec_length;         /* Stored record length*/
384
367
 
385
368
  uint32_t getRecordLength() const
386
369
  {
395
378
  const Field_blob *getBlobFieldAt(uint32_t arg) const
396
379
  {
397
380
    if (arg < blob_fields)
398
 
      return (Field_blob*) _fields[blob_field[arg]];
 
381
      return (Field_blob*) field[blob_field[arg]];
399
382
 
400
383
    return NULL;
401
384
  }
404
387
  /* Max rows is a hint to HEAP during a create tmp table */
405
388
  uint64_t max_rows;
406
389
 
407
 
  boost::scoped_ptr<message::Table> _table_message;
408
 
 
 
390
  message::Table *table_proto;
409
391
public:
 
392
 
410
393
  /*
411
 
    @note Without a _table_message, we assume we are building a STANDARD table.
 
394
    @note Without a table_proto, we assume we are building a STANDARD table.
412
395
    This will be modified once we use Identifiers in the Share itself.
413
396
  */
414
397
  message::Table::TableType getTableType() const
415
398
  {
416
 
    return getTableMessage() ? getTableMessage()->type() : message::Table::STANDARD;
 
399
    return table_proto ? table_proto->type() : message::Table::STANDARD;
417
400
  }
418
401
 
419
402
  const std::string &getTableTypeAsString() const
420
403
  {
421
 
    if (getTableMessage())
422
 
      return message::type(getTableMessage()->type());
423
 
 
424
 
    return NO_PROTOBUFFER_AVAILABLE;
 
404
    if (table_proto)
 
405
    {
 
406
      switch (table_proto->type())
 
407
      {
 
408
      default:
 
409
      case message::Table::STANDARD:
 
410
        return STANDARD_STRING;
 
411
      case message::Table::TEMPORARY:
 
412
        return TEMPORARY_STRING;
 
413
      case message::Table::INTERNAL:
 
414
        return INTERNAL_STRING;
 
415
      case message::Table::FUNCTION:
 
416
        return FUNCTION_STRING;
 
417
      }
 
418
    }
 
419
    else
 
420
    {
 
421
      return NO_PROTOBUFFER_AVAILABLE;
 
422
    }
425
423
  }
426
424
 
427
425
  /* This is only used in one location currently */
428
 
  inline message::Table *getTableMessage() const
429
 
  {
430
 
    return _table_message.get();
431
 
  }
432
 
 
433
 
  void setTableMessage(const message::Table &arg)
434
 
  {
435
 
    assert(not getTableMessage());
436
 
    _table_message.reset(new(std::nothrow) message::Table(arg));
437
 
  }
438
 
 
439
 
  const message::Table::Field &field(int32_t field_position) const
440
 
  {
441
 
    assert(getTableMessage());
442
 
    return getTableMessage()->field(field_position);
 
426
  inline message::Table *getTableProto() const
 
427
  {
 
428
    return table_proto;
 
429
  }
 
430
 
 
431
  inline void setTableProto(message::Table *arg)
 
432
  {
 
433
    assert(table_proto == NULL);
 
434
    table_proto= arg;
443
435
  }
444
436
 
445
437
  inline bool hasComment() const
446
438
  {
447
 
    return (getTableMessage()) ?  getTableMessage()->options().has_comment() : false; 
 
439
    return (table_proto) ?  table_proto->options().has_comment() : false; 
448
440
  }
449
441
 
450
442
  inline const char *getComment()
451
443
  {
452
 
    return (getTableMessage() && getTableMessage()->has_options()) ?  getTableMessage()->options().comment().c_str() : NULL; 
 
444
    return (table_proto && table_proto->has_options()) ?  table_proto->options().comment().c_str() : NULL; 
453
445
  }
454
446
 
455
447
  inline uint32_t getCommentLength() const
456
448
  {
457
 
    return (getTableMessage()) ? getTableMessage()->options().comment().length() : 0; 
 
449
    return (table_proto) ? table_proto->options().comment().length() : 0; 
458
450
  }
459
451
 
460
452
  inline uint64_t getMaxRows() const
484
476
  }
485
477
 
486
478
private:
487
 
  identifier::Table::Type tmp_table;
 
479
  TableIdentifier::Type tmp_table;
488
480
public:
489
481
 
490
 
  identifier::Table::Type getType() const
 
482
  TableIdentifier::Type getType() const
491
483
  {
492
484
    return tmp_table;
493
485
  }
494
486
 
495
487
private:
496
 
  uint32_t _ref_count;       /* How many Table objects uses this */
 
488
  uint32_t ref_count;       /* How many Table objects uses this */
497
489
 
498
490
public:
499
491
  uint32_t getTableCount() const
500
492
  {
501
 
    return _ref_count;
 
493
    return ref_count;
502
494
  }
503
495
 
504
496
  void incrementTableCount()
505
497
  {
506
498
    lock();
507
 
    _ref_count++;
 
499
    ref_count++;
508
500
    unlock();
509
501
  }
510
502
 
511
503
  uint32_t decrementTableCount()
512
504
  {
513
 
    return --_ref_count;
 
505
    return --ref_count;
514
506
  }
515
507
 
516
508
  uint32_t null_bytes;
517
509
  uint32_t last_null_bit_pos;
518
 
private:
519
 
  uint32_t _field_size;                         /* Number of fields */
520
 
 
521
 
public:
522
 
  void setFieldSize(uint32_t arg)
523
 
  {
524
 
    _field_size= arg;
525
 
  }
 
510
  uint32_t fields;                              /* Number of fields */
526
511
 
527
512
  uint32_t sizeFields() const
528
513
  {
529
 
    return _field_size;
 
514
    return fields;
530
515
  }
531
516
 
532
517
  uint32_t rec_buff_length;                 /* Size of table->record[] buffer */
541
526
  uint32_t uniques;                         /* Number of UNIQUE index */
542
527
  uint32_t null_fields;                 /* number of null fields */
543
528
  uint32_t blob_fields;                 /* number of blob fields */
 
529
  uint32_t timestamp_field_offset;              /* Field number for timestamp field */
544
530
private:
545
531
  bool has_variable_width;                  /* number of varchar fields */
546
 
 
547
532
public:
548
533
  bool hasVariableWidth() const
549
534
  {
586
571
  uint32_t next_number_keypart;             /* autoinc keypart number in a key */
587
572
  uint32_t error, open_errno, errarg;       /* error from open_table_def() */
588
573
 
589
 
private:
590
574
  uint8_t blob_ptr_size;                        /* 4 or 8 */
591
 
 
592
 
public:
593
 
  uint8_t sizeBlobPtr() const
594
 
  {
595
 
    return blob_ptr_size;
596
 
  }
597
 
 
598
575
  bool db_low_byte_first;               /* Portable row format */
599
576
 
600
577
  /*
608
585
    event_observers is a class containing all the event plugins that have 
609
586
    registered an interest in this table.
610
587
  */
611
 
  virtual plugin::EventObserverList *getTableObservers() 
 
588
  private:
 
589
  plugin::EventObserverList *event_observers;
 
590
  public:
 
591
  plugin::EventObserverList *getTableObservers() 
612
592
  { 
613
 
    return NULL;
 
593
    return event_observers;
614
594
  }
615
595
  
616
 
  virtual void setTableObservers(plugin::EventObserverList *) 
617
 
  { }
 
596
  void setTableObservers(plugin::EventObserverList *observers) 
 
597
  { 
 
598
    event_observers= observers;
 
599
  }
618
600
  
619
601
  /*
620
602
    Set share's identifier information.
625
607
    NOTES
626
608
  */
627
609
 
628
 
  void setIdentifier(const identifier::Table &identifier_arg);
 
610
  void setIdentifier(TableIdentifier &identifier_arg);
629
611
 
630
612
  /*
631
613
    Initialize share for temporary tables
646
628
private:
647
629
  void init(const char *new_table_name,
648
630
            const char *new_path);
 
631
public:
649
632
 
650
 
protected:
651
633
  void open_table_error(int pass_error, int db_errno, int pass_errarg);
652
634
 
653
 
public:
654
 
 
655
 
  static TableShare::shared_ptr getShareCreate(Session *session, 
656
 
                                               const identifier::Table &identifier,
657
 
                                               int &error);
 
635
  static void release(TableShare *share);
 
636
  static void release(TableSharePtr &share);
 
637
  static void release(TableIdentifier &identifier);
 
638
  static TableSharePtr getShare(TableIdentifier &identifier);
 
639
  static TableSharePtr getShareCreate(Session *session, 
 
640
                                      TableIdentifier &identifier,
 
641
                                      int &error);
658
642
 
659
643
  friend std::ostream& operator<<(std::ostream& output, const TableShare &share)
660
644
  {
671
655
    return output;  // for multiple << operators.
672
656
  }
673
657
 
674
 
protected:
675
 
  friend class drizzled::table::Singular;
676
 
 
677
 
  Field *make_field(const message::Table::Field &pfield,
678
 
                    unsigned char *ptr,
 
658
  Field *make_field(unsigned char *ptr,
679
659
                    uint32_t field_length,
680
660
                    bool is_nullable,
681
661
                    unsigned char *null_pos,
682
662
                    unsigned char null_bit,
683
663
                    uint8_t decimals,
684
664
                    enum_field_types field_type,
685
 
                    const charset_info_st * field_charset,
 
665
                    const CHARSET_INFO * field_charset,
686
666
                    Field::utype unireg_check,
687
667
                    TYPELIB *interval,
688
668
                    const char *field_name);
689
669
 
690
 
  Field *make_field(const message::Table::Field &pfield,
691
 
                    unsigned char *ptr,
692
 
                    uint32_t field_length,
693
 
                    bool is_nullable,
694
 
                    unsigned char *null_pos,
695
 
                    unsigned char null_bit,
696
 
                    uint8_t decimals,
697
 
                    enum_field_types field_type,
698
 
                    const charset_info_st * field_charset,
699
 
                    Field::utype unireg_check,
700
 
                    TYPELIB *interval,
701
 
                    const char *field_name, 
702
 
                    bool is_unsigned);
703
 
 
704
 
public:
705
 
  int open_table_def(Session& session, const identifier::Table &identifier);
 
670
  int open_table_def(Session& session, TableIdentifier &identifier);
706
671
 
707
672
  int open_table_from_share(Session *session,
708
 
                            const identifier::Table &identifier,
 
673
                            const TableIdentifier &identifier,
709
674
                            const char *alias,
710
675
                            uint32_t db_stat, uint32_t ha_open_flags,
711
676
                            Table &outparam);
714
679
                                  const char *alias,
715
680
                                  uint32_t db_stat,
716
681
                                  Table &outparam);
717
 
  int open_table_cursor_inner(const identifier::Table &identifier,
 
682
  int open_table_cursor_inner(const TableIdentifier &identifier,
718
683
                              uint32_t db_stat, uint32_t ha_open_flags,
719
684
                              Table &outparam,
720
685
                              bool &error_reported);
721
686
public:
722
 
  bool parse_table_proto(Session& session, message::Table &table);
723
 
 
724
 
  virtual bool replicate() const
725
 
  {
726
 
    return false;
727
 
  }
 
687
  int parse_table_proto(Session& session, message::Table &table);
 
688
private:
 
689
  int inner_parse_table_proto(Session& session, message::Table &table);
728
690
};
729
691
 
730
692
} /* namespace drizzled */
731
693
 
732
 
#endif /* DRIZZLED_TABLE_INSTANCE_BASE_H */
 
694
#endif /* DRIZZLED_DEFINITION_TABLE_H */