60
60
schema_cache_filled(false)
62
62
table_definition_ext= DEFAULT_FILE_EXTENSION;
63
pthread_rwlock_init(&schema_lock, NULL);
69
pthread_rwlock_destroy(&schema_lock);
72
70
void Schema::prime()
74
72
CachedDirectory directory(data_home, CachedDirectory::DIRECTORY);
75
73
CachedDirectory::Entries files= directory.getEntries();
77
pthread_rwlock_wrlock(&schema_lock);
79
77
for (CachedDirectory::Entries::iterator fileIter= files.begin();
80
78
fileIter != files.end(); fileIter++)
101
pthread_rwlock_unlock(&schema_lock);
104
102
void Schema::doGetSchemaIdentifiers(SchemaIdentifiers &set_of_names)
106
if (not pthread_rwlock_rdlock(&schema_lock))
108
106
for (SchemaCache::iterator iter= schema_cache.begin();
109
107
iter != schema_cache.end();
112
110
set_of_names.push_back(SchemaIdentifier((*iter).second.name()));
114
pthread_rwlock_unlock(&schema_lock);
119
// If for some reason getting a lock should fail, we resort to disk
121
CachedDirectory directory(data_home, CachedDirectory::DIRECTORY);
123
CachedDirectory::Entries files= directory.getEntries();
125
for (CachedDirectory::Entries::iterator fileIter= files.begin();
126
fileIter != files.end(); fileIter++)
128
CachedDirectory::Entry *entry= *fileIter;
129
set_of_names.push_back(entry->filename);
113
mutex.unlock_shared();
133
116
bool Schema::doGetSchemaDefinition(const SchemaIdentifier &schema_identifier, message::Schema &schema_message)
135
if (not pthread_rwlock_rdlock(&schema_lock))
119
SchemaCache::iterator iter= schema_cache.find(schema_identifier.getPath());
121
if (iter != schema_cache.end())
137
SchemaCache::iterator iter= schema_cache.find(schema_identifier.getPath());
139
if (iter != schema_cache.end())
141
schema_message.CopyFrom(((*iter).second));
142
pthread_rwlock_unlock(&schema_lock);
145
pthread_rwlock_unlock(&schema_lock);
123
schema_message.CopyFrom(((*iter).second));
124
mutex.unlock_shared();
127
mutex.unlock_shared();
150
// Fail to disk based means
151
return readSchemaFile(schema_identifier.getPath(), schema_message);
154
133
bool Schema::doCreateSchema(const drizzled::message::Schema &schema_message)
156
135
SchemaIdentifier schema_identifier(schema_message.name());
168
if (not pthread_rwlock_wrlock(&schema_lock))
170
pair<SchemaCache::iterator, bool> ret=
171
schema_cache.insert(make_pair(schema_identifier.getPath(), schema_message));
174
if (ret.second == false)
176
abort(); // If this has happened, something really bad is going down.
178
pthread_rwlock_unlock(&schema_lock);
149
pair<SchemaCache::iterator, bool> ret=
150
schema_cache.insert(make_pair(schema_identifier.getPath(), schema_message));
153
if (ret.second == false)
155
abort(); // If this has happened, something really bad is going down.