MCPcopy Create free account
hub / github.com/apple/foundationdb / ThreadSafeDatabase

Method ThreadSafeDatabase

fdbclient/ThreadSafeTransaction.cpp:197–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195}
196
197ThreadSafeDatabase::ThreadSafeDatabase(ConnectionRecordType connectionRecordType,
198 std::string connectionRecordString,
199 int apiVersion) {
200 // Allocate memory for the Database from this thread (so the pointer is known for subsequent method calls)
201 // but run its constructor on the main thread
202 DatabaseContext* db = this->db = DatabaseContext::allocateOnForeignThread();
203
204 onMainThreadVoid([db, connectionRecordType, connectionRecordString, apiVersion]() {
205 try {
206 Reference<IClusterConnectionRecord> connectionRecord =
207 connectionRecordType == ConnectionRecordType::FILE
208 ? Reference<IClusterConnectionRecord>(ClusterConnectionFile::openOrDefault(connectionRecordString))
209 : Reference<IClusterConnectionRecord>(
210 new ClusterConnectionMemoryRecord(ClusterConnectionString(connectionRecordString)));
211
212 Database::createDatabase(connectionRecord, apiVersion, IsInternal::False, LocalityData(), db).extractPtr();
213 } catch (Error& e) {
214 new (db) DatabaseContext(e);
215 } catch (...) {
216 new (db) DatabaseContext(unknown_error());
217 }
218 });
219}
220
221ThreadSafeDatabase::~ThreadSafeDatabase() {
222 DatabaseContext* db = this->db;

Callers

nothing calls this directly

Calls 5

onMainThreadVoidFunction · 0.85
createDatabaseFunction · 0.85
LocalityDataClass · 0.50
extractPtrMethod · 0.45

Tested by

no test coverage detected