~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

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