mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'devel' of github.com:triAGENS/ArangoDB into devel
This commit is contained in:
commit
4797634b14
|
@ -105,6 +105,8 @@ HeartbeatThread::~HeartbeatThread () {
|
|||
void HeartbeatThread::run () {
|
||||
LOG_TRACE("starting heartbeat thread");
|
||||
|
||||
uint64_t oldUserVersion = 0;
|
||||
|
||||
// convert timeout to seconds
|
||||
const double interval = (double) _interval / 1000.0 / 1000.0;
|
||||
|
||||
|
@ -170,6 +172,72 @@ void HeartbeatThread::run () {
|
|||
}
|
||||
}
|
||||
|
||||
result.clear();
|
||||
|
||||
result = _agency.getValues("Sync/UserVersion", false);
|
||||
if (result.successful()) {
|
||||
result.parse("", false);
|
||||
std::map<std::string, AgencyCommResultEntry>::iterator it
|
||||
= result._values.begin();
|
||||
if (it != result._values.end()) {
|
||||
// there is a UserVersion
|
||||
uint64_t userVersion = triagens::basics::JsonHelper::stringUInt64((*it).second._json);
|
||||
if (userVersion != oldUserVersion) {
|
||||
// reload user cache for all databases
|
||||
vector<DatabaseID> dbs
|
||||
= ClusterInfo::instance()->listDatabases(true);
|
||||
vector<DatabaseID>::iterator i;
|
||||
bool allOK = true;
|
||||
for (i = dbs.begin(); i != dbs.end(); i++) {
|
||||
TRI_vocbase_t* vocbase = TRI_UseCoordinatorDatabaseServer(_server,
|
||||
i->c_str());
|
||||
|
||||
if (vocbase != NULL) {
|
||||
LOG_INFO("Reloading users for database %s.",vocbase->_name);
|
||||
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
|
||||
TRI_InsertInitialAuthInfo(vocbase);
|
||||
allOK = false;
|
||||
// we will not set oldUserVersion such that we will try this
|
||||
// very same exercise again in the next heartbeat
|
||||
}
|
||||
|
||||
if (json != 0) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
}
|
||||
TRI_ReleaseVocBase(vocbase);
|
||||
}
|
||||
}
|
||||
if (allOK) {
|
||||
oldUserVersion = userVersion;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// ! isCoordinator
|
||||
|
@ -504,7 +572,7 @@ bool HeartbeatThread::handleStateChange (AgencyCommResult& result,
|
|||
|
||||
bool HeartbeatThread::sendState () {
|
||||
const AgencyCommResult result = _agency.sendServerState(
|
||||
3.0 * static_cast<double>(_interval) / 1000.0 / 1000.0);
|
||||
8.0 * static_cast<double>(_interval) / 1000.0 / 1000.0);
|
||||
|
||||
if (result.successful()) {
|
||||
_numFails = 0;
|
||||
|
|
|
@ -32,6 +32,7 @@ var arangodb = require("org/arangodb");
|
|||
var actions = require("org/arangodb/actions");
|
||||
var internal = require("internal");
|
||||
var console = require("console");
|
||||
var users = require("org/arangodb/users");
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private functions
|
||||
|
@ -155,7 +156,7 @@ actions.defineHttp({
|
|||
prefix : false,
|
||||
|
||||
callback : function (req, res) {
|
||||
internal.reloadAuth();
|
||||
users.reload();
|
||||
actions.resultOk(req, res, actions.HTTP_OK);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -555,7 +555,8 @@ Planner.prototype.makePlan = function() {
|
|||
"Problems" : {},
|
||||
"LatestID" : '"1"',
|
||||
"Commands" : {},
|
||||
"HeartbeatIntervalMs": '1000' };
|
||||
"HeartbeatIntervalMs": '1000',
|
||||
"UserVersion" : '"1"' };
|
||||
tmp = prefix.Sync.Commands;
|
||||
for (i = 0; i < DBservers; i++) {
|
||||
tmp[DBservers[i].id] = '"SERVE"';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true */
|
||||
/*global require, exports */
|
||||
/*global require, exports, ArangoAgency */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief User management
|
||||
|
@ -58,6 +58,29 @@ for (i in base) {
|
|||
|
||||
exports.reload = function () {
|
||||
internal.reloadAuth();
|
||||
if (require("org/arangodb/cluster").isCoordinator()) {
|
||||
// Tell the agency about this reload, such that all other coordinators
|
||||
// reload as well. This is important because most calls to this
|
||||
// function here come from actual changes in the collection _users.
|
||||
var UserVersion;
|
||||
var done = false;
|
||||
while (! done) {
|
||||
try {
|
||||
UserVersion = ArangoAgency.get("Sync/UserVersion")["Sync/UserVersion"];
|
||||
// This is now a string!
|
||||
}
|
||||
catch (err) {
|
||||
break;
|
||||
}
|
||||
try {
|
||||
done = ArangoAgency.cas("Sync/UserVersion",UserVersion,
|
||||
(parseInt(UserVersion,10)+1).toString());
|
||||
}
|
||||
catch (err2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -62,16 +62,22 @@ int TRI_closesocket (TRI_socket_t s) {
|
|||
}
|
||||
else if (s.fileHandle != TRI_INVALID_SOCKET) {
|
||||
res = shutdown(s.fileHandle, SD_SEND);
|
||||
|
||||
if (res != 0) {
|
||||
LOG_WARNING("socket shutdown error: %d", WSAGetLastError());
|
||||
// Windows complains about shutting down a socket that was not bound
|
||||
// so we will not print out the error here
|
||||
// LOG_WARNING("socket shutdown error: %d", WSAGetLastError());
|
||||
}
|
||||
else {
|
||||
char buf[256];
|
||||
int len;
|
||||
do {
|
||||
len = TRI_readsocket(s, buf, sizeof(buf), 0);
|
||||
} while (len > 0);
|
||||
}
|
||||
while (len > 0);
|
||||
|
||||
res = closesocket(s.fileHandle);
|
||||
|
||||
if (res != 0) {
|
||||
LOG_WARNING("socket close error: %d", WSAGetLastError());
|
||||
}
|
||||
|
|
|
@ -174,9 +174,9 @@ int finaliseWindows (const TRI_win_finalise_e finaliseWhat,
|
|||
// ............................................................................
|
||||
|
||||
switch (finaliseWhat) {
|
||||
|
||||
case TRI_WIN_FINAL_WSASTARTUP_FUNCTION_CALL: {
|
||||
result = WSACleanup(); // could this cause error on server termination?
|
||||
|
||||
if (result != 0) {
|
||||
// can not use LOG_ etc here since the logging may have terminated
|
||||
printf("ERROR: Could not perform a valid Winsock2 cleanup. WSACleanup returned error %d.",result);
|
||||
|
@ -236,11 +236,12 @@ int initialiseWindows (const TRI_win_initialise_e initialiseWhat,
|
|||
errorCode = WSAStartup(wVersionRequested, &wsaData);
|
||||
|
||||
if (errorCode != 0) {
|
||||
LOG_ERROR("Could not find a usuable Winsock DLL. WSAStartup returned an error.");
|
||||
LOG_ERROR("Could not find a usable Winsock DLL. WSAStartup returned an error.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
|
||||
LOG_ERROR("Could not find a usuable Winsock DLL. WSAStartup did not return version 2.2.");
|
||||
LOG_ERROR("Could not find a usable Winsock DLL. WSAStartup did not return version 2.2.");
|
||||
WSACleanup();
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -73,8 +73,11 @@ static SignalTask* localSignalTask;
|
|||
|
||||
ControlCTask (ApplicationServer* server) : Task("Control-C"), SignalTask(), _server(server), _seen(0) {
|
||||
localSignalTask = this;
|
||||
// TODO: Variable 'result' is assigned a value that is never used
|
||||
int result = SetConsoleCtrlHandler( (PHANDLER_ROUTINE)(CtrlHandler), true);
|
||||
int result = SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, true);
|
||||
|
||||
if (result == 0) {
|
||||
LOG_WARNING("unable to install control-c handler");
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -227,7 +230,7 @@ static SignalTask* localSignalTask;
|
|||
#ifdef _WIN32
|
||||
|
||||
bool CtrlHandler (DWORD eventType) {
|
||||
ControlCTask* ccTask = (ControlCTask*)(localSignalTask);
|
||||
ControlCTask* ccTask = (ControlCTask*) localSignalTask;
|
||||
string msg = ccTask->_server->getName() + " [shutting down]";
|
||||
bool shutdown = false;
|
||||
string shutdownMessage;
|
||||
|
@ -238,7 +241,6 @@ static SignalTask* localSignalTask;
|
|||
|
||||
|
||||
switch (eventType) {
|
||||
|
||||
case CTRL_BREAK_EVENT: {
|
||||
//TODO: windows does not appreciate changing the environment in this manner
|
||||
//TRI_SetProcessTitle(msg.c_str());
|
||||
|
|
Loading…
Reference in New Issue