Change cluster objects to be a char* for the cluster file path. Remove IDatabase::createDatabase. DLApi::createDatabase deletes the temporary cluster it creates.

This commit is contained in:
A.J. Beamon 2018-09-25 11:01:09 -07:00
parent 258e9225eb
commit 6ae50f7016
6 changed files with 13 additions and 26 deletions

View File

@ -37,6 +37,7 @@ int g_api_version = 0;
#define TSAVB(f) ((ThreadSingleAssignmentVarBase*)(f))
#define TSAV(T, f) ((ThreadSingleAssignmentVar<T>*)(f))
#define CLUSTER(c) ((char*)c)
#define DB(d) ((IDatabase*)d)
#define TXN(t) ((ITransaction*)t)
@ -236,7 +237,7 @@ extern "C" DLLEXPORT
fdb_error_t fdb_future_get_cluster( FDBFuture* f, FDBCluster** out_cluster ) {
CATCH_AND_RETURN(
*out_cluster = (FDBCluster*)
( (TSAV( Reference<IDatabase>, f )->get() ).extractPtr() ); );
( (TSAV( char*, f )->get() ) ); );
}
extern "C" DLLEXPORT
@ -293,7 +294,12 @@ fdb_error_t fdb_future_get_string_array(
extern "C" DLLEXPORT
FDBFuture* fdb_create_cluster( const char* cluster_file_path ) {
return (FDBFuture*) API->createDatabase( cluster_file_path ? cluster_file_path : "").extractPtr();
char *path = NULL;
if(cluster_file_path) {
path = (char*)malloc(strlen(cluster_file_path));
strcpy(path, cluster_file_path);
}
return (FDBFuture*)ThreadFuture<char*>(path).extractPtr();
}
extern "C" DLLEXPORT
@ -308,7 +314,7 @@ fdb_error_t fdb_cluster_set_option( FDBCluster* c,
extern "C" DLLEXPORT
void fdb_cluster_destroy( FDBCluster* c ) {
CATCH_AND_DIE( DB(c)->delref(); );
CATCH_AND_DIE( free(c); );
}
extern "C" DLLEXPORT
@ -319,7 +325,7 @@ FDBFuture* fdb_cluster_create_database( FDBCluster* c, uint8_t const* db_name,
return (FDBFuture*)ThreadFuture<Reference<IDatabase>>(invalid_database_name()).extractPtr();
}
return (FDBFuture*)ThreadFuture<Reference<IDatabase>>(Reference<IDatabase>(DB(c))).extractPtr();
return (FDBFuture*) API->createDatabase( CLUSTER(c) ? CLUSTER(c) : "").extractPtr();
}
extern "C" DLLEXPORT

View File

@ -75,7 +75,6 @@ class IDatabase {
public:
virtual ~IDatabase() {}
virtual ThreadFuture<Reference<IDatabase>> createDatabase() = 0;
virtual Reference<ITransaction> createTransaction() = 0;
virtual void setOption(FDBDatabaseOptions::Option option, Optional<StringRef> value = Optional<StringRef>()) = 0;

View File

@ -212,10 +212,6 @@ void DLTransaction::reset() {
}
// DLDatabase
ThreadFuture<Reference<IDatabase>> DLDatabase::createDatabase() {
return Reference<IDatabase>::addRef(this);
}
Reference<ITransaction> DLDatabase::createTransaction() {
FdbCApi::FDBTransaction *tr;
api->databaseCreateTransaction(db, &tr);
@ -370,7 +366,8 @@ ThreadFuture<Reference<IDatabase>> DLApi::createDatabase(const char *clusterFile
return ErrorOr<ThreadFuture<Reference<IDatabase>>>(toThreadFuture<Reference<IDatabase>>(innerApi, f, [cluster](FdbCApi::FDBFuture *f, FdbCApi *api) {
FdbCApi::FDBDatabase *db;
api->futureGetDatabase(f, &db);
return Reference<IDatabase>(new DLDatabase(Reference<FdbCApi>::addRef(api), cluster.get(), db));
api->clusterDestroy(cluster.get());
return Reference<IDatabase>(new DLDatabase(Reference<FdbCApi>::addRef(api), db));
}));
});
}
@ -700,10 +697,6 @@ void MultiVersionDatabase::Connector::error(const Error& e, int& userParam) {
MultiVersionDatabase::DatabaseState::DatabaseState()
: dbVar(new ThreadSafeAsyncVar<Reference<IDatabase>>(Reference<IDatabase>(NULL))), currentClientIndex(-1) {}
ThreadFuture<Reference<IDatabase>> MultiVersionDatabase::createDatabase() {
return ThreadFuture<Reference<IDatabase>>(Reference<IDatabase>::addRef(this));
}
// Only called from main thread
void MultiVersionDatabase::DatabaseState::stateChanged() {
int newIndex = -1;

View File

@ -159,10 +159,9 @@ private:
class DLDatabase : public IDatabase, ThreadSafeReferenceCounted<DLDatabase> {
public:
DLDatabase(Reference<FdbCApi> api, FdbCApi::FDBCluster *cluster, FdbCApi::FDBDatabase *db) : api(api), cluster(cluster), db(db) {}
DLDatabase(Reference<FdbCApi> api, FdbCApi::FDBDatabase *db) : api(api), db(db) {}
~DLDatabase() { api->databaseDestroy(db); }
ThreadFuture<Reference<IDatabase>> createDatabase();
Reference<ITransaction> createTransaction();
void setOption(FDBDatabaseOptions::Option option, Optional<StringRef> value = Optional<StringRef>());
@ -171,8 +170,6 @@ public:
private:
const Reference<FdbCApi> api;
FdbCApi::FDBCluster* const cluster;
FdbCApi::FDBDatabase* const db;
};
@ -284,7 +281,6 @@ public:
MultiVersionDatabase(MultiVersionApi *api, std::string clusterFilePath, Reference<IDatabase> db, bool openConnectors=true);
~MultiVersionDatabase();
ThreadFuture<Reference<IDatabase>> createDatabase();
Reference<ITransaction> createTransaction();
void setOption(FDBDatabaseOptions::Option option, Optional<StringRef> value = Optional<StringRef>());

View File

@ -56,12 +56,6 @@ ThreadFuture<Reference<IDatabase>> ThreadSafeDatabase::createFromExistingDatabas
});
}
ThreadFuture<Reference<IDatabase>> ThreadSafeDatabase::createDatabase() {
return onMainThread([this](){
return Future<Reference<IDatabase>>(Reference<IDatabase>::addRef(this));
});
}
Reference<ITransaction> ThreadSafeDatabase::createTransaction() {
return Reference<ITransaction>(new ThreadSafeTransaction(this));
}

View File

@ -33,7 +33,6 @@ public:
static ThreadFuture<Reference<IDatabase>> create( std::string connFilename, int apiVersion=-1 );
static ThreadFuture<Reference<IDatabase>> createFromExistingDatabase(Database cx);
ThreadFuture<Reference<IDatabase>> createDatabase();
Reference<ITransaction> createTransaction();
void setOption( FDBDatabaseOptions::Option option, Optional<StringRef> value = Optional<StringRef>() );