mirror of https://gitee.com/bigwinds/arangodb
create collections, v0.0.0
This commit is contained in:
parent
45a5296e9e
commit
9ce78430ac
|
@ -181,6 +181,13 @@ static TRI_vocbase_t* LookupDatabaseFromRequest (triagens::rest::HttpRequest* re
|
|||
// get database name from request
|
||||
string dbName = request->databaseName();
|
||||
|
||||
#ifdef TRI_ENABLE_CLUSTER
|
||||
// if we are a coordinator, we always work inside the system database
|
||||
if (ServerState::instance()->isCoordinator()) {
|
||||
dbName = TRI_VOC_SYSTEM_DATABASE;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (databases.empty()) {
|
||||
// no databases defined. this means all databases are accessible via the endpoint
|
||||
|
||||
|
|
|
@ -333,6 +333,12 @@ static v8::Handle<v8::Object> RequestCppToV8 ( TRI_v8_global_t const* v8g,
|
|||
|
||||
req->Set(v8g->DatabaseKey, v8::String::New(database.c_str(), database.size()));
|
||||
|
||||
#ifdef TRI_ENABLE_CLUSTER
|
||||
// set originally requested database
|
||||
string const& originalDatabase = request->originalDatabaseName();
|
||||
req->Set(v8g->OriginalDatabaseKey, v8::String::New(originalDatabase.c_str(), originalDatabase.size()));
|
||||
#endif
|
||||
|
||||
// set the full url
|
||||
string const& fullUrl = request->fullUrl();
|
||||
req->Set(v8g->UrlKey, v8::String::New(fullUrl.c_str(), fullUrl.size()));
|
||||
|
|
|
@ -76,6 +76,11 @@
|
|||
#include "v8.h"
|
||||
#include "V8/JSLoader.h"
|
||||
|
||||
#ifdef TRI_ENABLE_CLUSTER
|
||||
#include "Cluster/ClusterInfo.h"
|
||||
#include "Cluster/ServerState.h"
|
||||
#endif
|
||||
|
||||
#include "unicode/timezone.h"
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/datefmt.h"
|
||||
|
@ -1757,6 +1762,53 @@ static v8::Handle<v8::Value> CreateVocBase (v8::Arguments const& argv,
|
|||
TRI_InitCollectionInfo(vocbase, ¶meter, name.c_str(), collectionType, effectiveSize, 0);
|
||||
}
|
||||
|
||||
|
||||
#ifdef TRI_ENABLE_CLUSTER
|
||||
const bool isCoordinator = ServerState::instance()->isCoordinator();
|
||||
#else
|
||||
const bool isCoordinator = false;
|
||||
#endif
|
||||
|
||||
if (isCoordinator) {
|
||||
v8::Handle<v8::Object> p = argv[1]->ToObject();
|
||||
|
||||
int64_t numberOfShards = 0;
|
||||
std::vector<std::string> shardKeys;
|
||||
|
||||
if (p->Has(v8::String::New("numberOfShards"))) {
|
||||
numberOfShards = TRI_ObjectToInt64(p->Get(v8::String::New("numberOfShards")));
|
||||
}
|
||||
|
||||
if (p->Has(TRI_V8_SYMBOL("shardKeys"))) {
|
||||
if (p->Get(TRI_V8_SYMBOL("shardKeys"))->IsArray()) {
|
||||
v8::Handle<v8::Array> k = v8::Handle<v8::Array>::Cast(p->Get(TRI_V8_SYMBOL("shardKeys")));
|
||||
|
||||
for (uint32_t i = 0 ; i < k->Length(); ++i) {
|
||||
v8::Handle<v8::Value> v = k->Get(i);
|
||||
if (v->IsString()) {
|
||||
shardKeys.push_back(TRI_ObjectToString(v));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (numberOfShards == 0) {
|
||||
TRI_FreeCollectionInfoOptions(¶meter);
|
||||
TRI_V8_EXCEPTION_PARAMETER(scope, "invalid number of shards");
|
||||
}
|
||||
|
||||
if (shardKeys.empty()) {
|
||||
TRI_FreeCollectionInfoOptions(¶meter);
|
||||
TRI_V8_EXCEPTION_PARAMETER(scope, "no shard keys specified");
|
||||
}
|
||||
|
||||
if (! ClusterInfo::instance()->doesDatabaseExist(vocbase->_name)) {
|
||||
TRI_FreeCollectionInfoOptions(¶meter);
|
||||
TRI_V8_EXCEPTION_PARAMETER(scope, "selected database is not a cluster database");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TRI_vocbase_col_t const* collection = TRI_CreateCollectionVocBase(vocbase,
|
||||
¶meter,
|
||||
0,
|
||||
|
|
|
@ -76,6 +76,11 @@ function collectionRepresentation (collection, showProperties, showCount, showFi
|
|||
result.journalSize = properties.journalSize;
|
||||
result.keyOptions = properties.keyOptions;
|
||||
result.waitForSync = properties.waitForSync;
|
||||
|
||||
if (cluster.isCoordinator()) {
|
||||
result.shardKeys = properties.shardKeys;
|
||||
result.numberOfShards = properties.numberOfShards;
|
||||
}
|
||||
}
|
||||
|
||||
if (showCount) {
|
||||
|
@ -158,33 +163,18 @@ function parseBodyForCreateCollection (req, res) {
|
|||
if (body.hasOwnProperty("waitForSync")) {
|
||||
r.parameter.waitForSync = body.waitForSync;
|
||||
}
|
||||
|
||||
if (body.hasOwnProperty("shardKeys") && cluster.isCoordinator()) {
|
||||
r.parameter.shardKeys = body.shardKeys || { };
|
||||
}
|
||||
|
||||
if (body.hasOwnProperty("numberOfShards") && cluster.isCoordinator()) {
|
||||
r.parameter.numberOfShards = body.numberOfShards || 0;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief creates a cluster collection
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function post_api_collection_coordinator (req, res) {
|
||||
// We already know that we are in a cluster and that we are a coordinator.
|
||||
|
||||
var r = parseBodyForCreateCollection(req, res);
|
||||
|
||||
if (r.bodyIsEmpty) {
|
||||
return; // error in JSON, is already reported
|
||||
}
|
||||
|
||||
if (r.name === "") {
|
||||
actions.resultBad(req, res, arangodb.ERROR_ARANGO_ILLEGAL_NAME,
|
||||
"name must be non-empty");
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
actions.resultOk(req, res, actions.HTTP_OK, { notYetImplemented: true });
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief creates a collection
|
||||
///
|
||||
|
@ -299,22 +289,6 @@ function post_api_collection_coordinator (req, res) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function post_api_collection (req, res) {
|
||||
|
||||
if (cluster.isCluster()) {
|
||||
if (cluster.isCoordinator()) {
|
||||
return post_api_collection_coordinator(req, res);
|
||||
}
|
||||
// If we get here, we are a DB server.
|
||||
if (!cluster.isCoordinatorRequest(req)) {
|
||||
actions.resultError(req, res, actions.HTTP_FORBIDDEN,
|
||||
arangodb.ERROR_CLUSTER_NO_COORDINATOR_HEADER,
|
||||
"DB server in cluster got request without coordinator header");
|
||||
|
||||
return;
|
||||
}
|
||||
// If the header is there, go on as usual.
|
||||
}
|
||||
|
||||
var r = parseBodyForCreateCollection(req);
|
||||
|
||||
if (r.bodyIsEmpty) {
|
||||
|
@ -351,6 +325,12 @@ function post_api_collection (req, res) {
|
|||
result.status = collection.status();
|
||||
result.type = collection.type();
|
||||
result.keyOptions = collection.keyOptions;
|
||||
|
||||
if (cluster.isCoordinator()) {
|
||||
// TODO:
|
||||
result.shardKeys = collection.shardKeys;
|
||||
result.numberOfShards = collection.numberOfShards;
|
||||
}
|
||||
|
||||
var headers = {
|
||||
location: databasePrefix(req, "/" + API + "/" + result.name)
|
||||
|
|
|
@ -1016,7 +1016,7 @@ actions.defineHttp({
|
|||
else {
|
||||
params += "&";
|
||||
}
|
||||
params += p+"="+String(req.parameters[p]);
|
||||
params += p+"="+ encodeURIComponent(String(req.parameters[p]));
|
||||
}
|
||||
}
|
||||
if (params !== "") {
|
||||
|
|
|
@ -338,7 +338,7 @@ ArangoDatabase.prototype._create = function (name, properties, type) {
|
|||
|
||||
if (properties !== undefined) {
|
||||
[ "waitForSync", "journalSize", "isSystem", "isVolatile",
|
||||
"doCompact", "keyOptions" ].forEach(function(p) {
|
||||
"doCompact", "keyOptions", "shardKeys", "numberOfShards" ].forEach(function(p) {
|
||||
if (properties.hasOwnProperty(p)) {
|
||||
body[p] = properties[p];
|
||||
}
|
||||
|
|
|
@ -337,7 +337,7 @@ ArangoDatabase.prototype._create = function (name, properties, type) {
|
|||
|
||||
if (properties !== undefined) {
|
||||
[ "waitForSync", "journalSize", "isSystem", "isVolatile",
|
||||
"doCompact", "keyOptions" ].forEach(function(p) {
|
||||
"doCompact", "keyOptions", "shardKeys", "numberOfShards" ].forEach(function(p) {
|
||||
if (properties.hasOwnProperty(p)) {
|
||||
body[p] = properties[p];
|
||||
}
|
||||
|
|
|
@ -76,6 +76,9 @@ HttpRequest::HttpRequest (ConnectionInfo const& info,
|
|||
_suffix(),
|
||||
_version(HTTP_UNKNOWN),
|
||||
_databaseName(),
|
||||
#ifdef TRI_ENABLE_CLUSTER
|
||||
_originalDatabaseName(),
|
||||
#endif
|
||||
_user(),
|
||||
_requestContext(0),
|
||||
_isRequestContextOwner(false),
|
||||
|
@ -666,6 +669,16 @@ string const& HttpRequest::databaseName () const {
|
|||
return _databaseName;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns the database name
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef TRI_ENABLE_CLUSTER
|
||||
string const& HttpRequest::originalDatabaseName () const {
|
||||
return _originalDatabaseName;
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns the authenticated user
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -224,6 +224,14 @@ namespace triagens {
|
|||
|
||||
std::string const& databaseName () const;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns the database name
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef TRI_ENABLE_CLUSTER
|
||||
std::string const& originalDatabaseName () const;
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns the authenticated user
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -669,6 +677,14 @@ namespace triagens {
|
|||
|
||||
string _databaseName;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief original database name
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef TRI_ENABLE_CLUSTER
|
||||
string _originalDatabaseName;
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief authenticated user
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -77,6 +77,9 @@ TRI_v8_global_s::TRI_v8_global_s (v8::Isolate* isolate)
|
|||
CoordTransactionIDKey(),
|
||||
#endif
|
||||
DatabaseKey(),
|
||||
#ifdef TRI_ENABLE_CLUSTER
|
||||
OriginalDatabaseKey(),
|
||||
#endif
|
||||
DoCompactKey(),
|
||||
DomainKey(),
|
||||
ErrorKey(),
|
||||
|
@ -154,10 +157,17 @@ TRI_v8_global_s::TRI_v8_global_s (v8::Isolate* isolate)
|
|||
CompatibilityKey = v8::Persistent<v8::String>::New(isolate, TRI_V8_SYMBOL("compatibility"));
|
||||
ContentTypeKey = v8::Persistent<v8::String>::New(isolate, TRI_V8_SYMBOL("contentType"));
|
||||
CookiesKey = v8::Persistent<v8::String>::New(isolate, TRI_V8_SYMBOL("cookies"));
|
||||
|
||||
#ifdef TRI_ENABLE_CLUSTER
|
||||
CoordTransactionIDKey = v8::Persistent<v8::String>::New(isolate, TRI_V8_SYMBOL("coordTransactionID"));
|
||||
#endif
|
||||
|
||||
DatabaseKey = v8::Persistent<v8::String>::New(isolate, TRI_V8_SYMBOL("database"));
|
||||
|
||||
#ifdef TRI_ENABLE_CLUSTER
|
||||
OriginalDatabaseKey = v8::Persistent<v8::String>::New(isolate, TRI_V8_SYMBOL("originalDatabase"));
|
||||
#endif
|
||||
|
||||
DoCompactKey = v8::Persistent<v8::String>::New(isolate, TRI_V8_SYMBOL("doCompact"));
|
||||
DomainKey = v8::Persistent<v8::String>::New(isolate, TRI_V8_SYMBOL("domain"));
|
||||
ErrorKey = v8::Persistent<v8::String>::New(isolate, TRI_V8_SYMBOL("error"));
|
||||
|
|
|
@ -413,6 +413,14 @@ typedef struct TRI_v8_global_s {
|
|||
|
||||
v8::Persistent<v8::String> DatabaseKey;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief "originalDatabase" key name
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef TRI_ENABLE_CLUSTER
|
||||
v8::Persistent<v8::String> OriginalDatabaseKey;
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief "doCompact" key name
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue