1
0
Fork 0

replication API documentation

This commit is contained in:
Jan Steemann 2015-09-14 15:30:00 +02:00
parent fcd1637261
commit e08d840b47
2 changed files with 44 additions and 40 deletions

View File

@ -61,9 +61,9 @@ using namespace triagens::arango;
// --SECTION-- initialize static variables
// -----------------------------------------------------------------------------
const uint64_t RestReplicationHandler::defaultChunkSize = 128 * 1024;
uint64_t const RestReplicationHandler::defaultChunkSize = 128 * 1024;
const uint64_t RestReplicationHandler::maxChunkSize = 128 * 1024 * 1024;
uint64_t const RestReplicationHandler::maxChunkSize = 128 * 1024 * 1024;
// -----------------------------------------------------------------------------
// --SECTION-- constructors and destructors
@ -94,7 +94,7 @@ RestReplicationHandler::~RestReplicationHandler () {
HttpHandler::status_t RestReplicationHandler::execute () {
// extract the request type
const HttpRequest::HttpRequestType type = _request->requestType();
HttpRequest::HttpRequestType const type = _request->requestType();
vector<string> const& suffix = _request->suffix();
@ -909,7 +909,7 @@ void RestReplicationHandler::handleCommandBatch () {
int res = TRI_InsertBlockerCompactorVocBase(_vocbase, expires, &id);
if (res != TRI_ERROR_NO_ERROR) {
generateError(HttpResponse::BAD, res);
generateError(HttpResponse::responseCode(res), res);
return;
}
@ -948,7 +948,7 @@ void RestReplicationHandler::handleCommandBatch () {
_response = createResponse(HttpResponse::NO_CONTENT);
}
else {
generateError(HttpResponse::BAD, res);
generateError(HttpResponse::responseCode(res), res);
}
return;
}
@ -963,7 +963,7 @@ void RestReplicationHandler::handleCommandBatch () {
_response = createResponse(HttpResponse::NO_CONTENT);
}
else {
generateError(HttpResponse::BAD, res);
generateError(HttpResponse::responseCode(res), res);
}
return;
}
@ -1386,7 +1386,7 @@ void RestReplicationHandler::handleCommandLoggerFollow () {
}
if (res != TRI_ERROR_NO_ERROR) {
generateError(HttpResponse::SERVER_ERROR, res);
generateError(HttpResponse::responseCode(res), res);
}
}
@ -1466,7 +1466,7 @@ void RestReplicationHandler::handleCommandDetermineOpenTransactions () {
}
if (res != TRI_ERROR_NO_ERROR) {
generateError(HttpResponse::SERVER_ERROR, res);
generateError(HttpResponse::responseCode(res), res);
}
}
@ -1956,7 +1956,7 @@ void RestReplicationHandler::handleCommandRestoreCollection () {
}
if (res != TRI_ERROR_NO_ERROR) {
generateError(HttpResponse::SERVER_ERROR, res);
generateError(HttpResponse::responseCode(res), res);
}
else {
TRI_json_t result;
@ -2003,7 +2003,7 @@ void RestReplicationHandler::handleCommandRestoreIndexes () {
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
if (res != TRI_ERROR_NO_ERROR) {
generateError(HttpResponse::SERVER_ERROR, res);
generateError(HttpResponse::responseCode(res), res);
}
else {
TRI_json_t result;
@ -2773,7 +2773,7 @@ void RestReplicationHandler::handleCommandRestoreData () {
int res = processRestoreData(resolver, cid, recycleIds, force, errorMsg);
if (res != TRI_ERROR_NO_ERROR) {
generateError(HttpResponse::SERVER_ERROR, res);
generateError(HttpResponse::responseCode(res), res);
}
else {
TRI_json_t result;
@ -3063,7 +3063,7 @@ void RestReplicationHandler::handleCommandRestoreDataCoordinator () {
}
if (res != TRI_ERROR_NO_ERROR) {
generateError(HttpResponse::BAD, res, errorMsg);
generateError(HttpResponse::responseCode(res), res, errorMsg);
return;
}
@ -3157,7 +3157,7 @@ void RestReplicationHandler::handleCommandCreateKeys () {
}
if (res != TRI_ERROR_NO_ERROR) {
generateError(HttpResponse::SERVER_ERROR, res);
generateError(HttpResponse::responseCode(res), res);
}
}
@ -3249,7 +3249,7 @@ void RestReplicationHandler::handleCommandGetKeys () {
}
if (res != TRI_ERROR_NO_ERROR) {
generateError(HttpResponse::SERVER_ERROR, res);
generateError(HttpResponse::responseCode(res), res);
}
}
@ -3353,7 +3353,7 @@ void RestReplicationHandler::handleCommandFetchKeys () {
}
if (res != TRI_ERROR_NO_ERROR) {
generateError(HttpResponse::SERVER_ERROR, res);
generateError(HttpResponse::responseCode(res), res);
}
}
@ -3662,7 +3662,7 @@ void RestReplicationHandler::handleCommandDump () {
}
if (res != TRI_ERROR_NO_ERROR) {
generateError(HttpResponse::SERVER_ERROR, res);
generateError(HttpResponse::responseCode(res), res);
}
}
@ -3913,7 +3913,7 @@ void RestReplicationHandler::handleCommandMakeSlave () {
if (res != TRI_ERROR_NO_ERROR) {
TRI_DestroyConfigurationReplicationApplier(&config);
generateError(HttpResponse::SERVER_ERROR, res);
generateError(HttpResponse::responseCode(res), res);
return;
}
@ -3939,7 +3939,7 @@ void RestReplicationHandler::handleCommandMakeSlave () {
if (res != TRI_ERROR_NO_ERROR) {
TRI_DestroyConfigurationReplicationApplier(&config);
generateError(HttpResponse::SERVER_ERROR, res, errorMsg);
generateError(HttpResponse::responseCode(res), res, errorMsg);
return;
}
@ -3947,7 +3947,7 @@ void RestReplicationHandler::handleCommandMakeSlave () {
if (res != TRI_ERROR_NO_ERROR) {
TRI_DestroyConfigurationReplicationApplier(&config);
generateError(HttpResponse::SERVER_ERROR, res);
generateError(HttpResponse::responseCode(res), res);
return;
}
@ -3956,7 +3956,7 @@ void RestReplicationHandler::handleCommandMakeSlave () {
res =_vocbase->_replicationApplier->start(lastLogTick, true);
if (res != TRI_ERROR_NO_ERROR) {
generateError(HttpResponse::SERVER_ERROR, res);
generateError(HttpResponse::responseCode(res), res);
return;
}
@ -3990,9 +3990,17 @@ void RestReplicationHandler::handleCommandMakeSlave () {
/// @RESTBODYPARAM{password,string,required,string}
/// the password to use when connecting to the endpoint.
///
/// @RESTBODYPARAM{includeSystem,boolean,required,}
/// @RESTBODYPARAM{includeSystem,boolean,optional,}
/// whether or not system collection operations will be applied
///
/// @RESTBODYPARAM{incremental,boolean,optional,}
/// if set to *true*, then an incremental synchronization method will be used
/// for synchronizing data in collections. This method is useful when
/// collections already exist locally, and only the remaining differences need
/// to be transferred from the remote endpoint. The default value is *false*,
/// meaning that the complete data from the remote collection will be
/// transferred.
///
/// @RESTBODYPARAM{restrictType,string,optional,string}
/// an optional string value for collection filtering. When
/// specified, the allowed values are *include* or *exclude*.
@ -4027,7 +4035,7 @@ void RestReplicationHandler::handleCommandMakeSlave () {
/// was started. Use this value as the *from* value when starting the continuous
/// synchronization later.
///
/// WARNING: calling this method will sychronise data from the collections found
/// WARNING: calling this method will sychronize data from the collections found
/// on the remote endpoint to the local ArangoDB database. All data in the local
/// collections will be purged and replaced with data from the endpoint.
///
@ -4062,11 +4070,10 @@ void RestReplicationHandler::handleCommandSync () {
return;
}
const string endpoint = JsonHelper::getStringValue(json.get(), "endpoint", "");
const string database = JsonHelper::getStringValue(json.get(), "database", _vocbase->_name);
const string username = JsonHelper::getStringValue(json.get(), "username", "");
const string password = JsonHelper::getStringValue(json.get(), "password", "");
std::string const endpoint = JsonHelper::getStringValue(json.get(), "endpoint", "");
std::string const database = JsonHelper::getStringValue(json.get(), "database", _vocbase->_name);
std::string const username = JsonHelper::getStringValue(json.get(), "username", "");
std::string const password = JsonHelper::getStringValue(json.get(), "password", "");
if (endpoint.empty()) {
generateError(HttpResponse::BAD, TRI_ERROR_HTTP_BAD_PARAMETER, "<endpoint> must be a valid endpoint");
@ -4098,6 +4105,8 @@ void RestReplicationHandler::handleCommandSync () {
generateError(HttpResponse::BAD, TRI_ERROR_HTTP_BAD_PARAMETER, "invalid value for <restrictCollections> or <restrictType>");
return;
}
bool incremental = JsonHelper::getBooleanValue(json.get(), "incremental", false);
TRI_replication_applier_configuration_t config;
TRI_InitConfigurationReplicationApplier(&config);
@ -4114,7 +4123,7 @@ void RestReplicationHandler::handleCommandSync () {
string errorMsg = "";
try {
res = syncer.run(errorMsg, false);
res = syncer.run(errorMsg, incremental);
}
catch (...) {
errorMsg = "caught an exception";
@ -4122,22 +4131,21 @@ void RestReplicationHandler::handleCommandSync () {
}
if (res != TRI_ERROR_NO_ERROR) {
generateError(HttpResponse::SERVER_ERROR, res, errorMsg);
generateError(HttpResponse::responseCode(res), res, errorMsg);
return;
}
TRI_json_t result;
TRI_InitObjectJson(TRI_CORE_MEM_ZONE, &result);
TRI_json_t* jsonCollections = TRI_CreateArrayJson(TRI_CORE_MEM_ZONE);
if (jsonCollections != nullptr) {
map<TRI_voc_cid_t, string>::const_iterator it;
const map<TRI_voc_cid_t, string>& c = syncer.getProcessedCollections();
std::map<TRI_voc_cid_t, std::string>::const_iterator it;
std::map<TRI_voc_cid_t, std::string> const& c = syncer.getProcessedCollections();
for (it = c.begin(); it != c.end(); ++it) {
const string cidString = StringUtils::itoa((*it).first);
std::string const cidString = StringUtils::itoa((*it).first);
TRI_json_t* ci = TRI_CreateObjectJson(TRI_CORE_MEM_ZONE, 2);
@ -4531,13 +4539,7 @@ void RestReplicationHandler::handleCommandApplierSetConfig () {
TRI_DestroyConfigurationReplicationApplier(&config);
if (res != TRI_ERROR_NO_ERROR) {
if (res == TRI_ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION ||
res == TRI_ERROR_REPLICATION_RUNNING) {
generateError(HttpResponse::BAD, res);
}
else {
generateError(HttpResponse::SERVER_ERROR, res);
}
generateError(HttpResponse::responseCode(res), res);
return;
}

View File

@ -211,6 +211,8 @@ HttpResponse::HttpResponseCode HttpResponse::responseCode (int code) {
case TRI_ERROR_CLUSTER_MUST_NOT_SPECIFY_KEY:
case TRI_ERROR_TYPE_ERROR:
case TRI_ERROR_QUERY_NUMBER_OUT_OF_RANGE:
case TRI_ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION:
case TRI_ERROR_REPLICATION_RUNNING:
return BAD;
case TRI_ERROR_ARANGO_READ_ONLY: