mirror of https://gitee.com/bigwinds/arangodb
more exception handling
This commit is contained in:
parent
b759815b68
commit
234bb981aa
|
@ -1300,9 +1300,9 @@ int main (int argc, char* argv[]) {
|
|||
|
||||
BaseClient.createEndpoint();
|
||||
|
||||
if (BaseClient.endpointServer() == 0) {
|
||||
if (BaseClient.endpointServer() == nullptr) {
|
||||
cerr << "invalid value for --server.endpoint ('" << BaseClient.endpointString() << "')" << endl;
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, nullptr);
|
||||
}
|
||||
|
||||
Connection = GeneralClientConnection::factory(BaseClient.endpointServer(),
|
||||
|
@ -1311,16 +1311,16 @@ int main (int argc, char* argv[]) {
|
|||
ArangoClient::DEFAULT_RETRIES,
|
||||
BaseClient.sslProtocol());
|
||||
|
||||
if (Connection == 0) {
|
||||
if (Connection == nullptr) {
|
||||
cerr << "out of memory" << endl;
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, nullptr);
|
||||
}
|
||||
|
||||
Client = new SimpleHttpClient(Connection, BaseClient.requestTimeout(), false);
|
||||
|
||||
if (Client == 0) {
|
||||
if (Client == nullptr) {
|
||||
cerr << "out of memory" << endl;
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, nullptr);
|
||||
}
|
||||
|
||||
Client->setLocationRewriter(0, &rewriteLocation);
|
||||
|
@ -1397,22 +1397,33 @@ int main (int argc, char* argv[]) {
|
|||
string errorMsg = "";
|
||||
|
||||
int res;
|
||||
if (!clusterMode) {
|
||||
res = StartBatch("",errorMsg);
|
||||
if (res != TRI_ERROR_NO_ERROR && Force) {
|
||||
res = TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
if (res == TRI_ERROR_NO_ERROR) {
|
||||
res = RunDump(errorMsg);
|
||||
}
|
||||
try {
|
||||
if (! clusterMode) {
|
||||
res = StartBatch("",errorMsg);
|
||||
if (res != TRI_ERROR_NO_ERROR && Force) {
|
||||
res = TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
if (BatchId > 0) {
|
||||
EndBatch("");
|
||||
if (res == TRI_ERROR_NO_ERROR) {
|
||||
res = RunDump(errorMsg);
|
||||
}
|
||||
|
||||
if (BatchId > 0) {
|
||||
EndBatch("");
|
||||
}
|
||||
}
|
||||
else { // clusterMode == true
|
||||
res = RunClusterDump(errorMsg);
|
||||
}
|
||||
}
|
||||
else { // clusterMode == true
|
||||
res = RunClusterDump(errorMsg);
|
||||
catch (std::exception const& ex) {
|
||||
cerr << "caught exception " << ex.what() << endl;
|
||||
res = TRI_ERROR_INTERNAL;
|
||||
}
|
||||
catch (...) {
|
||||
cerr << "caught unknown exception" << endl;
|
||||
res = TRI_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
if (Progress) {
|
||||
|
@ -1431,13 +1442,13 @@ int main (int argc, char* argv[]) {
|
|||
ret = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (Client != 0) {
|
||||
if (Client != nullptr) {
|
||||
delete Client;
|
||||
}
|
||||
|
||||
TRIAGENS_REST_SHUTDOWN;
|
||||
|
||||
arangodumpExitFunction(ret, NULL);
|
||||
arangodumpExitFunction(ret, nullptr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -277,7 +277,7 @@ int main (int argc, char* argv[]) {
|
|||
|
||||
BaseClient.createEndpoint();
|
||||
|
||||
if (BaseClient.endpointServer() == 0) {
|
||||
if (BaseClient.endpointServer() == nullptr) {
|
||||
cerr << "invalid value for --server.endpoint ('" << BaseClient.endpointString() << "')" << endl;
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
|
||||
}
|
||||
|
@ -372,7 +372,7 @@ int main (int argc, char* argv[]) {
|
|||
cerr << "Cannot open '" << FileName << "'. Invalid file type." << endl;
|
||||
}
|
||||
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, nullptr);
|
||||
}
|
||||
|
||||
// progress
|
||||
|
@ -403,7 +403,7 @@ int main (int argc, char* argv[]) {
|
|||
|
||||
else {
|
||||
cerr << "Wrong type '" << TypeImport << "'." << endl;
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, nullptr);
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
|
@ -429,7 +429,7 @@ int main (int argc, char* argv[]) {
|
|||
|
||||
TRIAGENS_REST_SHUTDOWN;
|
||||
|
||||
arangoimpExitFunction(ret, NULL);
|
||||
arangoimpExitFunction(ret, nullptr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
#include "SimpleHttpClient/SimpleHttpClient.h"
|
||||
#include "SimpleHttpClient/SimpleHttpResult.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace triagens::basics;
|
||||
using namespace triagens::httpclient;
|
||||
|
@ -68,13 +67,13 @@ ArangoClient BaseClient;
|
|||
/// @brief the initial default connection
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
triagens::httpclient::GeneralClientConnection* Connection = 0;
|
||||
triagens::httpclient::GeneralClientConnection* Connection = nullptr;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief HTTP client
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
triagens::httpclient::SimpleHttpClient* Client = 0;
|
||||
triagens::httpclient::SimpleHttpClient* Client = nullptr;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief chunk size
|
||||
|
@ -272,7 +271,7 @@ static string GetHttpErrorMessage (SimpleHttpResult* result) {
|
|||
|
||||
TRI_json_t* json = JsonHelper::fromString(body.c_str(), body.length());
|
||||
|
||||
if (json != 0) {
|
||||
if (json != nullptr) {
|
||||
const string& errorMessage = JsonHelper::getStringValue(json, "errorMessage", "");
|
||||
const int errorNum = JsonHelper::getNumericValue<int>(json, "errorNum", 0);
|
||||
|
||||
|
@ -298,12 +297,12 @@ static string GetArangoVersion () {
|
|||
|
||||
SimpleHttpResult* response = Client->request(HttpRequest::HTTP_REQUEST_GET,
|
||||
"/_api/version",
|
||||
0,
|
||||
nullptr,
|
||||
0,
|
||||
headers);
|
||||
|
||||
if (response == 0 || ! response->isComplete()) {
|
||||
if (response != 0) {
|
||||
if (response == nullptr || ! response->isComplete()) {
|
||||
if (response != nullptr) {
|
||||
delete response;
|
||||
}
|
||||
|
||||
|
@ -358,8 +357,8 @@ static bool GetArangoIsCluster () {
|
|||
0,
|
||||
headers);
|
||||
|
||||
if (response == 0 || ! response->isComplete()) {
|
||||
if (response != 0) {
|
||||
if (response == nullptr || ! response->isComplete()) {
|
||||
if (response != nullptr) {
|
||||
delete response;
|
||||
}
|
||||
|
||||
|
@ -373,7 +372,7 @@ static bool GetArangoIsCluster () {
|
|||
TRI_json_t* json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE,
|
||||
response->getBody().c_str());
|
||||
|
||||
if (json != 0) {
|
||||
if (json != nullptr) {
|
||||
// look up "server" value
|
||||
role = JsonHelper::getStringValue(json, "role", "UNDEFINED");
|
||||
|
||||
|
@ -414,10 +413,10 @@ static int SendRestoreCollection (TRI_json_t const* json,
|
|||
body.size(),
|
||||
headers);
|
||||
|
||||
if (response == 0 || ! response->isComplete()) {
|
||||
if (response == nullptr || ! response->isComplete()) {
|
||||
errorMsg = "got invalid response from server: " + Client->getErrorMessage();
|
||||
|
||||
if (response != 0) {
|
||||
if (response != nullptr) {
|
||||
delete response;
|
||||
}
|
||||
|
||||
|
@ -453,10 +452,10 @@ static int SendRestoreIndexes (TRI_json_t const* json,
|
|||
body.size(),
|
||||
headers);
|
||||
|
||||
if (response == 0 || ! response->isComplete()) {
|
||||
if (response == nullptr || ! response->isComplete()) {
|
||||
errorMsg = "got invalid response from server: " + Client->getErrorMessage();
|
||||
|
||||
if (response != 0) {
|
||||
if (response != nullptr) {
|
||||
delete response;
|
||||
}
|
||||
|
||||
|
@ -497,10 +496,10 @@ static int SendRestoreData (string const& cname,
|
|||
headers);
|
||||
|
||||
|
||||
if (response == 0 || ! response->isComplete()) {
|
||||
if (response == nullptr || ! response->isComplete()) {
|
||||
errorMsg = "got invalid response from server: " + Client->getErrorMessage();
|
||||
|
||||
if (response != 0) {
|
||||
if (response != nullptr) {
|
||||
delete response;
|
||||
}
|
||||
|
||||
|
@ -557,7 +556,7 @@ static int ProcessInputDirectory (string& errorMsg) {
|
|||
|
||||
TRI_json_t* collections = TRI_CreateListJson(TRI_UNKNOWN_MEM_ZONE);
|
||||
|
||||
if (collections == 0) {
|
||||
if (collections == nullptr) {
|
||||
errorMsg = "out of memory";
|
||||
return TRI_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -605,7 +604,7 @@ static int ProcessInputDirectory (string& errorMsg) {
|
|||
! JsonHelper::isList(indexes)) {
|
||||
errorMsg = "could not read collection structure file '" + name + "'";
|
||||
|
||||
if (json != 0) {
|
||||
if (json != nullptr) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
}
|
||||
|
||||
|
@ -751,7 +750,7 @@ static int ProcessInputDirectory (string& errorMsg) {
|
|||
char* found = (char*) memrchr((const void*) buffer.begin(), '\n', buffer.length());
|
||||
size_t length;
|
||||
|
||||
if (found == 0) {
|
||||
if (found == nullptr) {
|
||||
// no \n found...
|
||||
if (numRead == 0) {
|
||||
// we're at the end. send the complete buffer anyway
|
||||
|
@ -891,12 +890,12 @@ int main (int argc, char* argv[]) {
|
|||
|
||||
if (InputDirectory == "" || ! TRI_IsDirectory(InputDirectory.c_str())) {
|
||||
cerr << "input directory '" << InputDirectory << "' does not exist" << endl;
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, nullptr);
|
||||
}
|
||||
|
||||
if (! ImportStructure && ! ImportData) {
|
||||
cerr << "must specify either --create-collection or --import-data" << endl;
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, nullptr);
|
||||
}
|
||||
|
||||
// .............................................................................
|
||||
|
@ -905,9 +904,9 @@ int main (int argc, char* argv[]) {
|
|||
|
||||
BaseClient.createEndpoint();
|
||||
|
||||
if (BaseClient.endpointServer() == 0) {
|
||||
if (BaseClient.endpointServer() == nullptr) {
|
||||
cerr << "invalid value for --server.endpoint ('" << BaseClient.endpointString() << "')" << endl;
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, nullptr);
|
||||
}
|
||||
|
||||
Connection = GeneralClientConnection::factory(BaseClient.endpointServer(),
|
||||
|
@ -916,16 +915,16 @@ int main (int argc, char* argv[]) {
|
|||
ArangoClient::DEFAULT_RETRIES,
|
||||
BaseClient.sslProtocol());
|
||||
|
||||
if (Connection == 0) {
|
||||
if (Connection == nullptr) {
|
||||
cerr << "out of memory" << endl;
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, nullptr);
|
||||
}
|
||||
|
||||
Client = new SimpleHttpClient(Connection, BaseClient.requestTimeout(), false);
|
||||
|
||||
if (Client == 0) {
|
||||
if (Client == nullptr) {
|
||||
cerr << "out of memory" << endl;
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, nullptr);
|
||||
}
|
||||
|
||||
Client->setLocationRewriter(0, &rewriteLocation);
|
||||
|
@ -936,7 +935,7 @@ int main (int argc, char* argv[]) {
|
|||
if (! Connection->isConnected()) {
|
||||
cerr << "Could not connect to endpoint " << BaseClient.endpointServer()->getSpecification() << endl;
|
||||
cerr << "Error message: '" << Client->getErrorMessage() << "'" << endl;
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, nullptr);
|
||||
}
|
||||
|
||||
// successfully connected
|
||||
|
@ -948,7 +947,7 @@ int main (int argc, char* argv[]) {
|
|||
|
||||
if (sscanf(versionString.c_str(), "%d.%d", &major, &minor) != 2) {
|
||||
cerr << "invalid server version '" << versionString << "'" << endl;
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, nullptr);
|
||||
}
|
||||
|
||||
if (major < 1 ||
|
||||
|
@ -957,7 +956,7 @@ int main (int argc, char* argv[]) {
|
|||
// we can connect to 1.4, 2.0 and higher only
|
||||
cerr << "got incompatible server version '" << versionString << "'" << endl;
|
||||
if (! Force) {
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -973,7 +972,20 @@ int main (int argc, char* argv[]) {
|
|||
memset(&Stats, 0, sizeof(Stats));
|
||||
|
||||
string errorMsg = "";
|
||||
int res = ProcessInputDirectory(errorMsg);
|
||||
|
||||
int res;
|
||||
try {
|
||||
res = ProcessInputDirectory(errorMsg);
|
||||
}
|
||||
catch (std::exception const& ex) {
|
||||
cerr << "caught exception " << ex.what() << endl;
|
||||
res = TRI_ERROR_INTERNAL;
|
||||
}
|
||||
catch (...) {
|
||||
cerr << "caught unknown exception" << endl;
|
||||
res = TRI_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
|
||||
if (Progress) {
|
||||
if (ImportData) {
|
||||
|
@ -992,13 +1004,13 @@ int main (int argc, char* argv[]) {
|
|||
ret = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (Client != 0) {
|
||||
if (Client != nullptr) {
|
||||
delete Client;
|
||||
}
|
||||
|
||||
TRIAGENS_REST_SHUTDOWN;
|
||||
|
||||
arangorestoreExitFunction(ret, NULL);
|
||||
arangorestoreExitFunction(ret, nullptr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ static uint64_t GcInterval = 10;
|
|||
/// @brief console object
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static V8LineEditor* Console = 0;
|
||||
static V8LineEditor* Console = nullptr;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief voice mode
|
||||
|
@ -583,13 +583,13 @@ static v8::Handle<v8::Value> ClientConnection_ConstructorCallback (v8::Arguments
|
|||
|
||||
BaseClient.createEndpoint(definition);
|
||||
|
||||
if (BaseClient.endpointServer() == 0) {
|
||||
if (BaseClient.endpointServer() == nullptr) {
|
||||
string errorMessage = "error in '" + definition + "'";
|
||||
TRI_V8_EXCEPTION_PARAMETER(scope, errorMessage.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if (BaseClient.endpointServer() == 0) {
|
||||
if (BaseClient.endpointServer() == nullptr) {
|
||||
return v8::Undefined();
|
||||
}
|
||||
|
||||
|
@ -704,7 +704,7 @@ static v8::Handle<v8::Value> ClientConnection_reconnect (v8::Arguments const& ar
|
|||
if (dbObj->Has(TRI_V8_STRING("_flushCache")) && dbObj->Get(TRI_V8_STRING("_flushCache"))->IsFunction()) {
|
||||
v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(dbObj->Get(TRI_V8_STRING("_flushCache")));
|
||||
|
||||
v8::Handle<v8::Value>* args = 0;
|
||||
v8::Handle<v8::Value>* args = nullptr;
|
||||
func->Call(dbObj, 0, args);
|
||||
}
|
||||
}
|
||||
|
@ -1363,13 +1363,13 @@ static std::string BuildPrompt () {
|
|||
#else
|
||||
|
||||
static void SignalHandler (int signal) {
|
||||
if (Console != 0) {
|
||||
if (Console != nullptr) {
|
||||
Console->close();
|
||||
Console = 0;
|
||||
Console = nullptr;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
TRI_EXIT_FUNCTION(EXIT_SUCCESS, NULL);
|
||||
TRI_EXIT_FUNCTION(EXIT_SUCCESS, nullptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1754,7 +1754,7 @@ static bool RunJsLint (v8::Handle<v8::Context> context) {
|
|||
/// @brief startup and exit functions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void* arangoshResourcesAllocated = NULL;
|
||||
void* arangoshResourcesAllocated = nullptr;
|
||||
static void arangoshEntryFunction ();
|
||||
static void arangoshExitFunction (int, void*);
|
||||
|
||||
|
@ -1796,17 +1796,15 @@ void arangoshEntryFunction() {
|
|||
}
|
||||
|
||||
TRI_Application_Exit_SetExit(arangoshExitFunction);
|
||||
|
||||
}
|
||||
|
||||
static void arangoshExitFunction(int exitCode, void* data) {
|
||||
int res = 0;
|
||||
// ...........................................................................
|
||||
// TODO: need a terminate function for windows to be called and cleanup
|
||||
// any windows specific stuff.
|
||||
// ...........................................................................
|
||||
|
||||
res = finaliseWindows(TRI_WIN_FINAL_WSASTARTUP_FUNCTION_CALL, 0);
|
||||
int res = finaliseWindows(TRI_WIN_FINAL_WSASTARTUP_FUNCTION_CALL, 0);
|
||||
|
||||
if (res != 0) {
|
||||
exit(1);
|
||||
|
@ -1862,13 +1860,13 @@ int main (int argc, char* argv[]) {
|
|||
if (useServer) {
|
||||
BaseClient.createEndpoint();
|
||||
|
||||
if (BaseClient.endpointServer() == 0) {
|
||||
if (BaseClient.endpointServer() == nullptr) {
|
||||
ostringstream s;
|
||||
s << "invalid value for --server.endpoint ('" << BaseClient.endpointString() << "')";
|
||||
|
||||
BaseClient.printErrLine(s.str());
|
||||
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, nullptr);
|
||||
}
|
||||
|
||||
ClientConnection = CreateConnection();
|
||||
|
@ -1890,7 +1888,7 @@ int main (int argc, char* argv[]) {
|
|||
|
||||
if (context.IsEmpty()) {
|
||||
BaseClient.printErrLine("cannot initialize V8 engine");
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
|
||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, nullptr);
|
||||
}
|
||||
|
||||
context->Enter();
|
||||
|
@ -2219,25 +2217,35 @@ int main (int argc, char* argv[]) {
|
|||
else {
|
||||
bool ok = false;
|
||||
|
||||
if (isExecuteScript) {
|
||||
// we have scripts to execute
|
||||
ok = RunScripts(context, ExecuteScripts, true);
|
||||
try {
|
||||
if (isExecuteScript) {
|
||||
// we have scripts to execute
|
||||
ok = RunScripts(context, ExecuteScripts, true);
|
||||
}
|
||||
else if (isExecuteString) {
|
||||
// we have string to execute
|
||||
ok = RunString(context, ExecuteString);
|
||||
}
|
||||
else if (isCheckScripts) {
|
||||
// we have scripts to syntax check
|
||||
ok = RunScripts(context, CheckScripts, false);
|
||||
}
|
||||
else if (isUnitTests) {
|
||||
// we have unit tests
|
||||
ok = RunUnitTests(context);
|
||||
}
|
||||
else if (isJsLint) {
|
||||
// we don't have unittests, but we have files to jslint
|
||||
ok = RunJsLint(context);
|
||||
}
|
||||
}
|
||||
else if (isExecuteString) {
|
||||
// we have string to execute
|
||||
ok = RunString(context, ExecuteString);
|
||||
catch (std::exception const& ex) {
|
||||
cerr << "caught exception " << ex.what() << endl;
|
||||
ok = false;
|
||||
}
|
||||
else if (isCheckScripts) {
|
||||
// we have scripts to syntax check
|
||||
ok = RunScripts(context, CheckScripts, false);
|
||||
}
|
||||
else if (isUnitTests) {
|
||||
// we have unit tests
|
||||
ok = RunUnitTests(context);
|
||||
}
|
||||
else if (isJsLint) {
|
||||
// we don't have unittests, but we have files to jslint
|
||||
ok = RunJsLint(context);
|
||||
catch (...) {
|
||||
cerr << "caught unknown exception" << endl;
|
||||
ok = false;
|
||||
}
|
||||
|
||||
if (! ok) {
|
||||
|
@ -2266,7 +2274,7 @@ int main (int argc, char* argv[]) {
|
|||
|
||||
TRIAGENS_REST_SHUTDOWN;
|
||||
|
||||
arangoshExitFunction(ret, NULL);
|
||||
arangoshExitFunction(ret, nullptr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ using namespace std;
|
|||
/// @brief name of the queue
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const string RestJobHandler::QUEUE_NAME = "STANDARD";
|
||||
const std::string RestJobHandler::QUEUE_NAME = "STANDARD";
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- constructors and destructors
|
||||
|
@ -83,7 +83,7 @@ bool RestJobHandler::isDirect () {
|
|||
/// {@inheritDoc}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
string const& RestJobHandler::queue () const {
|
||||
std::string const& RestJobHandler::queue () const {
|
||||
return QUEUE_NAME;
|
||||
}
|
||||
|
||||
|
@ -131,8 +131,8 @@ HttpHandler::status_t RestJobHandler::execute () {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RestJobHandler::putJob () {
|
||||
const vector<string>& suffix = _request->suffix();
|
||||
const string& value = suffix[0];
|
||||
std::vector<string> const& suffix = _request->suffix();
|
||||
std::string const& value = suffix[0];
|
||||
uint64_t jobId = StringUtils::uint64(value);
|
||||
|
||||
AsyncJobResult::Status status;
|
||||
|
@ -151,10 +151,10 @@ void RestJobHandler::putJob () {
|
|||
}
|
||||
|
||||
TRI_ASSERT(status == AsyncJobResult::JOB_DONE);
|
||||
TRI_ASSERT(response != 0);
|
||||
TRI_ASSERT(response != nullptr);
|
||||
|
||||
// delete our own response
|
||||
if (_response != 0) {
|
||||
if (_response != nullptr) {
|
||||
delete _response;
|
||||
}
|
||||
|
||||
|
@ -170,9 +170,9 @@ void RestJobHandler::putJob () {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RestJobHandler::putJobMethod () {
|
||||
const vector<string>& suffix = _request->suffix();
|
||||
const string& value = suffix[0];
|
||||
const string& method = suffix[1];
|
||||
std::vector<std::string> const& suffix = _request->suffix();
|
||||
std::string const& value = suffix[0];
|
||||
std::string const& method = suffix[1];
|
||||
uint64_t jobId = StringUtils::uint64(value);
|
||||
|
||||
if (method == "cancel") {
|
||||
|
@ -201,14 +201,14 @@ void RestJobHandler::putJobMethod () {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RestJobHandler::getJob () {
|
||||
const vector<string> suffix = _request->suffix();
|
||||
std::vector<std::string> const suffix = _request->suffix();
|
||||
|
||||
if (suffix.size() != 1) {
|
||||
generateError(HttpResponse::BAD, TRI_ERROR_HTTP_BAD_PARAMETER);
|
||||
return;
|
||||
}
|
||||
|
||||
const string type = suffix[0];
|
||||
std::string const type = suffix[0];
|
||||
|
||||
if (! type.empty() && type[0] >= '1' && type[0] <= '9') {
|
||||
getJobId(type);
|
||||
|
@ -259,25 +259,34 @@ void RestJobHandler::getJobType (std::string const& type) {
|
|||
count = (size_t) StringUtils::uint64(value);
|
||||
}
|
||||
|
||||
vector<AsyncJobResult::IdType> ids;
|
||||
if (type == "done") {
|
||||
ids = _jobManager->done(count);
|
||||
std::vector<AsyncJobResult::IdType> ids;
|
||||
try {
|
||||
if (type == "done") {
|
||||
ids = _jobManager->done(count);
|
||||
}
|
||||
else if (type == "pending") {
|
||||
ids = _jobManager->pending(count);
|
||||
}
|
||||
else {
|
||||
generateError(HttpResponse::BAD, TRI_ERROR_HTTP_BAD_PARAMETER);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (type == "pending") {
|
||||
ids = _jobManager->pending(count);
|
||||
}
|
||||
else {
|
||||
generateError(HttpResponse::BAD, TRI_ERROR_HTTP_BAD_PARAMETER);
|
||||
catch (...) {
|
||||
generateError(HttpResponse::SERVER_ERROR, TRI_ERROR_HTTP_SERVER_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
TRI_json_t* json = TRI_CreateList2Json(TRI_CORE_MEM_ZONE, ids.size());
|
||||
|
||||
if (json != 0) {
|
||||
for (size_t i = 0, n = ids.size(); i < n; ++i) {
|
||||
if (json != nullptr) {
|
||||
size_t const n = ids.size();
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
char* idString = TRI_StringUInt64(ids[i]);
|
||||
|
||||
TRI_PushBack3ListJson(TRI_CORE_MEM_ZONE, json, TRI_CreateStringJson(TRI_CORE_MEM_ZONE, idString));
|
||||
if (idString != nullptr) {
|
||||
TRI_PushBack3ListJson(TRI_CORE_MEM_ZONE, json, TRI_CreateStringJson(TRI_CORE_MEM_ZONE, idString));
|
||||
}
|
||||
}
|
||||
|
||||
generateResult(json);
|
||||
|
@ -293,7 +302,7 @@ void RestJobHandler::getJobType (std::string const& type) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RestJobHandler::deleteJob () {
|
||||
const vector<string> suffix = _request->suffix();
|
||||
std::vector<std::string> const suffix = _request->suffix();
|
||||
|
||||
if (suffix.size() != 1) {
|
||||
generateError(HttpResponse::BAD, TRI_ERROR_HTTP_BAD_PARAMETER);
|
||||
|
@ -330,7 +339,7 @@ void RestJobHandler::deleteJob () {
|
|||
|
||||
TRI_json_t* json = TRI_CreateArrayJson(TRI_CORE_MEM_ZONE);
|
||||
|
||||
if (json != 0) {
|
||||
if (json != nullptr) {
|
||||
TRI_Insert3ArrayJson(TRI_CORE_MEM_ZONE, json, "result", TRI_CreateBooleanJson(TRI_CORE_MEM_ZONE, true));
|
||||
|
||||
generateResult(json);
|
||||
|
|
|
@ -82,7 +82,7 @@ namespace triagens {
|
|||
/// {@inheritDoc}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
string const& queue () const;
|
||||
std::string const& queue () const;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief executes the handler
|
||||
|
|
|
@ -124,12 +124,12 @@ namespace triagens {
|
|||
handler_task_job_t const* table = this->_handlers.tableAndSize(size);
|
||||
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
if (table[i]._handler != 0) {
|
||||
if (table[i]._handler != nullptr) {
|
||||
ServerJob* job = table[i]._job;
|
||||
|
||||
if (job != 0) {
|
||||
if (job != nullptr) {
|
||||
job->abandon();
|
||||
const_cast<handler_task_job_t*>(table)[i]._job = 0;
|
||||
const_cast<handler_task_job_t*>(table)[i]._job = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -163,18 +163,18 @@ namespace triagens {
|
|||
|
||||
typename HF::GeneralResponse * response = handler->getResponse();
|
||||
|
||||
if (response == 0) {
|
||||
if (response == nullptr) {
|
||||
basics::InternalError err("no response received from handler", __FILE__, __LINE__);
|
||||
|
||||
handler->handleError(err);
|
||||
response = handler->getResponse();
|
||||
}
|
||||
|
||||
if (response != 0) {
|
||||
if (response != nullptr) {
|
||||
GeneralAsyncCommTask<S, HF, CT>* atask
|
||||
= dynamic_cast<GeneralAsyncCommTask<S, HF, CT>*>(task);
|
||||
|
||||
if (atask != 0) {
|
||||
if (atask != nullptr) {
|
||||
handler->RequestStatisticsAgent::transfer(atask);
|
||||
|
||||
atask->handleResponse(response);
|
||||
|
@ -203,7 +203,7 @@ namespace triagens {
|
|||
void jobDone (Job* ajob) {
|
||||
ServerJob* job = dynamic_cast<ServerJob*>(ajob);
|
||||
|
||||
if (job == 0) {
|
||||
if (job == nullptr) {
|
||||
LOG_WARNING("jobDone called, but Job is no ServerJob");
|
||||
return;
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ namespace triagens {
|
|||
GeneralHandler* handler = job->getHandler();
|
||||
|
||||
if (job->isDetached()) {
|
||||
if (handler != 0) {
|
||||
if (handler != nullptr) {
|
||||
_jobManager->finishAsyncJob<S, HF>(job);
|
||||
delete handler;
|
||||
}
|
||||
|
@ -231,10 +231,10 @@ namespace triagens {
|
|||
}
|
||||
|
||||
// remove the job from the mapping
|
||||
const_cast<handler_task_job_t&>(element)._job = 0;
|
||||
const_cast<handler_task_job_t&>(element)._job = nullptr;
|
||||
|
||||
// if there is no task, assume the client has died
|
||||
if (element._task == 0) {
|
||||
if (element._task == nullptr) {
|
||||
LOG_DEBUG("jobDone called, but no task is known, assume client has died");
|
||||
this->_handlers.removeKey(handler);
|
||||
|
||||
|
@ -249,7 +249,7 @@ namespace triagens {
|
|||
|
||||
GENERAL_SERVER_UNLOCK(&this->_mappingLock);
|
||||
|
||||
if (task == 0) {
|
||||
if (task == nullptr) {
|
||||
LOG_WARNING("task for handler is no GeneralAsyncCommTask, giving up");
|
||||
return;
|
||||
}
|
||||
|
@ -283,7 +283,7 @@ namespace triagens {
|
|||
|
||||
bool handleRequestAsync (GeneralHandler* handler,
|
||||
uint64_t* jobId) {
|
||||
if (_dispatcher == 0) {
|
||||
if (_dispatcher == nullptr) {
|
||||
// without a dispatcher, simply give up
|
||||
RequestStatisticsAgentSetExecuteError(handler);
|
||||
|
||||
|
@ -296,7 +296,7 @@ namespace triagens {
|
|||
// execute the handler using the dispatcher
|
||||
Job* ajob = handler->createJob(this, true);
|
||||
|
||||
if (ajob == 0) {
|
||||
if (ajob == nullptr) {
|
||||
RequestStatisticsAgentSetExecuteError(handler);
|
||||
|
||||
delete handler;
|
||||
|
@ -306,10 +306,18 @@ namespace triagens {
|
|||
}
|
||||
|
||||
ServerJob* job = dynamic_cast<ServerJob*>(ajob);
|
||||
TRI_ASSERT(job != 0);
|
||||
TRI_ASSERT(job != nullptr);
|
||||
|
||||
if (jobId != 0) {
|
||||
_jobManager->initAsyncJob<S, HF>(job, jobId);
|
||||
try {
|
||||
_jobManager->initAsyncJob<S, HF>(job, jobId);
|
||||
}
|
||||
catch (...) {
|
||||
LOG_WARNING("unable to initialize job");
|
||||
|
||||
delete handler;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (_dispatcher->addJob(job) != TRI_ERROR_NO_ERROR) {
|
||||
|
@ -344,10 +352,10 @@ namespace triagens {
|
|||
}
|
||||
|
||||
// execute the handler using the dispatcher
|
||||
else if (_dispatcher != 0) {
|
||||
else if (_dispatcher != nullptr) {
|
||||
GeneralAsyncCommTask<S, HF, CT>* atask = dynamic_cast<GeneralAsyncCommTask<S, HF, CT>*>(task);
|
||||
|
||||
if (atask == 0) {
|
||||
if (atask == nullptr) {
|
||||
RequestStatisticsAgentSetExecuteError(handler);
|
||||
|
||||
LOG_WARNING("task is indirect, but not asynchronous - this cannot work!");
|
||||
|
@ -358,7 +366,7 @@ namespace triagens {
|
|||
else {
|
||||
Job* ajob = handler->createJob(this, false);
|
||||
|
||||
if (ajob == 0) {
|
||||
if (ajob == nullptr) {
|
||||
RequestStatisticsAgentSetExecuteError(handler);
|
||||
|
||||
LOG_WARNING("task is indirect, but handler failed to create a job - this cannot work!");
|
||||
|
@ -368,7 +376,7 @@ namespace triagens {
|
|||
}
|
||||
|
||||
ServerJob* job = dynamic_cast<ServerJob*>(ajob);
|
||||
TRI_ASSERT(job != 0);
|
||||
TRI_ASSERT(job != nullptr);
|
||||
|
||||
registerJob(handler, job);
|
||||
return true;
|
||||
|
@ -421,7 +429,7 @@ namespace triagens {
|
|||
// if we do not know a job, delete handler
|
||||
Job* job = element2._job;
|
||||
|
||||
if (job == 0) {
|
||||
if (job == nullptr) {
|
||||
this->_handlers.removeKey(handler);
|
||||
|
||||
GENERAL_SERVER_UNLOCK(&this->_mappingLock);
|
||||
|
@ -432,7 +440,7 @@ namespace triagens {
|
|||
|
||||
// initiate shutdown if a job is known
|
||||
else {
|
||||
const_cast<handler_task_job_t&>(element2)._task = 0;
|
||||
const_cast<handler_task_job_t&>(element2)._task = nullptr;
|
||||
job->beginShutdown();
|
||||
|
||||
GENERAL_SERVER_UNLOCK(&this->_mappingLock);
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace triagens {
|
|||
|
||||
AsyncCallbackContext (std::string const& coordHeader)
|
||||
: _coordHeader(coordHeader),
|
||||
_response(0) {
|
||||
_response(nullptr) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -68,7 +68,7 @@ namespace triagens {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
~AsyncCallbackContext () {
|
||||
if (_response != 0) {
|
||||
if (_response != nullptr) {
|
||||
delete _response;
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ namespace triagens {
|
|||
|
||||
AsyncJobResult () :
|
||||
_jobId(0),
|
||||
_response(0),
|
||||
_response(nullptr),
|
||||
_stamp(0.0),
|
||||
_status(JOB_UNDEFINED),
|
||||
_ctx(nullptr) {
|
||||
|
@ -245,7 +245,7 @@ namespace triagens {
|
|||
/// @brief joblist typedef
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef std::map<AsyncJobResult::IdType, AsyncJobResult> JobList;
|
||||
typedef std::unordered_map<AsyncJobResult::IdType, AsyncJobResult> JobList;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- constructors / destructors
|
||||
|
@ -390,7 +390,7 @@ namespace triagens {
|
|||
bool removeFromList) {
|
||||
WRITE_LOCKER(_lock);
|
||||
|
||||
JobList::iterator it = _jobs.find(jobId);
|
||||
auto it = _jobs.find(jobId);
|
||||
|
||||
if (it == _jobs.end()) {
|
||||
status = AsyncJobResult::JOB_UNDEFINED;
|
||||
|
@ -602,7 +602,7 @@ namespace triagens {
|
|||
bool deleteJobResult (AsyncJobResult::IdType jobId) {
|
||||
WRITE_LOCKER(_lock);
|
||||
|
||||
JobList::iterator it = _jobs.find(jobId);
|
||||
auto it = _jobs.find(jobId);
|
||||
|
||||
if (it == _jobs.end()) {
|
||||
return false;
|
||||
|
@ -626,7 +626,7 @@ namespace triagens {
|
|||
void deleteJobResults () {
|
||||
WRITE_LOCKER(_lock);
|
||||
|
||||
JobList::iterator it = _jobs.begin();
|
||||
auto it = _jobs.begin();
|
||||
|
||||
while (it != _jobs.end()) {
|
||||
HttpResponse* response = (*it).second._response;
|
||||
|
@ -648,7 +648,7 @@ namespace triagens {
|
|||
void deleteExpiredJobResults (double stamp) {
|
||||
WRITE_LOCKER(_lock);
|
||||
|
||||
JobList::iterator it = _jobs.begin();
|
||||
auto it = _jobs.begin();
|
||||
|
||||
while (it != _jobs.end()) {
|
||||
AsyncJobResult ajr = (*it).second;
|
||||
|
@ -831,7 +831,7 @@ namespace triagens {
|
|||
|
||||
{
|
||||
READ_LOCKER(_lock);
|
||||
JobList::iterator it = _jobs.begin();
|
||||
auto it = _jobs.begin();
|
||||
|
||||
// iterate the list. the list is sorted by id
|
||||
while (it != _jobs.end()) {
|
||||
|
@ -879,14 +879,14 @@ namespace triagens {
|
|||
}
|
||||
|
||||
AsyncJobResult ajr(*jobId,
|
||||
0,
|
||||
nullptr,
|
||||
TRI_microtime(),
|
||||
AsyncJobResult::JOB_PENDING,
|
||||
ctx);
|
||||
|
||||
WRITE_LOCKER(_lock);
|
||||
|
||||
_jobs[*jobId] = ajr;
|
||||
_jobs.emplace(*jobId, ajr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -906,13 +906,13 @@ namespace triagens {
|
|||
return;
|
||||
}
|
||||
|
||||
const double now = TRI_microtime();
|
||||
double const now = TRI_microtime();
|
||||
AsyncCallbackContext* ctx = nullptr;
|
||||
HttpResponse* response = nullptr;
|
||||
|
||||
{
|
||||
WRITE_LOCKER(_lock);
|
||||
JobList::iterator it = _jobs.find(jobId);
|
||||
auto it = _jobs.find(jobId);
|
||||
|
||||
if (it == _jobs.end()) {
|
||||
// job is already deleted.
|
||||
|
|
Loading…
Reference in New Issue