~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/schema_engine/schema.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:
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 "plugin/schema_engine/schema.h"
24
 
#include "drizzled/db.h"
25
 
#include "drizzled/sql_table.h"
26
 
#include "drizzled/global_charset_info.h"
27
 
#include "drizzled/charset.h"
28
 
#include "drizzled/charset_info.h"
29
 
#include "drizzled/cursor.h"
30
 
#include "drizzled/data_home.h"
 
23
#include <drizzled/error.h>
 
24
#include <plugin/schema_engine/schema.h>
 
25
#include <drizzled/schema.h>
 
26
#include <drizzled/sql_table.h>
 
27
#include <drizzled/charset.h>
 
28
#include <drizzled/cursor.h>
 
29
#include <drizzled/data_home.h>
31
30
 
32
31
#include <drizzled/pthread_globals.h>
33
32
 
34
33
#include <drizzled/execute.h>
35
34
 
36
 
#include "drizzled/internal/my_sys.h"
 
35
#include <drizzled/internal/my_sys.h>
 
36
#include <drizzled/cached_directory.h>
37
37
 
38
38
#include <fcntl.h>
39
39
#include <sys/stat.h>
40
40
#include <sys/types.h>
41
41
 
 
42
#include <boost/foreach.hpp>
42
43
#include <google/protobuf/io/zero_copy_stream.h>
43
44
#include <google/protobuf/io/zero_copy_stream_impl.h>
44
45
 
49
50
using namespace std;
50
51
using namespace drizzled;
51
52
 
52
 
 
53
 
#define MY_DB_OPT_FILE "db.opt"
54
 
#define DEFAULT_FILE_EXTENSION ".dfe" // Deep Fried Elephant
55
 
 
56
 
Schema::Schema():
 
53
const char* MY_DB_OPT_FILE= "db.opt";
 
54
const char* DEFAULT_FILE_EXTENSION= ".dfe"; // Deep Fried Elephant
 
55
 
 
56
static const char* g_schema_exts[] = 
 
57
{
 
58
  NULL
 
59
};
 
60
 
 
61
Schema::Schema() :
57
62
  drizzled::plugin::StorageEngine("schema",
58
63
                                  HTON_ALTER_NOT_SUPPORTED |
59
64
                                  HTON_HAS_SCHEMA_DICTIONARY |
64
69
  table_definition_ext= DEFAULT_FILE_EXTENSION;
65
70
}
66
71
 
67
 
Schema::~Schema()
68
 
{
69
 
}
70
 
 
71
72
void Schema::prime()
72
73
{
73
74
  CachedDirectory directory(getDataHomeCatalog().file_string(), CachedDirectory::DIRECTORY);
74
75
  CachedDirectory::Entries files= directory.getEntries();
75
76
  boost::unique_lock<boost::shared_mutex> scopedLock(mutex);
76
77
 
77
 
  for (CachedDirectory::Entries::iterator fileIter= files.begin();
78
 
       fileIter != files.end(); fileIter++)
 
78
  BOOST_FOREACH(CachedDirectory::Entries::reference entry, files)
79
79
  {
80
 
    CachedDirectory::Entry *entry= *fileIter;
81
 
    message::Schema schema_message;
82
 
 
83
80
    if (not entry->filename.compare(GLOBAL_TEMPORARY_EXT))
84
81
      continue;
85
 
 
 
82
    message::Schema schema_message;
86
83
    if (readSchemaFile(entry->filename, schema_message))
87
84
    {
88
85
      identifier::Schema schema_identifier(schema_message.name());
90
87
      pair<SchemaCache::iterator, bool> ret=
91
88
        schema_cache.insert(make_pair(schema_identifier.getPath(), new message::Schema(schema_message)));
92
89
 
93
 
      if (ret.second == false)
94
 
      {
95
 
        abort(); // If this has happened, something really bad is going down.
96
 
      }
 
90
      assert(ret.second); // If this has happened, something really bad is going down.
97
91
    }
98
92
  }
99
93
}
100
94
 
101
 
void Schema::startup(drizzled::Session &)
102
 
{
103
 
}
104
 
 
105
 
