From b58347138f0356f1349c7fc8dbe08d091fce1e8f Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Mon, 18 Nov 2013 18:39:18 +0100 Subject: [PATCH] destroy can only be called if initialised --- arangod/RestServer/ArangoServer.cpp | 112 +++----- arangod/RestServer/ArangoServer.h | 74 +---- arangod/VocBase/server.c | 426 +++++++++++----------------- arangod/VocBase/server.h | 61 +--- lib/BasicsC/locks-posix.c | 83 +----- lib/BasicsC/locks-posix.h | 9 - 6 files changed, 227 insertions(+), 538 deletions(-) diff --git a/arangod/RestServer/ArangoServer.cpp b/arangod/RestServer/ArangoServer.cpp index abd108a8e9..0d286ffd9b 100644 --- a/arangod/RestServer/ArangoServer.cpp +++ b/arangod/RestServer/ArangoServer.cpp @@ -97,11 +97,6 @@ using namespace triagens::arango; // --SECTION-- private functions // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup ArangoDB -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief define "_api" handlers //////////////////////////////////////////////////////////////////////////////// @@ -112,7 +107,7 @@ static void DefineApiHandlers (HttpHandlerFactory* factory, // add "/version" handler admin->addBasicHandlers(factory, "/_api", (void*) jobManager); - + // add "/batch" handler factory->addPrefixHandler(RestVocbaseBaseHandler::BATCH_PATH, RestHandlerCreator::createNoData); @@ -164,7 +159,7 @@ static TRI_vocbase_t* LookupDatabaseFromRequest (triagens::rest::HttpRequest* re // get the request endpoint ConnectionInfo ci = request->connectionInfo(); const string& endpoint = ci.endpoint; - + // get the databases mapped to the endpoint ApplicationEndpointServer* s = static_cast(server->_applicationEndpointServer); const vector databases = s->getEndpointMapping(endpoint); @@ -174,7 +169,7 @@ static TRI_vocbase_t* LookupDatabaseFromRequest (triagens::rest::HttpRequest* re if (databases.empty()) { // no databases defined. this means all databases are accessible via the endpoint - + if (dbName.empty()) { // if no databases was specified in the request, use system database name as a fallback dbName = TRI_VOC_SYSTEM_DATABASE; @@ -204,14 +199,14 @@ static TRI_vocbase_t* LookupDatabaseFromRequest (triagens::rest::HttpRequest* re } } } - - TRI_vocbase_t* vocbase = TRI_UseDatabaseServer(server, dbName.c_str()); - + + TRI_vocbase_t* vocbase = TRI_UseDatabaseServer(server, dbName.c_str()); + if (vocbase == 0) { // database not found return 0; - } + } return vocbase; } @@ -220,7 +215,7 @@ static TRI_vocbase_t* LookupDatabaseFromRequest (triagens::rest::HttpRequest* re /// @brief add the context to a request //////////////////////////////////////////////////////////////////////////////// -static bool SetRequestContext (triagens::rest::HttpRequest* request, +static bool SetRequestContext (triagens::rest::HttpRequest* request, void* data) { TRI_server_t* server = (TRI_server_t*) data; @@ -237,17 +232,13 @@ static bool SetRequestContext (triagens::rest::HttpRequest* request, // out of memory return false; } - + // the "true" means the request is the owner of the context request->setRequestContext(ctx, true); return true; } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- class ArangoServer // ----------------------------------------------------------------------------- @@ -256,11 +247,6 @@ static bool SetRequestContext (triagens::rest::HttpRequest* request, // --SECTION-- constructors and destructors // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup ArangoDB -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// @@ -304,8 +290,8 @@ ArangoServer::ArangoServer (int argc, char** argv) _defaultLanguage = Utf8Helper::DefaultUtf8Helper.getCollatorLanguage(); - - TRI_InitialiseServer(); + + TRI_InitServerGlobals(); _server = TRI_CreateServer(); @@ -313,7 +299,7 @@ ArangoServer::ArangoServer (int argc, char** argv) LOG_FATAL_AND_EXIT("could not create server instance"); } } - + //////////////////////////////////////////////////////////////////////////////// /// @brief destructor //////////////////////////////////////////////////////////////////////////////// @@ -326,25 +312,16 @@ ArangoServer::~ArangoServer () { if (_server != 0) { TRI_FreeServer(_server); } - - TRI_ShutdownServer(); + + TRI_FreeServerGlobals(); Nonce::destroy(); } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- AnyServer methods // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup ArangoDB -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// @@ -390,9 +367,11 @@ void ArangoServer::buildApplicationServer () { // ............................................................................. _applicationV8 = new ApplicationV8(_server); + if (_applicationV8 == 0) { LOGGER_FATAL_AND_EXIT("out of memory"); } + _applicationServer->addFeature(_applicationV8); // ............................................................................. @@ -402,9 +381,11 @@ void ArangoServer::buildApplicationServer () { #ifdef TRI_ENABLE_MRUBY _applicationMR = new ApplicationMR(_server); + if (_applicationMR == 0) { LOGGER_FATAL_AND_EXIT("out of memory"); } + _applicationServer->addFeature(_applicationMR); #else @@ -419,7 +400,7 @@ void ArangoServer::buildApplicationServer () { ; #endif - + // ............................................................................. // and start a simple admin server // ............................................................................. @@ -482,7 +463,7 @@ void ArangoServer::buildApplicationServer () { ("jslint", &_jslint, "do not start as server, run js lint instead") ("javascript.unit-tests", &_unitTests, "do not start as server, run unit tests instead") ; - + // ............................................................................. // database options // ............................................................................. @@ -530,7 +511,7 @@ void ArangoServer::buildApplicationServer () { additional["THREAD Options:help-admin"] ("server.threads", &_dispatcherThreads, "number of threads for basic operations") ; - + additional["Server Options:help-extended"] ("scheduler.maximal-queue-size", &_dispatcherQueueSize, "maximum size of queue for asynchronous operations") ; @@ -561,9 +542,9 @@ void ArangoServer::buildApplicationServer () { if (! _applicationServer->parse(_argc, _argv, additional)) { CLEANUP_LOGGING_AND_EXIT_ON_FATAL_ERROR(); } - + // set the temp-path - _tempPath = StringUtils::rTrim(_tempPath, TRI_DIR_SEPARATOR_STR); + _tempPath = StringUtils::rTrim(_tempPath, TRI_DIR_SEPARATOR_STR); if (_applicationServer->programOptions().has("temp-path")) { TRI_SetUserTempPath((char*) _tempPath.c_str()); } @@ -631,14 +612,14 @@ void ArangoServer::buildApplicationServer () { } // strip trailing separators - _databasePath = StringUtils::rTrim(_databasePath, TRI_DIR_SEPARATOR_STR); - + _databasePath = StringUtils::rTrim(_databasePath, TRI_DIR_SEPARATOR_STR); + _applicationEndpointServer->setBasePath(_databasePath); // ............................................................................. // now run arangod // ............................................................................. - + // dump version details LOGGER_INFO(rest::Version::getVerboseVersionString()); @@ -706,7 +687,7 @@ void ArangoServer::buildApplicationServer () { int ArangoServer::startupServer () { v8::HandleScope scope; - + // ............................................................................. // prepare the various parts of the Arango server // ............................................................................. @@ -714,7 +695,7 @@ int ArangoServer::startupServer () { if (_dispatcherThreads < 1) { _dispatcherThreads = 1; } - + // open all databases openDatabases(); @@ -751,7 +732,7 @@ int ArangoServer::startupServer () { _applicationDispatcher->buildStandardQueue(_dispatcherThreads, (int) _dispatcherQueueSize); _applicationServer->prepare2(); - + // we pass the options by reference, so keep them until shutdown RestActionHandler::action_options_t httpOptions; @@ -812,19 +793,10 @@ int ArangoServer::startupServer () { return 0; } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- private methods // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup ArangoDB -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief executes the JavaScript emergency console //////////////////////////////////////////////////////////////////////////////// @@ -1254,9 +1226,9 @@ int ArangoServer::executeRubyConsole () { //////////////////////////////////////////////////////////////////////////////// void ArangoServer::openDatabases () { - TRI_vocbase_defaults_t defaults; + TRI_vocbase_defaults_t defaults; - // override with command-line options + // override with command-line options defaults.defaultMaximalSize = _defaultMaximalSize; defaults.removeOnDrop = _removeOnDrop; defaults.removeOnCompacted = _removeOnCompacted; @@ -1265,18 +1237,18 @@ void ArangoServer::openDatabases () { defaults.forceSyncProperties = _forceSyncProperties; defaults.requireAuthentication = ! _disableAuthentication; defaults.authenticateSystemOnly = _authenticateSystemOnly; - - assert(_server != 0); - - int res = TRI_InitServer(_server, + + assert(_server != 0); + + int res = TRI_InitServer(_server, _applicationEndpointServer, _databasePath.c_str(), _applicationV8->appPath().c_str(), - _applicationV8->devAppPath().c_str(), - &defaults, - _disableReplicationLogger, + _applicationV8->devAppPath().c_str(), + &defaults, + _disableReplicationLogger, _disableReplicationApplier); - + if (res != TRI_ERROR_NO_ERROR) { LOG_FATAL_AND_EXIT("cannot create server instance: out of memory"); } @@ -1287,7 +1259,7 @@ void ArangoServer::openDatabases () { if (res != TRI_ERROR_NO_ERROR) { LOG_FATAL_AND_EXIT("cannot start server: %s", TRI_errno_string(res)); } - + LOG_TRACE("found system database"); } @@ -1306,10 +1278,6 @@ void ArangoServer::closeDatabases () { LOGGER_INFO("ArangoDB has been shut down"); } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- END-OF-FILE // ----------------------------------------------------------------------------- diff --git a/arangod/RestServer/ArangoServer.h b/arangod/RestServer/ArangoServer.h index 4536a572b9..0c22cbed21 100644 --- a/arangod/RestServer/ArangoServer.h +++ b/arangod/RestServer/ArangoServer.h @@ -66,11 +66,6 @@ namespace triagens { // --SECTION-- class ArangoServer // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup ArangoDB -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief ArangoDB server //////////////////////////////////////////////////////////////////////////////// @@ -80,19 +75,10 @@ namespace triagens { ArangoServer (const ArangoServer&); ArangoServer& operator= (const ArangoServer&); -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- constructors and destructors // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup ArangoDB -/// @{ -//////////////////////////////////////////////////////////////////////////////// - public: //////////////////////////////////////////////////////////////////////////////// @@ -107,19 +93,10 @@ namespace triagens { ~ArangoServer (); -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- AnyServer methods // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup ArangoDB -/// @{ -//////////////////////////////////////////////////////////////////////////////// - public: //////////////////////////////////////////////////////////////////////////////// @@ -134,34 +111,16 @@ namespace triagens { int startupServer (); -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- public static methods // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup ArangoDB -/// @{ -//////////////////////////////////////////////////////////////////////////////// - public: -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- private methods // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup ArangoDB -/// @{ -//////////////////////////////////////////////////////////////////////////////// - private: //////////////////////////////////////////////////////////////////////////////// @@ -189,20 +148,11 @@ namespace triagens { //////////////////////////////////////////////////////////////////////////////// void closeDatabases (); - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup ArangoDB -/// @{ -//////////////////////////////////////////////////////////////////////////////// - private: //////////////////////////////////////////////////////////////////////////////// @@ -274,15 +224,15 @@ namespace triagens { /// /// Controls whether incoming requests need authentication only if they are /// directed to the ArangoDB's internal APIs and features, located at `/_api/`, -/// `/_admin/` etc. +/// `/_admin/` etc. /// /// IF the flag is set to @LIT{true}, then HTTP authentication is only -/// required for requests going to URLs starting with `/_`, but not for other +/// required for requests going to URLs starting with `/_`, but not for other /// URLs. The flag can thus be used to expose a user-made API without HTTP /// authentication to the outside world, but to prevent the outside world from /// using the ArangoDB API and the admin interface without authentication. /// Note that checking the URL is performed after any database name prefix -/// has been removed. That means when the actual URL called is +/// has been removed. That means when the actual URL called is /// `/_db/_system/myapp/myaction`, the URL `/myapp/myaction` will be used for /// `authenticate-system-only` check. /// @@ -292,8 +242,8 @@ namespace triagens { /// in order for HTTP authentication to be forced for the ArangoDB API and the /// web interface. Setting only this flag is not enough. /// -/// You can control ArangoDB's general authentication feature with the -/// `--server.disable-authentication` flag. +/// You can control ArangoDB's general authentication feature with the +/// `--server.disable-authentication` flag. //////////////////////////////////////////////////////////////////////////////// bool _authenticateSystemOnly; @@ -399,7 +349,7 @@ namespace triagens { /// development mode forces reloading of all actions and Foxx applications on /// every HTTP request. This is very resource-intensive and slow, but makes /// developing server-side actions and Foxx applications much easier. -/// +/// /// Never use this option in production. //////////////////////////////////////////////////////////////////////////////// @@ -410,10 +360,10 @@ namespace triagens { /// /// @CMDOPT{\--database.force-sync-properties @CA{boolean}} /// -/// Force syncing of collection properties to disk after creating a collection +/// Force syncing of collection properties to disk after creating a collection /// or updating its properties. /// -/// If turned off, syncing will still happen for collection that have a +/// If turned off, syncing will still happen for collection that have a /// waitForSync value of @LIT{true}. If turned on, syncing of properties will /// always happen, regardless of the value of waitForSync. /// @@ -445,7 +395,7 @@ namespace triagens { /// If @LIT{true} the server will start with the replication logger turned off, /// even if the replication logger is configured with the `autoStart` option. /// Using this option will not change the value of the `autoStart` option in -/// the logger configuration, but will suppress auto-starting the replication +/// the logger configuration, but will suppress auto-starting the replication /// logger just once. /// /// If the option is not used, ArangoDB will read the logger configuration from @@ -465,7 +415,7 @@ namespace triagens { /// If @LIT{true} the server will start with the replication applier turned off, /// even if the replication applier is configured with the `autoStart` option. /// Using the command-line option will not change the value of the `autoStart` -/// option in the applier configuration, but will suppress auto-starting the +/// option in the applier configuration, but will suppress auto-starting the /// replication applier just once. /// /// If the option is not used, ArangoDB will read the applier configuration from @@ -573,10 +523,6 @@ namespace triagens { } } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - #endif // ----------------------------------------------------------------------------- diff --git a/arangod/VocBase/server.c b/arangod/VocBase/server.c index 401f19c086..8e738044cd 100644 --- a/arangod/VocBase/server.c +++ b/arangod/VocBase/server.c @@ -50,11 +50,6 @@ // --SECTION-- private defines // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief mask value for significant bits of server id //////////////////////////////////////////////////////////////////////////////// @@ -67,19 +62,10 @@ #define DATABASE_MANAGER_INTERVAL (500 * 1000) -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief page size //////////////////////////////////////////////////////////////////////////////// @@ -110,10 +96,6 @@ static TRI_spin_t TickLock; static TRI_server_id_t ServerId; -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- private functions // ----------------------------------------------------------------------------- @@ -122,16 +104,11 @@ static TRI_server_id_t ServerId; // --SECTION-- database hash functions // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief hashes the database name //////////////////////////////////////////////////////////////////////////////// -static uint64_t HashElementDatabaseName (TRI_associative_pointer_t* array, +static uint64_t HashElementDatabaseName (TRI_associative_pointer_t* array, void const* element) { TRI_vocbase_t const* e = element; @@ -142,8 +119,8 @@ static uint64_t HashElementDatabaseName (TRI_associative_pointer_t* array, /// @brief compares a database name and a database //////////////////////////////////////////////////////////////////////////////// -static bool EqualKeyDatabaseName (TRI_associative_pointer_t* array, - void const* key, +static bool EqualKeyDatabaseName (TRI_associative_pointer_t* array, + void const* key, void const* element) { char const* k = (char const*) key; TRI_vocbase_t const* e = element; @@ -151,19 +128,10 @@ static bool EqualKeyDatabaseName (TRI_associative_pointer_t* array, return TRI_EqualString(k, e->_name); } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- server id functions // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief generates a new server id /// @@ -304,19 +272,10 @@ static int DetermineServerId (TRI_server_t* server) { return res; } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- tick functions // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief returns the current tick value, without using a lock //////////////////////////////////////////////////////////////////////////////// @@ -337,10 +296,6 @@ static inline void UpdateTick (TRI_voc_tick_t tick) { } } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief reads shutdown information file /// this is called at server startup. if the file is present, the last tick @@ -364,7 +319,7 @@ static int ReadShutdownInfo (char const* filename) { if (json == NULL) { return TRI_ERROR_INTERNAL; } - + shutdownTime = TRI_LookupArrayJson(json, "shutdownTime"); if (TRI_IsStringJson(shutdownTime)) { @@ -383,7 +338,7 @@ static int ReadShutdownInfo (char const* filename) { tickString->_value._string.length - 1); TRI_FreeJson(TRI_CORE_MEM_ZONE, json); - LOG_TRACE("using existing tick from shutdown info file: %llu", + LOG_TRACE("using existing tick from shutdown info file: %llu", (unsigned long long) foundTick); if (foundTick == 0) { @@ -412,7 +367,7 @@ static int RemoveShutdownInfo (TRI_server_t* server) { /// @brief writes shutdown information file /// the file will contain the timestamp of the shutdown time plus the last /// tick value the server used. it will be read on restart of the server. -/// if the server can find the file on restart, it can avoid scanning +/// if the server can find the file on restart, it can avoid scanning /// collections. //////////////////////////////////////////////////////////////////////////////// @@ -430,7 +385,7 @@ static int WriteShutdownInfo (TRI_server_t* server) { if (json == NULL) { // out of memory - LOG_ERROR("cannot save shutdown info in file '%s': out of memory", + LOG_ERROR("cannot save shutdown info in file '%s': out of memory", server->_shutdownFilename); return TRI_ERROR_OUT_OF_MEMORY; @@ -451,8 +406,8 @@ static int WriteShutdownInfo (TRI_server_t* server) { TRI_FreeJson(TRI_CORE_MEM_ZONE, json); if (! ok) { - LOG_ERROR("could not save shutdown info in file '%s': %s", - server->_shutdownFilename, + LOG_ERROR("could not save shutdown info in file '%s': %s", + server->_shutdownFilename, TRI_last_error()); return TRI_ERROR_INTERNAL; @@ -461,19 +416,10 @@ static int WriteShutdownInfo (TRI_server_t* server) { return TRI_ERROR_NO_ERROR; } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- database functions // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief check if a user can see a database //////////////////////////////////////////////////////////////////////////////// @@ -496,7 +442,7 @@ static bool CanUseDatabase (TRI_vocbase_t* vocbase, static int DatabaseNameComparator (const void* lhs, const void* rhs) { const char* l = *((char**) lhs); const char* r = *((char**) rhs); - + return strcmp(l, r); } @@ -505,7 +451,7 @@ static int DatabaseNameComparator (const void* lhs, const void* rhs) { //////////////////////////////////////////////////////////////////////////////// static void SortDatabaseNames (TRI_vector_string_t* names) { - qsort(names->_buffer, names->_length, sizeof(char*), &DatabaseNameComparator); + qsort(names->_buffer, names->_length, sizeof(char*), &DatabaseNameComparator); } //////////////////////////////////////////////////////////////////////////////// @@ -526,7 +472,7 @@ static uint64_t GetNumericFilenamePart (const char* filename) { //////////////////////////////////////////////////////////////////////////////// /// @brief compare two filenames, based on the numeric part contained in -/// the filename. this is used to sort database filenames on startup +/// the filename. this is used to sort database filenames on startup //////////////////////////////////////////////////////////////////////////////// static int DatabaseIdComparator (const void* lhs, const void* rhs) { @@ -564,7 +510,7 @@ static int CreateBaseApplicationDirectory (char const* basePath, res = TRI_CreateDirectory(path); if (res == TRI_ERROR_NO_ERROR) { - LOG_INFO("created base application directory '%s'", + LOG_INFO("created base application directory '%s'", path); } else { @@ -601,14 +547,14 @@ static int CreateApplicationDirectory (char const* name, res = TRI_CreateDirectory(path); if (res == TRI_ERROR_NO_ERROR) { - LOG_INFO("created application directory '%s' for database '%s'", - path, + LOG_INFO("created application directory '%s' for database '%s'", + path, name); } else { - LOG_ERROR("unable to create application directory '%s' for database '%s': %s", - path, - name, + LOG_ERROR("unable to create application directory '%s' for database '%s': %s", + path, + name, TRI_errno_string(res)); } } @@ -631,7 +577,7 @@ static int OpenDatabases (TRI_server_t* server) { res = TRI_ERROR_NO_ERROR; files = TRI_FilesDirectory(server->_databasePath); n = files._length; - + // open databases in defined order if (n > 1) { qsort(files._buffer, n, sizeof(char**), &DatabaseIdComparator); @@ -653,7 +599,7 @@ static int OpenDatabases (TRI_server_t* server) { name = files._buffer[i]; assert(name != NULL); - + // ............................................................................. // construct and validate path // ............................................................................. @@ -671,12 +617,12 @@ static int OpenDatabases (TRI_server_t* server) { } // we have a directory... - + if (! TRI_IsWritable(databaseDirectory)) { // the database directory we found is not writable for the current user // this can cause serious trouble so we will abort the server start if we // encounter this situation - LOG_ERROR("database directory '%s' is not writable for current user", + LOG_ERROR("database directory '%s' is not writable for current user", databaseDirectory); TRI_FreeString(TRI_CORE_MEM_ZONE, databaseDirectory); @@ -685,7 +631,7 @@ static int OpenDatabases (TRI_server_t* server) { } // we have a writable directory... - + // ............................................................................. // read parameter.json file // ............................................................................. @@ -716,9 +662,9 @@ static int OpenDatabases (TRI_server_t* server) { json = TRI_JsonFile(TRI_CORE_MEM_ZONE, parametersFile, NULL); if (json == NULL) { - LOG_ERROR("database directory '%s' does not contain a valid parameters file", + LOG_ERROR("database directory '%s' does not contain a valid parameters file", databaseDirectory); - + TRI_FreeString(TRI_CORE_MEM_ZONE, parametersFile); TRI_FreeString(TRI_CORE_MEM_ZONE, databaseDirectory); // skip this database @@ -734,7 +680,7 @@ static int OpenDatabases (TRI_server_t* server) { // database is deleted, skip it! LOG_INFO("found dropped database in directory '%s'", databaseDirectory); - + LOG_INFO("removing superfluous database directory '%s'", databaseDirectory); @@ -745,11 +691,11 @@ static int OpenDatabases (TRI_server_t* server) { continue; } } - + idJson = TRI_LookupArrayJson(json, "id"); if (! TRI_IsStringJson(idJson)) { - LOG_ERROR("database directory '%s' does not contain a valid parameters file", + LOG_ERROR("database directory '%s' does not contain a valid parameters file", databaseDirectory); TRI_FreeString(TRI_CORE_MEM_ZONE, databaseDirectory); @@ -763,7 +709,7 @@ static int OpenDatabases (TRI_server_t* server) { nameJson = TRI_LookupArrayJson(json, "name"); if (! TRI_IsStringJson(nameJson)) { - LOG_ERROR("database directory '%s' does not contain a valid parameters file", + LOG_ERROR("database directory '%s' does not contain a valid parameters file", databaseDirectory); TRI_FreeString(TRI_CORE_MEM_ZONE, databaseDirectory); @@ -771,9 +717,9 @@ static int OpenDatabases (TRI_server_t* server) { // skip this database continue; } - + databaseName = TRI_DuplicateString2Z(TRI_CORE_MEM_ZONE, nameJson->_value._string.data, nameJson->_value._string.length); - + // ............................................................................. // setup defaults // ............................................................................. @@ -790,13 +736,13 @@ static int OpenDatabases (TRI_server_t* server) { res = TRI_ERROR_OUT_OF_MEMORY; break; } - + // ............................................................................. // create app directories // ............................................................................. res = CreateApplicationDirectory(databaseName, server->_appPath); - + if (res != TRI_ERROR_NO_ERROR) { TRI_FreeString(TRI_CORE_MEM_ZONE, databaseName); TRI_FreeString(TRI_CORE_MEM_ZONE, databaseDirectory); @@ -804,7 +750,7 @@ static int OpenDatabases (TRI_server_t* server) { } res = CreateApplicationDirectory(databaseName, server->_devAppPath); - + if (res != TRI_ERROR_NO_ERROR) { TRI_FreeString(TRI_CORE_MEM_ZONE, databaseName); TRI_FreeString(TRI_CORE_MEM_ZONE, databaseDirectory); @@ -829,22 +775,22 @@ static int OpenDatabases (TRI_server_t* server) { res = TRI_ERROR_INTERNAL; } - LOG_ERROR("could not process database directory '%s' for database '%s': %s", + LOG_ERROR("could not process database directory '%s' for database '%s': %s", databaseDirectory, - name, + name, TRI_errno_string(res)); TRI_FreeString(TRI_CORE_MEM_ZONE, databaseDirectory); break; } - - // we found a valid database + + // we found a valid database TRI_FreeString(TRI_CORE_MEM_ZONE, databaseDirectory); res = TRI_InsertKeyAssociativePointer2(&server->_databases, vocbase->_name, vocbase, &found); if (res != TRI_ERROR_NO_ERROR) { - LOG_ERROR("could not add database '%s': out of memory", + LOG_ERROR("could not add database '%s': out of memory", name); break; @@ -852,12 +798,12 @@ static int OpenDatabases (TRI_server_t* server) { // should never have a duplicate database name assert(found == NULL); - + LOG_INFO("loaded database '%s' from '%s'", vocbase->_name, vocbase->_path); } - + TRI_DestroyVectorString(&files); return res; @@ -894,14 +840,14 @@ static int CloseDatabases (TRI_server_t* server) { /// @brief get the names of all databases in the ArangoDB 1.4 layout //////////////////////////////////////////////////////////////////////////////// -static int GetDatabases (TRI_server_t* server, +static int GetDatabases (TRI_server_t* server, TRI_vector_string_t* databases) { regex_t re; regmatch_t matches[2]; TRI_vector_string_t files; int res; size_t i, n; - + assert(server != NULL); res = regcomp(&re, "^database-([0-9][0-9]*)$", REG_EXTENDED); @@ -924,12 +870,12 @@ static int GetDatabases (TRI_server_t* server, assert(name != NULL); if (regexec(&re, name, sizeof(matches) / sizeof(matches[0]), matches, 0) != 0) { - // found some other file + // found some other file continue; } // found a database name - + dname = TRI_Concatenate2File(server->_databasePath, name); if (dname == NULL) { @@ -946,15 +892,15 @@ static int GetDatabases (TRI_server_t* server, TRI_DestroyVectorString(&files); regfree(&re); - - // sort by id + + // sort by id qsort(databases->_buffer, databases->_length, sizeof(char*), &DatabaseIdComparator); return res; } //////////////////////////////////////////////////////////////////////////////// -/// @brief move the VERSION file from the main data directory into the _system +/// @brief move the VERSION file from the main data directory into the _system /// database subdirectory //////////////////////////////////////////////////////////////////////////////// @@ -971,7 +917,7 @@ static int MoveVersionFile (TRI_server_t* server, } targetName = TRI_Concatenate3File(server->_databasePath, systemName, "VERSION"); - + if (targetName == NULL) { TRI_FreeString(TRI_CORE_MEM_ZONE, oldName); return TRI_ERROR_OUT_OF_MEMORY; @@ -1010,7 +956,7 @@ static bool HasOldCollections (TRI_server_t* server) { found = false; files = TRI_FilesDirectory(server->_basePath); n = files._length; - + for (i = 0; i < n; ++i) { char const* name = files._buffer[i]; assert(name != NULL); @@ -1021,7 +967,7 @@ static bool HasOldCollections (TRI_server_t* server) { break; } } - + TRI_DestroyVectorString(&files); regfree(&re); @@ -1029,7 +975,7 @@ static bool HasOldCollections (TRI_server_t* server) { } //////////////////////////////////////////////////////////////////////////////// -/// @brief move collections from the main data directory into the _system +/// @brief move collections from the main data directory into the _system /// database subdirectory //////////////////////////////////////////////////////////////////////////////// @@ -1088,7 +1034,7 @@ static int MoveOldCollections (TRI_server_t* server, // move into system database directory targetName = TRI_Concatenate3File(server->_databasePath, systemName, name); - + if (targetName == NULL) { TRI_FreeString(TRI_CORE_MEM_ZONE, oldName); res = TRI_ERROR_OUT_OF_MEMORY; @@ -1131,17 +1077,17 @@ static int SaveDatabaseParameters (TRI_voc_tick_t id, char* tickString; TRI_json_t* json; // TRI_json_t* properties; - + assert(id > 0); assert(name != NULL); assert(directory != NULL); - + file = TRI_Concatenate2File(directory, TRI_VOC_PARAMETER_FILE); if (file == NULL) { return TRI_ERROR_OUT_OF_MEMORY; } - + tickString = TRI_StringUInt64((uint64_t) id); if (tickString == NULL) { @@ -1149,7 +1095,7 @@ static int SaveDatabaseParameters (TRI_voc_tick_t id, return TRI_ERROR_OUT_OF_MEMORY; } - + json = TRI_CreateArrayJson(TRI_CORE_MEM_ZONE); if (json == NULL) { @@ -1158,9 +1104,9 @@ static int SaveDatabaseParameters (TRI_voc_tick_t id, return TRI_ERROR_OUT_OF_MEMORY; } - + // TODO - /* + /* properties = TRI_JsonVocBaseDefaults(TRI_CORE_MEM_ZONE, defaults); if (properties == NULL) { @@ -1177,9 +1123,9 @@ static int SaveDatabaseParameters (TRI_voc_tick_t id, TRI_Insert3ArrayJson(TRI_CORE_MEM_ZONE, json, "deleted", TRI_CreateBooleanJson(TRI_CORE_MEM_ZONE, deleted)); // TODO: save properties later when it is clear what they will be used // TRI_Insert3ArrayJson(TRI_CORE_MEM_ZONE, json, "properties", properties); - + TRI_FreeString(TRI_CORE_MEM_ZONE, tickString); - + if (! TRI_SaveJson(file, json, false)) { LOG_ERROR("cannot save database information in file '%s'", file); @@ -1189,7 +1135,7 @@ static int SaveDatabaseParameters (TRI_voc_tick_t id, return TRI_ERROR_INTERNAL; } - + TRI_FreeJson(TRI_CORE_MEM_ZONE, json); TRI_FreeString(TRI_CORE_MEM_ZONE, file); @@ -1209,7 +1155,7 @@ static int CreateDatabaseDirectory (TRI_server_t* server, char* dname; char* file; int res; - + assert(server != NULL); assert(databaseName != NULL); @@ -1257,17 +1203,17 @@ static int CreateDatabaseDirectory (TRI_server_t* server, } //////////////////////////////////////////////////////////////////////////////// -/// @brief move 1.4-alpha database directories around until they are matching +/// @brief move 1.4-alpha database directories around until they are matching /// the final ArangoDB 1.4 filename layout //////////////////////////////////////////////////////////////////////////////// -static int Move14AlphaDatabases (TRI_server_t* server) { +static int Move14AlphaDatabases (TRI_server_t* server) { regex_t re; regmatch_t matches[2]; TRI_vector_string_t files; int res; size_t i, n; - + assert(server != NULL); res = regcomp(&re, "^database-([0-9][0-9]*)$", REG_EXTENDED); @@ -1299,7 +1245,7 @@ static int Move14AlphaDatabases (TRI_server_t* server) { } // found some other format. we need to adjust the name - + oldName = TRI_Concatenate2File(server->_databasePath, name); if (oldName == NULL) { @@ -1337,7 +1283,7 @@ static int Move14AlphaDatabases (TRI_server_t* server) { res = TRI_ERROR_OUT_OF_MEMORY; break; } - + res = SaveDatabaseParameters(tick, name, false, &server->_defaults, oldName); if (res != TRI_ERROR_NO_ERROR) { @@ -1367,7 +1313,7 @@ static int Move14AlphaDatabases (TRI_server_t* server) { return res; } - + //////////////////////////////////////////////////////////////////////////////// /// @brief initialise the list of databases //////////////////////////////////////////////////////////////////////////////// @@ -1376,9 +1322,9 @@ static int InitDatabases (TRI_server_t* server, bool isUpgrade) { TRI_vector_string_t names; int res; - + assert(server != NULL); - + TRI_InitVectorString(&names, TRI_CORE_MEM_ZONE); res = GetDatabases(server, &names); @@ -1423,7 +1369,7 @@ static int InitDatabases (TRI_server_t* server, } } } - + TRI_DestroyVectorString(&names); return res; @@ -1452,7 +1398,7 @@ static void DatabaseManager (void* data) { // check if we have to drop some database database = NULL; - TRI_ReadLockReadWriteLock(&server->_databasesLock); + TRI_ReadLockReadWriteLock(&server->_databasesLock); n = server->_droppedDatabases._length; @@ -1462,13 +1408,13 @@ static void DatabaseManager (void* data) { if (! TRI_CanRemoveVocBase(vocbase)) { continue; } - + // found a database to delete database = TRI_RemoveVectorPointer(&server->_droppedDatabases, i); break; } - - TRI_ReadUnlockReadWriteLock(&server->_databasesLock); + + TRI_ReadUnlockReadWriteLock(&server->_databasesLock); if (database != NULL) { // remember the database path @@ -1494,7 +1440,7 @@ static void DatabaseManager (void* data) { TRI_Free(TRI_CORE_MEM_ZONE, path); } } - + // remove dev-apps directory for database if (strlen(server->_devAppPath) > 0) { path = TRI_Concatenate3File(server->_devAppPath, "databases", database->_name); @@ -1538,19 +1484,10 @@ static void DatabaseManager (void* data) { } } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- constructors / destructors // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief create a server instance //////////////////////////////////////////////////////////////////////////////// @@ -1558,7 +1495,7 @@ static void DatabaseManager (void* data) { TRI_server_t* TRI_CreateServer () { TRI_server_t* server; - server = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_server_t), false); + server = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_server_t), true); return server; } @@ -1581,9 +1518,9 @@ int TRI_InitServer (TRI_server_t* server, // c++ object, may be null in console mode server->_applicationEndpointServer = applicationEndpointServer; - + // ............................................................................. - // set up paths and filenames + // set up paths and filenames // ............................................................................. server->_basePath = TRI_DuplicateStringZ(TRI_CORE_MEM_ZONE, basePath); @@ -1591,7 +1528,7 @@ int TRI_InitServer (TRI_server_t* server, if (server->_basePath == NULL) { return TRI_ERROR_OUT_OF_MEMORY; } - + server->_databasePath = TRI_Concatenate2File(server->_basePath, "databases"); if (server->_databasePath == NULL) { @@ -1599,7 +1536,7 @@ int TRI_InitServer (TRI_server_t* server, return TRI_ERROR_OUT_OF_MEMORY; } - + server->_lockFilename = TRI_Concatenate2File(server->_basePath, "LOCK"); if (server->_lockFilename == NULL) { @@ -1608,7 +1545,7 @@ int TRI_InitServer (TRI_server_t* server, return TRI_ERROR_OUT_OF_MEMORY; } - + server->_shutdownFilename = TRI_Concatenate2File(server->_basePath, "SHUTDOWN"); if (server->_shutdownFilename == NULL) { @@ -1618,7 +1555,7 @@ int TRI_InitServer (TRI_server_t* server, return TRI_ERROR_OUT_OF_MEMORY; } - + server->_serverIdFilename = TRI_Concatenate2File(server->_basePath, "SERVER"); if (server->_serverIdFilename == NULL) { @@ -1631,7 +1568,7 @@ int TRI_InitServer (TRI_server_t* server, } server->_appPath = TRI_DuplicateStringZ(TRI_CORE_MEM_ZONE, appPath); - + if (server->_appPath == NULL) { TRI_Free(TRI_CORE_MEM_ZONE, server->_serverIdFilename); TRI_Free(TRI_CORE_MEM_ZONE, server->_shutdownFilename); @@ -1643,7 +1580,7 @@ int TRI_InitServer (TRI_server_t* server, } server->_devAppPath = TRI_DuplicateStringZ(TRI_CORE_MEM_ZONE, devAppPath); - + if (server->_devAppPath == NULL) { TRI_Free(TRI_CORE_MEM_ZONE, server->_appPath); TRI_Free(TRI_CORE_MEM_ZONE, server->_serverIdFilename); @@ -1654,38 +1591,39 @@ int TRI_InitServer (TRI_server_t* server, return TRI_ERROR_OUT_OF_MEMORY; } - - + + // ............................................................................. // server defaults // ............................................................................. memcpy(&server->_defaults, defaults, sizeof(TRI_vocbase_defaults_t)); - + // ............................................................................. // database hashes and vectors // ............................................................................. - + TRI_InitAssociativePointer(&server->_databases, TRI_UNKNOWN_MEM_ZONE, &TRI_HashStringKeyAssociativePointer, HashElementDatabaseName, EqualKeyDatabaseName, NULL); - + TRI_InitReadWriteLock(&server->_databasesLock); TRI_InitVectorPointer2(&server->_droppedDatabases, TRI_UNKNOWN_MEM_ZONE, 64); - + TRI_InitMutex(&server->_createLock); - - + + server->_disableReplicationLoggers = disableLoggers; server->_disableReplicationAppliers = disableAppliers; server->_wasShutdownCleanly = false; - + server->_initialised = true; + return TRI_ERROR_NO_ERROR; } @@ -1694,20 +1632,22 @@ int TRI_InitServer (TRI_server_t* server, //////////////////////////////////////////////////////////////////////////////// void TRI_DestroyServer (TRI_server_t* server) { - CloseDatabases(server); + if (server->_initialised) { + CloseDatabases(server); - TRI_DestroyMutex(&server->_createLock); - TRI_DestroyVectorPointer(&server->_droppedDatabases); - TRI_DestroyReadWriteLock(&server->_databasesLock); - TRI_DestroyAssociativePointer(&server->_databases); + TRI_DestroyMutex(&server->_createLock); + TRI_DestroyVectorPointer(&server->_droppedDatabases); + TRI_DestroyReadWriteLock(&server->_databasesLock); + TRI_DestroyAssociativePointer(&server->_databases); - TRI_Free(TRI_CORE_MEM_ZONE, server->_devAppPath); - TRI_Free(TRI_CORE_MEM_ZONE, server->_appPath); - TRI_Free(TRI_CORE_MEM_ZONE, server->_serverIdFilename); - TRI_Free(TRI_CORE_MEM_ZONE, server->_shutdownFilename); - TRI_Free(TRI_CORE_MEM_ZONE, server->_lockFilename); - TRI_Free(TRI_CORE_MEM_ZONE, server->_databasePath); - TRI_Free(TRI_CORE_MEM_ZONE, server->_basePath); + TRI_Free(TRI_CORE_MEM_ZONE, server->_devAppPath); + TRI_Free(TRI_CORE_MEM_ZONE, server->_appPath); + TRI_Free(TRI_CORE_MEM_ZONE, server->_serverIdFilename); + TRI_Free(TRI_CORE_MEM_ZONE, server->_shutdownFilename); + TRI_Free(TRI_CORE_MEM_ZONE, server->_lockFilename); + TRI_Free(TRI_CORE_MEM_ZONE, server->_databasePath); + TRI_Free(TRI_CORE_MEM_ZONE, server->_basePath); + } } //////////////////////////////////////////////////////////////////////////////// @@ -1723,14 +1663,13 @@ void TRI_FreeServer (TRI_server_t* server) { /// @brief initialise globals //////////////////////////////////////////////////////////////////////////////// -void TRI_InitialiseServer () { +void TRI_InitServerGlobals () { ServerIdentifier = TRI_UInt16Random(); - PageSize = (size_t) getpagesize(); - + PageSize = (size_t) getpagesize(); + memset(&ServerId, 0, sizeof(TRI_server_id_t)); TRI_InitSpin(&TickLock); - TRI_GlobalInitStatementListAql(); } @@ -1738,24 +1677,15 @@ void TRI_InitialiseServer () { /// @brief de-initialise globals //////////////////////////////////////////////////////////////////////////////// -void TRI_ShutdownServer () { +void TRI_FreeServerGlobals () { TRI_GlobalFreeStatementListAql(); TRI_DestroySpin(&TickLock); } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- public functions // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief get the global server id //////////////////////////////////////////////////////////////////////////////// @@ -1773,20 +1703,20 @@ int TRI_StartServer (TRI_server_t* server, int res; if (! TRI_IsDirectory(server->_basePath)) { - LOG_ERROR("database path '%s' is not a directory", + LOG_ERROR("database path '%s' is not a directory", server->_basePath); return TRI_ERROR_ARANGO_DATADIR_INVALID; } - + if (! TRI_IsWritable(server->_basePath)) { // database directory is not writable for the current user... bad luck - LOG_ERROR("database directory '%s' is not writable for current user", + LOG_ERROR("database directory '%s' is not writable for current user", server->_basePath); return TRI_ERROR_ARANGO_DATADIR_NOT_WRITABLE; } - + // ............................................................................. // check that the database is not locked and lock it // ............................................................................. @@ -1794,7 +1724,7 @@ int TRI_StartServer (TRI_server_t* server, res = TRI_VerifyLockFile(server->_lockFilename); if (res == TRI_ERROR_NO_ERROR) { - LOG_ERROR("database is locked, please check the lock file '%s'", + LOG_ERROR("database is locked, please check the lock file '%s'", server->_lockFilename); return TRI_ERROR_ARANGO_DATADIR_LOCKED; @@ -1808,7 +1738,7 @@ int TRI_StartServer (TRI_server_t* server, if (res != TRI_ERROR_NO_ERROR) { LOG_ERROR("cannot lock the database directory, please check the lock file '%s': %s", - server->_lockFilename, + server->_lockFilename, TRI_errno_string(res)); return TRI_ERROR_ARANGO_DATADIR_UNLOCKABLE; @@ -1827,8 +1757,8 @@ int TRI_StartServer (TRI_server_t* server, return res; } - - + + // ............................................................................. // read information from last shutdown // ............................................................................. @@ -1840,15 +1770,15 @@ int TRI_StartServer (TRI_server_t* server, res = ReadShutdownInfo(server->_shutdownFilename); if (res == TRI_ERROR_INTERNAL) { - LOG_ERROR("cannot read shutdown information from file '%s'", + LOG_ERROR("cannot read shutdown information from file '%s'", server->_shutdownFilename); return TRI_ERROR_INTERNAL; } server->_wasShutdownCleanly = (res == TRI_ERROR_NO_ERROR); - - + + // ............................................................................. // verify existence of "databases" subdirectory // ............................................................................. @@ -1857,7 +1787,7 @@ int TRI_StartServer (TRI_server_t* server, res = TRI_CreateDirectory(server->_databasePath); if (res != TRI_ERROR_NO_ERROR) { - LOG_ERROR("unable to create database directory '%s': %s", + LOG_ERROR("unable to create database directory '%s': %s", server->_databasePath, TRI_errno_string(res)); @@ -1866,35 +1796,35 @@ int TRI_StartServer (TRI_server_t* server, } if (! TRI_IsWritable(server->_databasePath)) { - LOG_ERROR("database drectory '%s' is not writable", + LOG_ERROR("database drectory '%s' is not writable", server->_databasePath); return TRI_ERROR_ARANGO_DATADIR_NOT_WRITABLE; } - + // ............................................................................. - // perform an eventual migration of the databases. + // perform an eventual migration of the databases. // ............................................................................. res = InitDatabases(server, isUpgrade); if (res != TRI_ERROR_NO_ERROR) { - LOG_ERROR("unable to initialise databases: %s", + LOG_ERROR("unable to initialise databases: %s", TRI_errno_string(res)); return res; } - + // ............................................................................. // create shared application directories // ............................................................................. - if (server->_appPath != NULL && + if (server->_appPath != NULL && strlen(server->_appPath) > 0 && ! TRI_IsDirectory(server->_appPath)) { if (! isUpgrade) { LOG_ERROR("specified --javascript.app-path directory '%s' does not exist. " - "Please start again with --upgrade option to create it.", + "Please start again with --upgrade option to create it.", server->_appPath); return TRI_ERROR_BAD_PARAMETER; } @@ -1902,19 +1832,19 @@ int TRI_StartServer (TRI_server_t* server, res = TRI_CreateDirectory(server->_appPath); if (res != TRI_ERROR_NO_ERROR) { - LOG_ERROR("unable to create --javascript.app-path directory '%s': %s", - server->_appPath, + LOG_ERROR("unable to create --javascript.app-path directory '%s': %s", + server->_appPath, TRI_errno_string(res)); return res; } } - - if (server->_devAppPath != NULL && + + if (server->_devAppPath != NULL && strlen(server->_devAppPath) > 0 && ! TRI_IsDirectory(server->_devAppPath)) { if (! isUpgrade) { LOG_ERROR("specified --javascript.dev-app-path directory '%s' does not exist. " - "Please start again with --upgrade option to create it.", + "Please start again with --upgrade option to create it.", server->_devAppPath); return TRI_ERROR_BAD_PARAMETER; } @@ -1922,14 +1852,14 @@ int TRI_StartServer (TRI_server_t* server, res = TRI_CreateDirectory(server->_devAppPath); if (res != TRI_ERROR_NO_ERROR) { - LOG_ERROR("unable to create --javascript.dev-app-path directory '%s': %s", - server->_devAppPath, + LOG_ERROR("unable to create --javascript.dev-app-path directory '%s': %s", + server->_devAppPath, TRI_errno_string(res)); return res; } } - - // create subdirectories if not yet present + + // create subdirectories if not yet present res = CreateBaseApplicationDirectory(server->_appPath, "databases"); if (res == TRI_ERROR_NO_ERROR) { @@ -1943,9 +1873,9 @@ int TRI_StartServer (TRI_server_t* server, if (res == TRI_ERROR_NO_ERROR) { res = CreateBaseApplicationDirectory(server->_devAppPath, "system"); } - + if (res != TRI_ERROR_NO_ERROR) { - LOG_ERROR("unable to initialise databases: %s", + LOG_ERROR("unable to initialise databases: %s", TRI_errno_string(res)); return res; } @@ -1954,7 +1884,7 @@ int TRI_StartServer (TRI_server_t* server, // ............................................................................. // open and scan all databases // ............................................................................. - + // scan all databases res = OpenDatabases(server); @@ -1965,14 +1895,14 @@ int TRI_StartServer (TRI_server_t* server, return res; } - LOG_TRACE("last tick value found: %llu", (unsigned long long) GetTick()); + LOG_TRACE("last tick value found: %llu", (unsigned long long) GetTick()); // now remove SHUTDOWN file if it was present if (server->_wasShutdownCleanly) { res = RemoveShutdownInfo(server); if (res != TRI_ERROR_NO_ERROR) { - LOG_ERROR("unable to remove shutdown information file '%s': %s", + LOG_ERROR("unable to remove shutdown information file '%s': %s", server->_shutdownFilename, TRI_errno_string(res)); @@ -1985,7 +1915,7 @@ int TRI_StartServer (TRI_server_t* server, TRI_LockMutex(&server->_createLock); server->_shutdown = false; TRI_UnlockMutex(&server->_createLock); - + // start dbm thread TRI_InitThread(&server->_databaseManager); TRI_StartThread(&server->_databaseManager, "[databases]", DatabaseManager, server); @@ -2021,7 +1951,7 @@ int TRI_StopServer (TRI_server_t* server) { } //////////////////////////////////////////////////////////////////////////////// -/// @brief create a new database +/// @brief create a new database //////////////////////////////////////////////////////////////////////////////// int TRI_CreateDatabaseServer (TRI_server_t* server, @@ -2034,7 +1964,7 @@ int TRI_CreateDatabaseServer (TRI_server_t* server, char* path; int res; size_t i, n; - + if (! TRI_IsAllowedNameVocBase(false, name)) { return TRI_ERROR_ARANGO_DATABASE_NAME_INVALID; } @@ -2073,8 +2003,8 @@ int TRI_CreateDatabaseServer (TRI_server_t* server, path = TRI_Concatenate2File(server->_databasePath, file); TRI_FreeString(TRI_CORE_MEM_ZONE, file); - - LOG_INFO("creating database '%s', directory '%s'", + + LOG_INFO("creating database '%s', directory '%s'", name, path); @@ -2092,7 +2022,7 @@ int TRI_CreateDatabaseServer (TRI_server_t* server, res = TRI_ERROR_INTERNAL; } - LOG_ERROR("could not create database '%s': %s", + LOG_ERROR("could not create database '%s': %s", name, TRI_errno_string(res)); @@ -2100,8 +2030,8 @@ int TRI_CreateDatabaseServer (TRI_server_t* server, } assert(vocbase != NULL); - - // create application directories + + // create application directories CreateApplicationDirectory(vocbase->_name, server->_appPath); CreateApplicationDirectory(vocbase->_name, server->_devAppPath); @@ -2112,7 +2042,7 @@ int TRI_CreateDatabaseServer (TRI_server_t* server, TRI_WriteLockReadWriteLock(&server->_databasesLock); TRI_InsertKeyAssociativePointer(&server->_databases, vocbase->_name, vocbase, false); TRI_WriteUnlockReadWriteLock(&server->_databasesLock); - + TRI_UnlockMutex(&server->_createLock); *database = vocbase; @@ -2133,7 +2063,7 @@ int TRI_DropDatabaseServer (TRI_server_t* server, // prevent deletion of system database return TRI_ERROR_FORBIDDEN; } - + TRI_WriteLockReadWriteLock(&server->_databasesLock); if (TRI_ReserveVectorPointer(&server->_droppedDatabases, 1) != TRI_ERROR_NO_ERROR) { @@ -2146,19 +2076,19 @@ int TRI_DropDatabaseServer (TRI_server_t* server, vocbase = TRI_RemoveKeyAssociativePointer(&server->_databases, name); if (vocbase == NULL) { - // not found + // not found res = TRI_ERROR_ARANGO_DATABASE_NOT_FOUND; } else { // mark as deleted if (TRI_DropVocBase(vocbase)) { - - LOG_INFO("dropping database '%s', directory '%s'", + + LOG_INFO("dropping database '%s', directory '%s'", vocbase->_name, vocbase->_path); - res = SaveDatabaseParameters(vocbase->_id, - vocbase->_name, + res = SaveDatabaseParameters(vocbase->_id, + vocbase->_name, true, &vocbase->_settings, vocbase->_path); @@ -2213,7 +2143,7 @@ void TRI_ReleaseDatabaseServer (TRI_server_t* server, } //////////////////////////////////////////////////////////////////////////////// -/// @brief return the list of all databases a user can see +/// @brief return the list of all databases a user can see //////////////////////////////////////////////////////////////////////////////// int TRI_GetUserDatabasesServer (TRI_server_t* server, @@ -2303,7 +2233,7 @@ int TRI_GetDatabaseNamesServer (TRI_server_t* server, } } TRI_ReadUnlockReadWriteLock(&server->_databasesLock); - + SortDatabaseNames(names); return res; @@ -2319,19 +2249,10 @@ void TRI_GetDatabaseDefaultsServer (TRI_server_t* server, memcpy(target, &server->_defaults, sizeof(TRI_vocbase_defaults_t)); } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- tick functions // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief create a new tick //////////////////////////////////////////////////////////////////////////////// @@ -2380,26 +2301,17 @@ TRI_voc_tick_t TRI_CurrentTickServer () { return tick; } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- other functions // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief msyncs a memory block between begin (incl) and end (excl) //////////////////////////////////////////////////////////////////////////////// -bool TRI_MSync (int fd, - void* mmHandle, - char const* begin, +bool TRI_MSync (int fd, + void* mmHandle, + char const* begin, char const* end) { uintptr_t p = (intptr_t) begin; uintptr_t q = (intptr_t) end; @@ -2420,10 +2332,6 @@ bool TRI_MSync (int fd, return true; } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // Local Variables: // mode: outline-minor // outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}" diff --git a/arangod/VocBase/server.h b/arangod/VocBase/server.h index bcd73cbc11..27bce3f740 100644 --- a/arangod/VocBase/server.h +++ b/arangod/VocBase/server.h @@ -44,11 +44,6 @@ extern "C" { // --SECTION-- public types // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief server structure //////////////////////////////////////////////////////////////////////////////// @@ -70,7 +65,7 @@ typedef struct TRI_server_s { char* _lockFilename; char* _shutdownFilename; char* _serverIdFilename; - + char* _appPath; char* _devAppPath; @@ -78,6 +73,8 @@ typedef struct TRI_server_s { bool _disableReplicationAppliers; bool _wasShutdownCleanly; + + bool _initialised; } TRI_server_t; @@ -87,19 +84,10 @@ TRI_server_t; extern size_t PageSize; -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- constructors / destructors // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief create a server instance //////////////////////////////////////////////////////////////////////////////// @@ -112,9 +100,9 @@ TRI_server_t* TRI_CreateServer (void); int TRI_InitServer (TRI_server_t* server, void*, - char const*, - char const*, - char const*, + char const*, + char const*, + char const*, TRI_vocbase_defaults_t const*, bool, bool); @@ -135,27 +123,18 @@ void TRI_FreeServer (TRI_server_t*); /// @brief initialise globals //////////////////////////////////////////////////////////////////////////////// -void TRI_InitialiseServer (void); +void TRI_InitServerGlobals (void); //////////////////////////////////////////////////////////////////////////////// /// @brief de-initialise globals //////////////////////////////////////////////////////////////////////////////// -void TRI_ShutdownServer (void); - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// +void TRI_FreeServerGlobals (void); // ----------------------------------------------------------------------------- // --SECTION-- public functions // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief get the global server id //////////////////////////////////////////////////////////////////////////////// @@ -176,7 +155,7 @@ int TRI_StartServer (TRI_server_t*, int TRI_StopServer (TRI_server_t*); //////////////////////////////////////////////////////////////////////////////// -/// @brief create a new database +/// @brief create a new database //////////////////////////////////////////////////////////////////////////////// int TRI_CreateDatabaseServer (TRI_server_t*, @@ -230,19 +209,10 @@ int TRI_GetDatabaseNamesServer (TRI_server_t*, void TRI_GetDatabaseDefaultsServer (TRI_server_t*, TRI_vocbase_defaults_t*); -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- tick functions // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief create a new tick //////////////////////////////////////////////////////////////////////////////// @@ -267,19 +237,10 @@ void TRI_FastUpdateTickServer (TRI_voc_tick_t); TRI_voc_tick_t TRI_CurrentTickServer (void); -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- other functions // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup VocBase -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief msyncs a memory block between begin (incl) and end (excl) //////////////////////////////////////////////////////////////////////////////// @@ -289,10 +250,6 @@ bool TRI_MSync (int, char const*, char const*); -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - #ifdef __cplusplus } #endif diff --git a/lib/BasicsC/locks-posix.c b/lib/BasicsC/locks-posix.c index e50d880ede..4ee9e2fa97 100644 --- a/lib/BasicsC/locks-posix.c +++ b/lib/BasicsC/locks-posix.c @@ -39,11 +39,6 @@ // --SECTION-- private macros // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup Threading -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief busy wait delay (in microseconds) /// @@ -54,10 +49,6 @@ #define BUSY_LOCK_DELAY (10 * 1000) -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- MUTEX // ----------------------------------------------------------------------------- @@ -66,11 +57,6 @@ // --SECTION-- constructors and destructors // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup Threading -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief initialises a new mutex //////////////////////////////////////////////////////////////////////////////// @@ -87,19 +73,10 @@ int TRI_DestroyMutex (TRI_mutex_t* mutex) { return pthread_mutex_destroy(mutex); } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- public functions // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup Threading -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief locks mutex //////////////////////////////////////////////////////////////////////////////// @@ -131,10 +108,6 @@ void TRI_UnlockMutex (TRI_mutex_t* mutex) { } } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- SPIN // ----------------------------------------------------------------------------- @@ -145,11 +118,6 @@ void TRI_UnlockMutex (TRI_mutex_t* mutex) { // --SECTION-- constructors and destructors // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup Threading -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief initialises a new spin-lock //////////////////////////////////////////////////////////////////////////////// @@ -166,19 +134,10 @@ void TRI_DestroySpin (TRI_spin_t* spinLock) { pthread_spin_destroy(spinLock); } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- public functions // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup Threading -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief locks spin-lock //////////////////////////////////////////////////////////////////////////////// @@ -210,10 +169,6 @@ void TRI_UnlockSpin (TRI_spin_t* spinLock) { } } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - #endif // ----------------------------------------------------------------------------- @@ -224,11 +179,6 @@ void TRI_UnlockSpin (TRI_spin_t* spinLock) { // --SECTION-- constructors and destructors // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup Threading -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief initialises a new read-write lock //////////////////////////////////////////////////////////////////////////////// @@ -245,19 +195,10 @@ void TRI_DestroyReadWriteLock (TRI_read_write_lock_t* lock) { pthread_rwlock_destroy(lock); } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- public functions // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup Threading -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief tries to read lock read-write lock //////////////////////////////////////////////////////////////////////////////// @@ -365,10 +306,6 @@ void TRI_WriteUnlockReadWriteLock (TRI_read_write_lock_t* lock) { } } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- CONDITION VARIABLE // ----------------------------------------------------------------------------- @@ -377,11 +314,6 @@ void TRI_WriteUnlockReadWriteLock (TRI_read_write_lock_t* lock) { // --SECTION-- constructors and destructors // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup Threading -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief initialises a new condition variable //////////////////////////////////////////////////////////////////////////////// @@ -408,19 +340,10 @@ void TRI_DestroyCondition (TRI_condition_t* cond) { TRI_Free(TRI_CORE_MEM_ZONE, cond->_mutex); } -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- public functions // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup Threading -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief signals a condition variable /// @@ -541,7 +464,7 @@ void TRI_UnlockCondition (TRI_condition_t* cond) { // Note that for the MAC OS we use the 'barrier' functions which ensure that // read/write operations on the scalars are executed in order. According to the // available documentation, the GCC variants of these COMPARE & SWAP operations -// are implemented with a memory barrier. The MS Windows variants of these +// are implemented with a memory barrier. The MS Windows variants of these // operations (according to the documentation on MS site) also provide a full // memory barrier. // ----------------------------------------------------------------------------- @@ -662,10 +585,6 @@ bool TRI_ComparePointer(void* volatile* theValue, void* oldValue) { #endif -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - #endif // ----------------------------------------------------------------------------- diff --git a/lib/BasicsC/locks-posix.h b/lib/BasicsC/locks-posix.h index 3e9ad7b33e..4538337e60 100644 --- a/lib/BasicsC/locks-posix.h +++ b/lib/BasicsC/locks-posix.h @@ -42,11 +42,6 @@ extern "C" { // --SECTION-- public types // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup Threading -/// @{ -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// /// @brief mutex type //////////////////////////////////////////////////////////////////////////////// @@ -77,10 +72,6 @@ typedef struct TRI_condition_s { } TRI_condition_t; -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - #ifdef __cplusplus } #endif