1
0
Fork 0

changed authentication procedure

This commit is contained in:
Jan Steemann 2014-03-06 16:37:00 +01:00
parent 43b0e8c692
commit b3b22a1f1c
3 changed files with 55 additions and 11 deletions

View File

@ -30,6 +30,7 @@
#include "Basics/JsonHelper.h" #include "Basics/JsonHelper.h"
#include "BasicsC/logging.h" #include "BasicsC/logging.h"
#include "Cluster/ClusterInfo.h" #include "Cluster/ClusterInfo.h"
#include "Cluster/ClusterMethods.h"
#include "Cluster/ServerJob.h" #include "Cluster/ServerJob.h"
#include "Cluster/ServerState.h" #include "Cluster/ServerState.h"
#include "Dispatcher/ApplicationDispatcher.h" #include "Dispatcher/ApplicationDispatcher.h"
@ -322,6 +323,8 @@ bool HeartbeatThread::handlePlanChangeCoordinator (uint64_t currentPlanVersion,
} }
} }
bool mustRetry = false;
if (result.successful()) { if (result.successful()) {
result.parse(prefix + "/", false); result.parse(prefix + "/", false);
@ -359,10 +362,43 @@ bool HeartbeatThread::handlePlanChangeCoordinator (uint64_t currentPlanVersion,
// create a local database object... // create a local database object...
TRI_CreateCoordinatorDatabaseServer(_server, id, name.c_str(), &defaults, &vocbase); TRI_CreateCoordinatorDatabaseServer(_server, id, name.c_str(), &defaults, &vocbase);
if (vocbase != 0 && if (vocbase != 0) {
name == TRI_VOC_SYSTEM_DATABASE) { // insert initial user(s) for system database
// insert initial user for system database
TRI_InsertInitialAuthInfo(vocbase); TRI_json_t* json = 0;
int res = usersOnCoordinator(string(vocbase->_name), json);
if (res == TRI_ERROR_NO_ERROR) {
// we were able to read from the _users collection
assert(TRI_IsListJson(json));
if (json->_value._objects._length == 0) {
// no users found, now insert initial default user
TRI_InsertInitialAuthInfo(vocbase);
}
else {
// users found in collection, insert them into cache
TRI_PopulateAuthInfo(vocbase, json);
}
}
else if (res == TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND) {
// could not access _users collection, probably the cluster
// was just created... insert initial default user
TRI_InsertInitialAuthInfo(vocbase);
}
else if (res == TRI_ERROR_INTERNAL) {
// something is wrong... probably the database server with the
// _users collection is not yet available
// delete the database again (and try again next time)
TRI_ReleaseVocBase(vocbase);
TRI_DropByIdCoordinatorDatabaseServer(_server, vocbase->_id, true);
mustRetry = true;
}
if (json != 0) {
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
}
} }
} }
else { else {
@ -382,7 +418,7 @@ bool HeartbeatThread::handlePlanChangeCoordinator (uint64_t currentPlanVersion,
vector<TRI_voc_tick_t>::const_iterator r = std::find(ids.begin(), ids.end(), *p); vector<TRI_voc_tick_t>::const_iterator r = std::find(ids.begin(), ids.end(), *p);
if (r == ids.end()) { if (r == ids.end()) {
TRI_DropByIdCoordinatorDatabaseServer(_server, *p); TRI_DropByIdCoordinatorDatabaseServer(_server, *p, false);
} }
++p; ++p;
@ -391,9 +427,15 @@ bool HeartbeatThread::handlePlanChangeCoordinator (uint64_t currentPlanVersion,
TRI_Free(TRI_UNKNOWN_MEM_ZONE, localIds); TRI_Free(TRI_UNKNOWN_MEM_ZONE, localIds);
} }
} }
else {
mustRetry = true;
}
if (mustRetry) {
return false;
}
remotePlanVersion = currentPlanVersion; remotePlanVersion = currentPlanVersion;
return true; return true;
} }

View File

@ -2271,7 +2271,8 @@ TRI_voc_tick_t* TRI_GetIdsCoordinatorDatabaseServer (TRI_server_t* server) {
#ifdef TRI_ENABLE_CLUSTER #ifdef TRI_ENABLE_CLUSTER
int TRI_DropByIdCoordinatorDatabaseServer (TRI_server_t* server, int TRI_DropByIdCoordinatorDatabaseServer (TRI_server_t* server,
TRI_voc_tick_t id) { TRI_voc_tick_t id,
bool force) {
size_t i, n; size_t i, n;
int res; int res;
@ -2292,7 +2293,7 @@ int TRI_DropByIdCoordinatorDatabaseServer (TRI_server_t* server,
if (vocbase != NULL && if (vocbase != NULL &&
vocbase->_id == id && vocbase->_id == id &&
! TRI_EqualString(vocbase->_name, TRI_VOC_SYSTEM_DATABASE)) { (force || ! TRI_EqualString(vocbase->_name, TRI_VOC_SYSTEM_DATABASE))) {
TRI_RemoveKeyAssociativePointer(&server->_coordinatorDatabases, vocbase->_name); TRI_RemoveKeyAssociativePointer(&server->_coordinatorDatabases, vocbase->_name);
if (TRI_DropVocBase(vocbase)) { if (TRI_DropVocBase(vocbase)) {

View File

@ -195,7 +195,8 @@ TRI_voc_tick_t* TRI_GetIdsCoordinatorDatabaseServer (TRI_server_t*);
#ifdef TRI_ENABLE_CLUSTER #ifdef TRI_ENABLE_CLUSTER
int TRI_DropByIdCoordinatorDatabaseServer (TRI_server_t*, int TRI_DropByIdCoordinatorDatabaseServer (TRI_server_t*,
TRI_voc_tick_t); TRI_voc_tick_t,
bool);
#endif #endif
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////