mirror of https://gitee.com/bigwinds/arangodb
fix collection creation
This commit is contained in:
parent
e56d385c5e
commit
ba2ed30093
|
@ -1566,17 +1566,10 @@ static void CreateVocBase (const v8::FunctionCallbackInfo<v8::Value>& args,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
PREVENT_EMBEDDED_TRANSACTION();
|
||||
|
||||
|
||||
|
||||
// extract the name
|
||||
string const name = TRI_ObjectToString(args[0]);
|
||||
|
||||
// extract the parameters
|
||||
TRI_voc_cid_t cid = 0;
|
||||
|
||||
std::string const name = TRI_ObjectToString(args[0]);
|
||||
|
||||
VPackBuilder builder;
|
||||
VPackSlice infoSlice;
|
||||
|
@ -1586,94 +1579,23 @@ static void CreateVocBase (const v8::FunctionCallbackInfo<v8::Value>& args,
|
|||
}
|
||||
|
||||
int res = TRI_V8ToVPack(isolate, builder, args[1], false);
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
TRI_V8_THROW_EXCEPTION(res);
|
||||
}
|
||||
infoSlice = builder.slice();
|
||||
|
||||
if (infoSlice.hasKey("journalSize")) {
|
||||
VPackSlice maxSizeSlice = infoSlice.get("journalSize");
|
||||
TRI_voc_size_t maximalSize = maxSizeSlice.getNumericValue<TRI_voc_size_t>();
|
||||
if (maximalSize < TRI_JOURNAL_MINIMAL_SIZE) {
|
||||
TRI_V8_THROW_EXCEPTION_PARAMETER("<properties>.journalSize too small");
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef TRI_HAVE_ANONYMOUS_MMAP
|
||||
if (infoSlice.hasKey("isVolatile")) {
|
||||
TRI_V8_THROW_EXCEPTION_PARAMETER("volatile collections are not supported on this platform");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
VocbaseCollectionInfo parameters(vocbase, name.c_str(), collectionType, infoSlice);
|
||||
|
||||
if (parameters.isVolatile() && parameters.waitForSync()) {
|
||||
// the combination of waitForSync and isVolatile makes no sense
|
||||
TRI_V8_THROW_EXCEPTION_PARAMETER("volatile collections do not support the waitForSync option");
|
||||
}
|
||||
|
||||
|
||||
if (parameters.indexBuckets() < 1 ||
|
||||
parameters.indexBuckets() > 1024) {
|
||||
TRI_V8_THROW_EXCEPTION_PARAMETER("indexBuckets must be a two-power between 1 and 1024");
|
||||
}
|
||||
|
||||
// TODO Remove these ASSERTS
|
||||
|
||||
if (2 <= args.Length()) {
|
||||
v8::Handle<v8::Object> p = args[1]->ToObject();
|
||||
TRI_GET_GLOBALS();
|
||||
|
||||
TRI_GET_GLOBAL_STRING(JournalSizeKey);
|
||||
if (! p->Has(JournalSizeKey)) {
|
||||
TRI_ASSERT(parameters.maximalSize() == vocbase->_settings.defaultMaximalSize);
|
||||
}
|
||||
|
||||
if (p->Has(TRI_V8_ASCII_STRING("planId"))) {
|
||||
TRI_ASSERT(parameters.planId() == TRI_ObjectToUInt64(p->Get(TRI_V8_ASCII_STRING("planId")), true));
|
||||
}
|
||||
|
||||
TRI_GET_GLOBAL_STRING(WaitForSyncKey);
|
||||
if (p->Has(WaitForSyncKey)) {
|
||||
TRI_ASSERT(parameters.waitForSync() == TRI_ObjectToBoolean(p->Get(WaitForSyncKey)));
|
||||
}
|
||||
|
||||
TRI_GET_GLOBAL_STRING(DoCompactKey);
|
||||
if (p->Has(DoCompactKey)) {
|
||||
TRI_ASSERT(parameters.doCompact() == TRI_ObjectToBoolean(p->Get(DoCompactKey)));
|
||||
}
|
||||
else {
|
||||
// default value for compaction
|
||||
TRI_ASSERT(parameters.doCompact());
|
||||
}
|
||||
|
||||
TRI_GET_GLOBAL_STRING(IsSystemKey);
|
||||
if (p->Has(IsSystemKey)) {
|
||||
TRI_ASSERT(parameters.isSystem() == TRI_ObjectToBoolean(p->Get(IsSystemKey)));
|
||||
}
|
||||
|
||||
|
||||
TRI_GET_GLOBAL_STRING(IdKey);
|
||||
if (p->Has(IdKey)) {
|
||||
// specify collection id - used for testing only
|
||||
cid = TRI_ObjectToUInt64(p->Get(IdKey), true);
|
||||
}
|
||||
|
||||
if (p->Has(TRI_V8_ASCII_STRING("indexBuckets"))) {
|
||||
TRI_ASSERT(parameters.indexBuckets() == static_cast<uint32_t>(TRI_ObjectToUInt64(p->Get(TRI_V8_ASCII_STRING("indexBuckets")), true)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ServerState::instance()->isCoordinator()) {
|
||||
CreateCollectionCoordinator(args, collectionType, vocbase->_name, parameters, vocbase);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
TRI_vocbase_col_t const* collection = TRI_CreateCollectionVocBase(vocbase,
|
||||
parameters,
|
||||
cid,
|
||||
parameters.id(),
|
||||
true);
|
||||
|
||||
|
||||
|
|
|
@ -1125,8 +1125,12 @@ VocbaseCollectionInfo::VocbaseCollectionInfo (TRI_vocbase_t* vocbase,
|
|||
_waitForSync(vocbase->_settings.defaultWaitForSync) {
|
||||
|
||||
memset(_name, 0, sizeof(_name));
|
||||
|
||||
if (name != '\0') {
|
||||
TRI_CopyString(_name, name, sizeof(_name) - 1);
|
||||
}
|
||||
|
||||
if (!options.isNone() && options.isObject() ) {
|
||||
if (options.isObject()) {
|
||||
// TODO what if both are present?
|
||||
TRI_voc_size_t maximalSize;
|
||||
if (options.hasKey("journalSize")) {
|
||||
|
@ -1144,7 +1148,6 @@ VocbaseCollectionInfo::VocbaseCollectionInfo (TRI_vocbase_t* vocbase,
|
|||
_doCompact = triagens::basics::VelocyPackHelper::getBooleanValue(options, "doCompact", true);
|
||||
_waitForSync = triagens::basics::VelocyPackHelper::getBooleanValue(options, "waitForSync", vocbase->_settings.defaultWaitForSync);
|
||||
_isVolatile = triagens::basics::VelocyPackHelper::getBooleanValue(options, "isVolatile", false);
|
||||
_isSystem = (name[0] == '_');
|
||||
_indexBuckets = triagens::basics::VelocyPackHelper::getNumericValue<uint32_t>(options, "indexBuckets", TRI_DEFAULT_INDEX_BUCKETS);
|
||||
// TODO
|
||||
// CHECK data type
|
||||
|
@ -1160,11 +1163,26 @@ VocbaseCollectionInfo::VocbaseCollectionInfo (TRI_vocbase_t* vocbase,
|
|||
// note: this may throw
|
||||
_cid = std::stoull(cidString);
|
||||
}
|
||||
|
||||
if (options.hasKey("isSystem")) {
|
||||
VPackSlice isSystemSlice = options.get("isSystem");
|
||||
if (isSystemSlice.isBoolean()) {
|
||||
_isSystem = isSystemSlice.getBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
if (options.hasKey("journalSize")) {
|
||||
VPackSlice maxSizeSlice = options.get("journalSize");
|
||||
TRI_voc_size_t maximalSize = maxSizeSlice.getNumericValue<TRI_voc_size_t>();
|
||||
if (maximalSize < TRI_JOURNAL_MINIMAL_SIZE) {
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_BAD_PARAMETER, "journalSize is too small");
|
||||
}
|
||||
}
|
||||
|
||||
VPackSlice const planIdSlice = options.get("planId");
|
||||
TRI_voc_cid_t planId = 0;
|
||||
if (planIdSlice.isNumber()) {
|
||||
planId = static_cast<TRI_voc_cid_t>(planIdSlice.getNumericValue<uint64_t>());
|
||||
planId = planIdSlice.getNumericValue<TRI_voc_cid_t>();
|
||||
}
|
||||
else if (planIdSlice.isString()) {
|
||||
std::string tmp = planIdSlice.copyString();
|
||||
|
@ -1174,23 +1192,45 @@ VocbaseCollectionInfo::VocbaseCollectionInfo (TRI_vocbase_t* vocbase,
|
|||
if (planId > 0) {
|
||||
_planId = planId;
|
||||
}
|
||||
try {
|
||||
if (options.hasKey("keyOptions")) {
|
||||
VPackSlice const slice = options.get("keyOptions");
|
||||
VPackBuilder builder;
|
||||
builder.add(slice);
|
||||
_keyOptions = builder.steal();
|
||||
}
|
||||
|
||||
VPackSlice const cidSlice = options.get("cid");
|
||||
if (cidSlice.isNumber()) {
|
||||
_cid = cidSlice.getNumericValue<TRI_voc_cid_t>();
|
||||
}
|
||||
catch (...) {
|
||||
// Unparseable
|
||||
// We keep a nullptr
|
||||
else if (cidSlice.isString()) {
|
||||
std::string tmp = cidSlice.copyString();
|
||||
_cid = static_cast<TRI_voc_cid_t>(TRI_UInt64String2(tmp.c_str(), tmp.length()));
|
||||
}
|
||||
|
||||
if (options.hasKey("keyOptions")) {
|
||||
VPackSlice const slice = options.get("keyOptions");
|
||||
VPackBuilder builder;
|
||||
builder.add(slice);
|
||||
_keyOptions = builder.steal();
|
||||
}
|
||||
}
|
||||
|
||||
if (*_name == '\0') {
|
||||
TRI_CopyString(_name, name, sizeof(_name) - 1);
|
||||
#ifndef TRI_HAVE_ANONYMOUS_MMAP
|
||||
if (_isVolatile) {
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_BAD_PARAMETER, "volatile collections are not supported on this platform");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (_isVolatile && _waitForSync) {
|
||||
// the combination of waitForSync and isVolatile makes no sense
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_BAD_PARAMETER, "volatile collections do not support the waitForSync option");
|
||||
}
|
||||
|
||||
if (_indexBuckets < 1 || _indexBuckets > 1024) {
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_BAD_PARAMETER, "indexBuckets must be a two-power between 1 and 1024");
|
||||
}
|
||||
|
||||
if (! TRI_IsAllowedNameCollection(_isSystem, _name)) {
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_ILLEGAL_NAME);
|
||||
}
|
||||
|
||||
// fix _isSystem value if mis-specified by user
|
||||
_isSystem = (*_name == '_');
|
||||
}
|
||||
|
||||
VocbaseCollectionInfo::~VocbaseCollectionInfo () {
|
||||
|
|
Loading…
Reference in New Issue