1
0
Fork 0

First case of create document is working on cluster.

This commit is contained in:
Max Neunhoeffer 2014-01-23 16:16:06 +01:00
parent 69c3456e1d
commit 9230f5020c
8 changed files with 54 additions and 11 deletions

View File

@ -1578,7 +1578,6 @@ ShardID ClusterInfo::getResponsibleShard (CollectionID const& collectionID,
int tries = 0;
TRI_shared_ptr<vector<string> > shardKeysPtr;
char const** shardKeys = 0;
int nrShardKeys = 0;
TRI_shared_ptr<vector<ShardID> > shards;
while (++tries <= 2) {
@ -1610,7 +1609,8 @@ ShardID ClusterInfo::getResponsibleShard (CollectionID const& collectionID,
return string("");
}
uint64_t hash = TRI_HashJsonByAttributes(json, shardKeys, nrShardKeys);
uint64_t hash = TRI_HashJsonByAttributes(json, shardKeys,
shardKeysPtr->size());
delete[] shardKeys;
return shards->at(hash % shards->size());

View File

@ -410,11 +410,10 @@ bool RestDocumentHandler::createDocumentCoordinator (char const* collection,
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();
string collid = StringUtils::itoa(collinfo.id());
// Now find the responsible shard:
ShardID shardID = ci->getResponsibleShard( collid, json, true );
@ -441,16 +440,39 @@ bool RestDocumentHandler::createDocumentCoordinator (char const* collection,
res = cc->syncRequest("", TRI_NewTickServer(), "shard:"+shardID,
triagens::rest::HttpRequest::HTTP_REQUEST_POST,
"/_db/"+dbname+"/_api/document?collection="+
StringUtils::urlEncode(collname)+"&waitForSync="+
StringUtils::urlEncode(shardID)+"&waitForSync="+
(waitForSync ? "true" : "false"),
body.c_str(), body.size(), headers, 0.0);
body.c_str(), body.size(), headers, 60.0);
if (res->status != CL_COMM_SENT) {
if (res->status == CL_COMM_TIMEOUT) {
// No reply, we give up:
generateTransactionError(collection, TRI_ERROR_CLUSTER_TIMEOUT);
return false;
}
// if not successful prepare error and return false
// prepare successful answer (created or accepted depending on waitForSync)
return true;
bool resultflag = true;
if (res->status == CL_COMM_ERROR) {
// This could be a broken connection or an Http error:
if (!res->result->isComplete()) {
generateTransactionError(collection, TRI_ERROR_CLUSTER_CONNECTION_LOST);
return false;
}
// In this case a proper HTTP error was reported by the DBserver,
// this can be 400 or 404, we simply forward the result.
resultflag = false;
// We intentionally fall through here.
}
_response = createResponse(
static_cast<rest::HttpResponse::HttpResponseCode>
(res->result->getHttpReturnCode()));
//cout << "CreateDoc: result code: " << res->result->getHttpReturnCode()
// << endl;
_response->setContentType(res->result->getContentType(false));
//cout << "CreateDoc: contentType: " << res->result->getContentType(false)
// << endl;
body = res->result->getBody().str(); // FIXME: a bad unnecessary copy!
//cout << "CreateDoc: body" << endl << body << endl;
//_response->body().appendText(body.c_str(), body.size());
return resultflag;
}
#endif

View File

@ -442,6 +442,9 @@ void RestVocbaseBaseHandler::generateTransactionError (const string& collectionN
generateError(HttpResponse::SERVER_ERROR, res,
"coordinator: no responsible shard found");
return;
case TRI_ERROR_CLUSTER_TIMEOUT:
generateError(HttpResponse::SERVER_ERROR, res);
return;
#endif
default:

View File

@ -126,6 +126,7 @@
"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_CLUSTER_CONNECTION_LOST" : { "code" : 1466, "message" : "cluster internal HTTP connection broken" },
"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

@ -126,6 +126,7 @@
"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_CLUSTER_CONNECTION_LOST" : { "code" : 1466, "message" : "cluster internal HTTP connection broken" },
"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

@ -161,6 +161,7 @@ ERROR_CLUSTER_COULD_NOT_CREATE_DATABASE,1462,"could not create database","Will b
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."
ERROR_CLUSTER_CONNECTION_LOST,1466,"cluster internal HTTP connection broken","Will be raised when a coordinator in a cluster loses an HTTP connection to a DBserver in the cluster whilst transferring data."
################################################################################
## ArangoDB query errors

View File

@ -122,6 +122,7 @@ void TRI_InitialiseErrorMessages (void) {
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_CLUSTER_CONNECTION_LOST, "cluster internal HTTP connection broken");
REG_ERROR(ERROR_QUERY_KILLED, "query killed");
REG_ERROR(ERROR_QUERY_PARSE, "%s");
REG_ERROR(ERROR_QUERY_EMPTY, "query is empty");

View File

@ -283,6 +283,9 @@ extern "C" {
/// - 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.
/// - 1466: @LIT{cluster internal HTTP connection broken}
/// Will be raised when a coordinator in a cluster loses an HTTP connection
/// to a DBserver in the cluster whilst transferring data.
/// - 1500: @LIT{query killed}
/// Will be raised when a running query is killed by an explicit admin
/// command.
@ -1638,6 +1641,17 @@ void TRI_InitialiseErrorMessages (void);
#define TRI_ERROR_SHARD_GONE (1465)
////////////////////////////////////////////////////////////////////////////////
/// @brief 1466: ERROR_CLUSTER_CONNECTION_LOST
///
/// cluster internal HTTP connection broken
///
/// Will be raised when a coordinator in a cluster loses an HTTP connection to
/// a DBserver in the cluster whilst transferring data.
////////////////////////////////////////////////////////////////////////////////
#define TRI_ERROR_CLUSTER_CONNECTION_LOST (1466)
////////////////////////////////////////////////////////////////////////////////
/// @brief 1500: ERROR_QUERY_KILLED
///