1
0
Fork 0

First hack at create document via REST on cluster.

This commit is contained in:
Max Neunhoeffer 2014-01-23 13:00:44 +01:00
parent eeca60897a
commit 165d98578a
9 changed files with 70 additions and 6 deletions

View File

@ -325,6 +325,7 @@ bool RestDocumentHandler::createDocument () {
#ifdef TRI_ENABLE_CLUSTER
if (ServerState::instance()->isCoordinator()) {
// json will be freed inside!
return createDocumentCoordinator(collection, waitForSync, json);
}
#endif
@ -404,9 +405,49 @@ bool RestDocumentHandler::createDocument () {
bool RestDocumentHandler::createDocumentCoordinator (char const* collection,
bool waitForSync,
TRI_json_t* json) {
// Find collectionID from collection, which is the name
// ask ClusterInfo for the responsible shard
// send a synchronous request to that shard using ClusterComm
// Set a few variables needed for our work:
ClusterInfo* ci = ClusterInfo::instance();
ClusterComm* cc = ClusterComm::instance();
string const& dbname = _request->originalDatabaseName();
CollectionID const collname(collection);
string collid;
// First determine the collection ID from the name:
CollectionInfo collinfo = ci->getCollection(dbname, collname);
collid = collinfo.id();
// Now find the responsible shard:
ShardID shardID = ci->getResponsibleShard( collid, json, true );
if (shardID == "") {
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
generateTransactionError(collection, TRI_ERROR_SHARD_GONE);
return false;
}
// Now sort out the _key attribute:
// FIXME: we have to be cleverer here, depending on shard attributes
uint64_t uid = ci->uniqid();
string _key = triagens::basics::StringUtils::itoa(uid);
TRI_InsertArrayJson(TRI_UNKNOWN_MEM_ZONE, json, "_key",
TRI_CreateStringReference2Json(TRI_UNKNOWN_MEM_ZONE,
_key.c_str(), _key.size()));
string body = JsonHelper::toString(json);
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
// Send a synchronous request to that shard using ClusterComm:
ClusterCommResult* res;
map<string, string> headers;
res = cc->syncRequest("", TRI_NewTickServer(), "shard:"+shardID,
triagens::rest::HttpRequest::HTTP_REQUEST_POST,
"/_db/"+dbname+"/_api/document?collection="+
StringUtils::urlEncode(collname)+"&waitForSync="+
(waitForSync ? "true" : "false"),
body.c_str(), body.size(), headers, 0.0);
if (res->status != CL_COMM_SENT) {
}
// if not successful prepare error and return false
// prepare successful answer (created or accepted depending on waitForSync)
return true;

View File

@ -437,6 +437,13 @@ void RestVocbaseBaseHandler::generateTransactionError (const string& collectionN
generatePreconditionFailed(_resolver.getCollectionId(collectionName), key ? key : (TRI_voc_key_t) "unknown", rid);
return;
#ifdef TRI_ENABLE_CLUSTER
case TRI_ERROR_SHARD_GONE:
generateError(HttpResponse::SERVER_ERROR, res,
"coordinator: no responsible shard found");
return;
#endif
default:
generateError(HttpResponse::SERVER_ERROR, TRI_ERROR_INTERNAL, "failed with error: " + string(TRI_errno_string(res)));
}

View File

@ -25,5 +25,3 @@ echo start arangod with:
echo "Pavel: bin/arangod --cluster.my-id Pavel --cluster.agency-prefix $NAME --cluster.agency-endpoint tcp://127.0.0.1:4001 --server.endpoint tcp://127.0.0.1:8530 data-pavel"
echo "Perry: bin/arangod --cluster.my-id Perry --cluster.agency-prefix $NAME --cluster.agency-endpoint tcp://127.0.0.1:4001 --server.endpoint tcp://127.0.0.1:8531 data-perry"
echo "Claus: bin/arangod --cluster.my-id Claus --cluster.agency-prefix $NAME --cluster.agency-endpoint tcp://127.0.0.1:4001 --server.endpoint tcp://127.0.0.1:8529 data-claus"
echo test with:
echo curl -X GET http://localhost:8529/_admin/sharding-test/_admin/time

View File

@ -125,6 +125,7 @@
"ERROR_CLUSTER_COULD_NOT_CREATE_DATABASE" : { "code" : 1462, "message" : "could not create database" },
"ERROR_CLUSTER_COULD_NOT_REMOVE_DATABASE_IN_PLAN" : { "code" : 1463, "message" : "could not remove database from plan" },
"ERROR_CLUSTER_COULD_NOT_REMOVE_DATABASE_IN_CURRENT" : { "code" : 1464, "message" : "could not remove database from current" },
"ERROR_SHARD_GONE" : { "code" : 1465, "message" : "no responsible shard found" },
"ERROR_QUERY_KILLED" : { "code" : 1500, "message" : "query killed" },
"ERROR_QUERY_PARSE" : { "code" : 1501, "message" : "%s" },
"ERROR_QUERY_EMPTY" : { "code" : 1502, "message" : "query is empty" },

View File

@ -125,6 +125,7 @@
"ERROR_CLUSTER_COULD_NOT_CREATE_DATABASE" : { "code" : 1462, "message" : "could not create database" },
"ERROR_CLUSTER_COULD_NOT_REMOVE_DATABASE_IN_PLAN" : { "code" : 1463, "message" : "could not remove database from plan" },
"ERROR_CLUSTER_COULD_NOT_REMOVE_DATABASE_IN_CURRENT" : { "code" : 1464, "message" : "could not remove database from current" },
"ERROR_SHARD_GONE" : { "code" : 1465, "message" : "no responsible shard found" },
"ERROR_QUERY_KILLED" : { "code" : 1500, "message" : "query killed" },
"ERROR_QUERY_PARSE" : { "code" : 1501, "message" : "%s" },
"ERROR_QUERY_EMPTY" : { "code" : 1502, "message" : "query is empty" },

View File

@ -160,6 +160,7 @@ ERROR_CLUSTER_COULD_NOT_CREATE_DATABASE_IN_PLAN,1461,"could not create database
ERROR_CLUSTER_COULD_NOT_CREATE_DATABASE,1462,"could not create database","Will be raised when a coordinator in a cluster notices that some DBServers report problems when creating databases for a new cluster wide database."
ERROR_CLUSTER_COULD_NOT_REMOVE_DATABASE_IN_PLAN,1463,"could not remove database from plan","Will be raised when a coordinator in a cluster cannot remove an entry for a database in the Plan hierarchy in the agency."
ERROR_CLUSTER_COULD_NOT_REMOVE_DATABASE_IN_CURRENT,1464,"could not remove database from current","Will be raised when a coordinator in a cluster cannot remove an entry for a database in the Current hierarchy in the agency."
ERROR_SHARD_GONE,1465,"no responsible shard found","Will be raised when a coordinator in a cluster cannot determine the shard that is responsible for a given document."
################################################################################
## ArangoDB query errors

View File

@ -203,7 +203,7 @@ void TRI_DestroyStringBuffer (TRI_string_buffer_t * self) {
////////////////////////////////////////////////////////////////////////////////
/// @brief frees the string buffer and cleans the buffer
///
/// @warning You must call free after or destroy using the string buffer.
/// @warning You must call free or destroy after using the string buffer.
////////////////////////////////////////////////////////////////////////////////
void TRI_AnnihilateStringBuffer (TRI_string_buffer_t * self) {

View File

@ -121,6 +121,7 @@ void TRI_InitialiseErrorMessages (void) {
REG_ERROR(ERROR_CLUSTER_COULD_NOT_CREATE_DATABASE, "could not create database");
REG_ERROR(ERROR_CLUSTER_COULD_NOT_REMOVE_DATABASE_IN_PLAN, "could not remove database from plan");
REG_ERROR(ERROR_CLUSTER_COULD_NOT_REMOVE_DATABASE_IN_CURRENT, "could not remove database from current");
REG_ERROR(ERROR_SHARD_GONE, "no responsible shard found");
REG_ERROR(ERROR_QUERY_KILLED, "query killed");
REG_ERROR(ERROR_QUERY_PARSE, "%s");
REG_ERROR(ERROR_QUERY_EMPTY, "query is empty");

View File

@ -280,6 +280,9 @@ extern "C" {
/// - 1464: @LIT{could not remove database from current}
/// Will be raised when a coordinator in a cluster cannot remove an entry for
/// a database in the Current hierarchy in the agency.
/// - 1465: @LIT{no responsible shard found}
/// Will be raised when a coordinator in a cluster cannot determine the shard
/// that is responsible for a given document.
/// - 1500: @LIT{query killed}
/// Will be raised when a running query is killed by an explicit admin
/// command.
@ -1624,6 +1627,17 @@ void TRI_InitialiseErrorMessages (void);
#define TRI_ERROR_CLUSTER_COULD_NOT_REMOVE_DATABASE_IN_CURRENT (1464)
////////////////////////////////////////////////////////////////////////////////
/// @brief 1465: ERROR_SHARD_GONE
///
/// no responsible shard found
///
/// Will be raised when a coordinator in a cluster cannot determine the shard
/// that is responsible for a given document.
////////////////////////////////////////////////////////////////////////////////
#define TRI_ERROR_SHARD_GONE (1465)
////////////////////////////////////////////////////////////////////////////////
/// @brief 1500: ERROR_QUERY_KILLED
///