From 6ae50f7016439f80757d4d007c70795740638aab Mon Sep 17 00:00:00 2001 From: "A.J. Beamon" Date: Tue, 25 Sep 2018 11:01:09 -0700 Subject: [PATCH] Change cluster objects to be a char* for the cluster file path. Remove IDatabase::createDatabase. DLApi::createDatabase deletes the temporary cluster it creates. --- bindings/c/fdb_c.cpp | 14 ++++++++++---- fdbclient/IClientApi.h | 1 - fdbclient/MultiVersionTransaction.actor.cpp | 11 ++--------- fdbclient/MultiVersionTransaction.h | 6 +----- fdbclient/ThreadSafeTransaction.actor.cpp | 6 ------ fdbclient/ThreadSafeTransaction.h | 1 - 6 files changed, 13 insertions(+), 26 deletions(-) diff --git a/bindings/c/fdb_c.cpp b/bindings/c/fdb_c.cpp index 3189d276d5..aa6c7f25f5 100644 --- a/bindings/c/fdb_c.cpp +++ b/bindings/c/fdb_c.cpp @@ -37,6 +37,7 @@ int g_api_version = 0; #define TSAVB(f) ((ThreadSingleAssignmentVarBase*)(f)) #define TSAV(T, f) ((ThreadSingleAssignmentVar*)(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, 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(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>(invalid_database_name()).extractPtr(); } - return (FDBFuture*)ThreadFuture>(Reference(DB(c))).extractPtr(); + return (FDBFuture*) API->createDatabase( CLUSTER(c) ? CLUSTER(c) : "").extractPtr(); } extern "C" DLLEXPORT diff --git a/fdbclient/IClientApi.h b/fdbclient/IClientApi.h index 8dfa05fedd..df609d1c57 100644 --- a/fdbclient/IClientApi.h +++ b/fdbclient/IClientApi.h @@ -75,7 +75,6 @@ class IDatabase { public: virtual ~IDatabase() {} - virtual ThreadFuture> createDatabase() = 0; virtual Reference createTransaction() = 0; virtual void setOption(FDBDatabaseOptions::Option option, Optional value = Optional()) = 0; diff --git a/fdbclient/MultiVersionTransaction.actor.cpp b/fdbclient/MultiVersionTransaction.actor.cpp index 8cf93d3119..08a812e37e 100644 --- a/fdbclient/MultiVersionTransaction.actor.cpp +++ b/fdbclient/MultiVersionTransaction.actor.cpp @@ -212,10 +212,6 @@ void DLTransaction::reset() { } // DLDatabase -ThreadFuture> DLDatabase::createDatabase() { - return Reference::addRef(this); -} - Reference DLDatabase::createTransaction() { FdbCApi::FDBTransaction *tr; api->databaseCreateTransaction(db, &tr); @@ -370,7 +366,8 @@ ThreadFuture> DLApi::createDatabase(const char *clusterFile return ErrorOr>>(toThreadFuture>(innerApi, f, [cluster](FdbCApi::FDBFuture *f, FdbCApi *api) { FdbCApi::FDBDatabase *db; api->futureGetDatabase(f, &db); - return Reference(new DLDatabase(Reference::addRef(api), cluster.get(), db)); + api->clusterDestroy(cluster.get()); + return Reference(new DLDatabase(Reference::addRef(api), db)); })); }); } @@ -700,10 +697,6 @@ void MultiVersionDatabase::Connector::error(const Error& e, int& userParam) { MultiVersionDatabase::DatabaseState::DatabaseState() : dbVar(new ThreadSafeAsyncVar>(Reference(NULL))), currentClientIndex(-1) {} -ThreadFuture> MultiVersionDatabase::createDatabase() { - return ThreadFuture>(Reference::addRef(this)); -} - // Only called from main thread void MultiVersionDatabase::DatabaseState::stateChanged() { int newIndex = -1; diff --git a/fdbclient/MultiVersionTransaction.h b/fdbclient/MultiVersionTransaction.h index 2419d82a67..99c111b024 100644 --- a/fdbclient/MultiVersionTransaction.h +++ b/fdbclient/MultiVersionTransaction.h @@ -159,10 +159,9 @@ private: class DLDatabase : public IDatabase, ThreadSafeReferenceCounted { public: - DLDatabase(Reference api, FdbCApi::FDBCluster *cluster, FdbCApi::FDBDatabase *db) : api(api), cluster(cluster), db(db) {} + DLDatabase(Reference api, FdbCApi::FDBDatabase *db) : api(api), db(db) {} ~DLDatabase() { api->databaseDestroy(db); } - ThreadFuture> createDatabase(); Reference createTransaction(); void setOption(FDBDatabaseOptions::Option option, Optional value = Optional()); @@ -171,8 +170,6 @@ public: private: const Reference api; - - FdbCApi::FDBCluster* const cluster; FdbCApi::FDBDatabase* const db; }; @@ -284,7 +281,6 @@ public: MultiVersionDatabase(MultiVersionApi *api, std::string clusterFilePath, Reference db, bool openConnectors=true); ~MultiVersionDatabase(); - ThreadFuture> createDatabase(); Reference createTransaction(); void setOption(FDBDatabaseOptions::Option option, Optional value = Optional()); diff --git a/fdbclient/ThreadSafeTransaction.actor.cpp b/fdbclient/ThreadSafeTransaction.actor.cpp index 6d85a42c94..fcfa45c44d 100644 --- a/fdbclient/ThreadSafeTransaction.actor.cpp +++ b/fdbclient/ThreadSafeTransaction.actor.cpp @@ -56,12 +56,6 @@ ThreadFuture> ThreadSafeDatabase::createFromExistingDatabas }); } -ThreadFuture> ThreadSafeDatabase::createDatabase() { - return onMainThread([this](){ - return Future>(Reference::addRef(this)); - }); -} - Reference ThreadSafeDatabase::createTransaction() { return Reference(new ThreadSafeTransaction(this)); } diff --git a/fdbclient/ThreadSafeTransaction.h b/fdbclient/ThreadSafeTransaction.h index ede6638e14..b1ddc0d6e0 100644 --- a/fdbclient/ThreadSafeTransaction.h +++ b/fdbclient/ThreadSafeTransaction.h @@ -33,7 +33,6 @@ public: static ThreadFuture> create( std::string connFilename, int apiVersion=-1 ); static ThreadFuture> createFromExistingDatabase(Database cx); - ThreadFuture> createDatabase(); Reference createTransaction(); void setOption( FDBDatabaseOptions::Option option, Optional value = Optional() );