~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table/instance/shared.cc

  • Committer: Mark Atwood
  • Date: 2011-08-12 04:08:33 UTC
  • mfrom: (2385.2.17 refactor5)
  • Revision ID: me@mark.atwood.name-20110812040833-u6j85nc6ahuc0dtz
mergeĀ lp:~olafvdspek/drizzle/refactor5

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include <config.h>
22
22
 
23
 
#include <drizzled/table/instance/shared.h>
24
23
#include <drizzled/definition/cache.h>
 
24
#include <drizzled/error.h>
 
25
#include <drizzled/message/schema.h>
25
26
#include <drizzled/plugin/event_observer.h>
26
 
 
27
 
namespace drizzled
28
 
{
29
 
 
30
 
namespace table
31
 
{
32
 
 
33
 
namespace instance
34
 
{
 
27
#include <drizzled/table/instance/shared.h>
 
28
#include <drizzled/plugin/storage_engine.h>
 
29
 
 
30
namespace drizzled {
 
31
namespace table {
 
32
namespace instance {
35
33
 
36
34
Shared::Shared(const identifier::Table::Type type_arg,
37
35
               const identifier::Table &identifier,
41
39
{
42
40
}
43
41
 
 
42
Shared::Shared(const identifier::Table &identifier,
 
43
               message::schema::shared_ptr schema_message) :
 
44
  TableShare(message::Table::STANDARD, identifier, NULL, 0),
 
45
  _schema(schema_message),
 
46
  event_observers(NULL)
 
47
{
 
48
}
 
49
 
44
50
Shared::Shared(const identifier::Table &identifier) :
45
51
  TableShare(identifier, identifier.getKey()),
46
52
  event_observers(NULL)
47
53
{
48
54
}
49
55
 
 
56
bool Shared::is_replicated() const
 
57
{
 
58
  if (_schema)
 
59
  {
 
60
    if (not message::is_replicated(*_schema))
 
61
      return false;
 
62
  }
 
63
 
 
64
  assert(getTableMessage());
 
65
  return message::is_replicated(*getTableMessage());
 
66
}
 
67
 
 
68
 
50
69
Shared::shared_ptr Shared::foundTableShare(Shared::shared_ptr share)
51
70
{
52
71
  /*
83
102
  If it doesn't exist, create a new from the table definition file.
84
103
 
85
104
  NOTES
86
 
  We must have wrlock on table::Cache::singleton().mutex() when we come here
 
105
  We must have wrlock on table::Cache::mutex() when we come here
87
106
  (To be changed later)
88
107
 
89
108
  RETURN
100
119
  in_error= 0;
101
120
 
102
121
  /* Read table definition from cache */
103
 
  if ((share= definition::Cache::singleton().find(identifier.getKey())))
 
122
  if ((share= definition::Cache::find(identifier.getKey())))
104
123
    return foundTableShare(share);
105
 
 
106
 
  share.reset(new Shared(message::Table::STANDARD, identifier));
107
124
  
 
125
  drizzled::message::schema::shared_ptr schema_message_ptr= plugin::StorageEngine::getSchemaDefinition(identifier);
 
126
 
 
127
  if (not schema_message_ptr)
 
128
  {
 
129
    drizzled::my_error(ER_SCHEMA_DOES_NOT_EXIST, identifier);
 
130
    return Shared::shared_ptr();
 
131
  }
 
132
 
 
133
  share.reset(new Shared(identifier, schema_message_ptr));
 
134
 
108
135
  if (share->open_table_def(*session, identifier))
109
136
  {
110
137
    in_error= share->error;
115
142
  
116
143
  plugin::EventObserver::registerTableEvents(*share);
117
144
 
118
 
  bool ret= definition::Cache::singleton().insert(identifier.getKey(), share);
 
145
  bool ret= definition::Cache::insert(identifier.getKey(), share);
119
146
 
120
147
  if (not ret)
 
148
  {
 
149
    drizzled::my_error(ER_UNKNOWN_ERROR);
121
150
    return Shared::shared_ptr();
 
151
  }
122
152
 
123
153
  return share;
124
154
}
149
179
void release(TableShare *share)
150
180
{
151
181
  bool to_be_deleted= false;
152
 
  //safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle);
 
182
  //safe_mutex_assert_owner(table::Cache::mutex().native_handle);
153
183
 
154
184
  share->lock();
155
185
  if (not share->decrementTableCount())
160
190
 
161
191
  if (to_be_deleted)
162
192
  {
163
 
    definition::Cache::singleton().erase(share->getCacheKey());
 
193
    definition::Cache::erase(share->getCacheKey());
164
194
  }
165
195
}
166
196
 
168
198
{
169
199
  bool to_be_deleted= false;
170
200
#if 0
171
 
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle);
 
201
  safe_mutex_assert_owner(table::Cache::mutex().native_handle);
172
202
#endif
173
203
 
174
204
  share->lock();
180
210
 
181
211
  if (to_be_deleted)
182
212
  {
183
 
    definition::Cache::singleton().erase(share->getCacheKey());
 
213
    definition::Cache::erase(share->getCacheKey());
184
214
  }
185
215
}
186
216
 
187
217
void release(const identifier::Table &identifier)
188
218
{
189
 
  TableShare::shared_ptr share= definition::Cache::singleton().find(identifier.getKey());
 
219
  TableShare::shared_ptr share= definition::Cache::find(identifier.getKey());
190
220
  if (share)
191
221
  {
192
222
    share->resetVersion(); 
193
223
    if (share->getTableCount() == 0)
194
224
    {
195
 
      definition::Cache::singleton().erase(identifier.getKey());
 
225
      definition::Cache::erase(identifier.getKey());
196
226
    }
197
227
  }
198
228
}