~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/archive/ha_archive.cc

Moved the archive_open_tables list into the Archive Storage Engine itself.

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
/* Variables for archive share methods */
105
105
pthread_mutex_t archive_mutex= PTHREAD_MUTEX_INITIALIZER;
106
106
 
107
 
std::map<const char *, ArchiveShare *> archive_open_tables;
108
 
 
109
107
static unsigned int global_version;
110
108
 
111
109
/* The file extension */
136
134
 
137
135
class ArchiveEngine : public drizzled::plugin::StorageEngine
138
136
{
 
137
std::map<std::string, ArchiveShare *> archive_open_tables;
139
138
public:
140
139
  ArchiveEngine(const string &name_arg)
141
140
   : drizzled::plugin::StorageEngine(name_arg,
142
141
                                     HTON_FILE_BASED
143
 
                                      | HTON_HAS_DATA_DICTIONARY) 
 
142
                                      | HTON_HAS_DATA_DICTIONARY),
 
143
     archive_open_tables()
144
144
  {
145
145
    table_definition_ext= ARZ;
146
146
  }
176
176
  void doGetTableNames(CachedDirectory &directory, string& , set<string>& set_of_names);
177
177
 
178
178
  int doDropTable(Session&, const string table_path);
 
179
  ArchiveShare *findOpenTable(const string table_name);
 
180
  void addOpenTable(const string &table_name, ArchiveShare *);
 
181
  void deleteOpenTable(const string &table_name);
179
182
};
180
183
 
 
184
ArchiveShare *ArchiveEngine::findOpenTable(const string table_name)
 
185
{
 
186
  map<string, ArchiveShare *>::iterator find_iter=
 
187
    archive_open_tables.find(table_name);
 
188
 
 
189
  if (find_iter != archive_open_tables.end())
 
190
    return (*find_iter).second;
 
191
  else
 
192
    return NULL;
 
193
}
 
194
 
 
195
void ArchiveEngine::addOpenTable(const string &table_name, ArchiveShare *share)
 
196
{
 
197
  archive_open_tables[table_name]= share;
 
198
}
 
199
 
 
200
void ArchiveEngine::deleteOpenTable(const string &table_name)
 
201
{
 
202
  archive_open_tables.erase(table_name);
 
203
}
181
204
 
182
205
void ArchiveEngine::doGetTableNames(CachedDirectory &directory, 
183
206
                                    string&, 
294
317
{
295
318
 
296
319
  pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST);
297
 
  archive_engine= new ArchiveEngine(engine_name);
 
320
  archive_engine= new ArchiveEngine("ARCHIVE");
298
321
  registry.add(archive_engine);
299
322
 
300
323
  /* When the engine starts up set the first version */
424
447
*/
425
448
ArchiveShare *ha_archive::get_share(const char *table_name, int *rc)
426
449
{
427
 
  uint32_t length;
428
 
  map<const char *, ArchiveShare *> ::iterator find_iter;
429
 
 
430
450
  pthread_mutex_lock(&archive_mutex);
431
 
  length=(uint) strlen(table_name);
432
 
 
433
 
  find_iter= archive_open_tables.find(table_name);
434
 
 
435
 
  if (find_iter != archive_open_tables.end())
436
 
    share= (*find_iter).second;
437
 
  else
438
 
    share= NULL;
 
451
 
 
452
  ArchiveEngine *a_engine= static_cast<ArchiveEngine *>(engine);
 
453
  share= a_engine->findOpenTable(table_name);
439
454
 
440
455
  if (!share)
441
456
  {
457
472
      return NULL;
458
473
    }
459
474
 
460
 
    archive_open_tables[share->table_name.c_str()]= share; 
 
475
    a_engine->addOpenTable(share->table_name, share);
461
476
    thr_lock_init(&share->lock);
462
477
  }
463
478
  share->use_count++;
478
493
  pthread_mutex_lock(&archive_mutex);
479
494
  if (!--share->use_count)
480
495
  {
481
 
    archive_open_tables.erase(share->table_name.c_str());
 
496
    ArchiveEngine *a_engine= static_cast<ArchiveEngine *>(engine);
 
497
    a_engine->deleteOpenTable(share->table_name);
482
498
    delete share;
483
499
  }
484
500
  pthread_mutex_unlock(&archive_mutex);