void Schema::doGetSchemaIdentifiers(identifier::Schema::vector &set_of_names)
 
95
void Schema::doGetSchemaIdentifiers(identifier::schema::vector &set_of_names)
106
96
{
107
97
  mutex.lock_shared();
108
 
  {
109
 
    for (SchemaCache::iterator iter= schema_cache.begin();
110
 
         iter != schema_cache.end();
111
 
         iter++)
112
 
    {
113
 
      set_of_names.push_back(identifier::Schema((*iter).second->name()));
114
 
    }
115
 
  }
 
98
  BOOST_FOREACH(SchemaCache::reference iter, schema_cache)
 
99
    set_of_names.push_back(iter.second->name());
116
100
  mutex.unlock_shared();
117
101
}
118
102
 
119
 
bool Schema::doGetSchemaDefinition(const identifier::Schema &schema_identifier, message::schema::shared_ptr &schema_message)
 
103
drizzled::message::schema::shared_ptr Schema::doGetSchemaDefinition(const identifier::Schema &schema_identifier)
120
104
{
121
105
  mutex.lock_shared();
122
106
  SchemaCache::iterator iter= schema_cache.find(schema_identifier.getPath());
123
 
 
124
107
  if (iter != schema_cache.end())
125
108
  {
126
 
    schema_message= (*iter).second;
 
109
    drizzled::message::schema::shared_ptr schema_message= iter->second;
127
110
    mutex.unlock_shared();
128
 
 
129
 
    return true;
 
111
    return schema_message;
130
112
  }
131
113
  mutex.unlock_shared();
132
 
 
133
 
  return false;
 
114
  return drizzled::message::schema::shared_ptr();
134
115
}
135
116
 
136
117
 
151
132
    return false;
152
133
  }
153
134
 
154
 
  {
155
 
    boost::unique_lock<boost::shared_mutex> scopedLock(mutex);
156
 
    pair<SchemaCache::iterator, bool> ret=
157
 
      schema_cache.insert(make_pair(schema_identifier.getPath(), new message::Schema(schema_message)));
158
 
 
159
 
 
160
 
    if (ret.second == false)
161
 
    {
162
 
      abort(); // If this has happened, something really bad is going down.
163
 
    }
164
 
  }
165
 
 
 
135
  boost::unique_lock<boost::shared_mutex> scopedLock(mutex);
 
136
  pair<SchemaCache::iterator, bool> ret= 
 
137
    schema_cache.insert(make_pair(schema_identifier.getPath(), new message::Schema(schema_message)));
 
138
 
 
139
  assert(ret.second); // If this has happened, something really bad is going down.
166
140
  return true;
167
141
}
168
142
 
169
143
bool Schema::doDropSchema(const identifier::Schema &schema_identifier)
170
144
{
171
 
  message::schema::shared_ptr schema_message;
172
 
 
173
145
  string schema_file(schema_identifier.getPath());
174
146
  schema_file.append(1, FN_LIBCHAR);
175
147
  schema_file.append(MY_DB_OPT_FILE);
176
148
 
177
 
  if (not doGetSchemaDefinition(schema_identifier, schema_message))
 
149
  if (not doGetSchemaDefinition(schema_identifier))
178
150
    return false;
179
151
 
180
152
  // No db.opt file, no love from us.
220
192
    pair<SchemaCache::iterator, bool> ret=
221
193
      schema_cache.insert(make_pair(schema_identifier.getPath(), new message::Schema(schema_message)));
222
194
 
223
 
    if (ret.second == false)
224
 
    {
225
 
      abort(); // If this has happened, something really bad is going down.
226
 
    }
 
195
    assert(ret.second); // If this has happened, something really bad is going down.
227
196
  }
228
197
 
229
198
  return true;
341
310
 
342
311
void Schema::doGetTableIdentifiers(drizzled::CachedDirectory&,
343
312
                                   const drizzled::identifier::Schema&,
344
 
                                   drizzled::identifier::Table::vector&)
345
 
{
 
313
                                   drizzled::identifier::table::vector&)
 
314
{
 
315
}
 
316
 
 
317
const char** Schema::bas_ext() const
 
318
{
 
319
  return g_schema_exts;
346
320
}