mirror of https://gitee.com/bigwinds/arangodb
disable the creation of TTL indexes on sub-attributes (#9995)
* disable the creation of TTL indexes on sub-attributes * updated CHANGELOG
This commit is contained in:
parent
393ffba276
commit
c7b0e68026
|
@ -1,6 +1,12 @@
|
||||||
v3.5.1 (XXXX-XX-XX)
|
v3.5.1 (XXXX-XX-XX)
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
* Disallow creation of TTL indexes on sub-attributes.
|
||||||
|
|
||||||
|
Creation of such indexes was not caught before, but the resulting
|
||||||
|
indexes were defunct. From now on the creation of TTL indexes on sub-
|
||||||
|
attributes is disallowed.
|
||||||
|
|
||||||
* Added HotBackup feature.
|
* Added HotBackup feature.
|
||||||
|
|
||||||
* Improved database creation within the cluster. In the case of
|
* Improved database creation within the cluster. In the case of
|
||||||
|
|
|
@ -333,7 +333,9 @@ TRI_idx_iid_t IndexFactory::validateSlice(arangodb::velocypack::Slice info,
|
||||||
return iid;
|
return iid;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result IndexFactory::validateFieldsDefinition(VPackSlice definition, size_t minFields, size_t maxFields) {
|
Result IndexFactory::validateFieldsDefinition(VPackSlice definition,
|
||||||
|
size_t minFields, size_t maxFields,
|
||||||
|
bool allowSubAttributes) {
|
||||||
if (basics::VelocyPackHelper::getBooleanValue(definition, StaticStrings::Error, false)) {
|
if (basics::VelocyPackHelper::getBooleanValue(definition, StaticStrings::Error, false)) {
|
||||||
// We have an error here.
|
// We have an error here.
|
||||||
return Result(TRI_ERROR_BAD_PARAMETER);
|
return Result(TRI_ERROR_BAD_PARAMETER);
|
||||||
|
@ -365,6 +367,11 @@ Result IndexFactory::validateFieldsDefinition(VPackSlice definition, size_t minF
|
||||||
"duplicate attribute name in index fields list");
|
"duplicate attribute name in index fields list");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!allowSubAttributes && f.find('.') != std::string::npos) {
|
||||||
|
return Result(TRI_ERROR_BAD_PARAMETER,
|
||||||
|
"cannot index a sub-attribute in this type of index");
|
||||||
|
}
|
||||||
|
|
||||||
if (std::regex_match(f.toString(), idRegex)) {
|
if (std::regex_match(f.toString(), idRegex)) {
|
||||||
return Result(TRI_ERROR_BAD_PARAMETER,
|
return Result(TRI_ERROR_BAD_PARAMETER,
|
||||||
"_id attribute cannot be indexed");
|
"_id attribute cannot be indexed");
|
||||||
|
@ -386,10 +393,11 @@ Result IndexFactory::validateFieldsDefinition(VPackSlice definition, size_t minF
|
||||||
/// @brief process the fields list, deduplicate it, and add it to the json
|
/// @brief process the fields list, deduplicate it, and add it to the json
|
||||||
Result IndexFactory::processIndexFields(VPackSlice definition, VPackBuilder& builder,
|
Result IndexFactory::processIndexFields(VPackSlice definition, VPackBuilder& builder,
|
||||||
size_t minFields, size_t maxFields,
|
size_t minFields, size_t maxFields,
|
||||||
bool create, bool allowExpansion) {
|
bool create, bool allowExpansion,
|
||||||
|
bool allowSubAttributes) {
|
||||||
TRI_ASSERT(builder.isOpenObject());
|
TRI_ASSERT(builder.isOpenObject());
|
||||||
|
|
||||||
Result res = validateFieldsDefinition(definition, minFields, maxFields);
|
Result res = validateFieldsDefinition(definition, minFields, maxFields, allowSubAttributes);
|
||||||
if (res.fail()) {
|
if (res.fail()) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -477,7 +485,7 @@ Result IndexFactory::enhanceJsonIndexGeneric(VPackSlice definition,
|
||||||
/// @brief enhances the json of a ttl index
|
/// @brief enhances the json of a ttl index
|
||||||
Result IndexFactory::enhanceJsonIndexTtl(VPackSlice definition,
|
Result IndexFactory::enhanceJsonIndexTtl(VPackSlice definition,
|
||||||
VPackBuilder& builder, bool create) {
|
VPackBuilder& builder, bool create) {
|
||||||
Result res = processIndexFields(definition, builder, 1, 1, create, false);
|
Result res = processIndexFields(definition, builder, 1, 1, create, false, false);
|
||||||
|
|
||||||
auto value = definition.get(arangodb::StaticStrings::IndexUnique);
|
auto value = definition.get(arangodb::StaticStrings::IndexUnique);
|
||||||
if (value.isBoolean() && value.getBoolean()) {
|
if (value.isBoolean() && value.getBoolean()) {
|
||||||
|
|
|
@ -111,13 +111,14 @@ class IndexFactory {
|
||||||
std::vector<std::shared_ptr<arangodb::Index>>& indexes) const = 0;
|
std::vector<std::shared_ptr<arangodb::Index>>& indexes) const = 0;
|
||||||
|
|
||||||
static Result validateFieldsDefinition(arangodb::velocypack::Slice definition,
|
static Result validateFieldsDefinition(arangodb::velocypack::Slice definition,
|
||||||
size_t minFields, size_t maxFields);
|
size_t minFields, size_t maxFields,
|
||||||
|
bool allowSubAttributes = true);
|
||||||
|
|
||||||
/// @brief process the fields list, deduplicate it, and add it to the json
|
/// @brief process the fields list, deduplicate it, and add it to the json
|
||||||
static Result processIndexFields(arangodb::velocypack::Slice definition,
|
static Result processIndexFields(arangodb::velocypack::Slice definition,
|
||||||
arangodb::velocypack::Builder& builder,
|
arangodb::velocypack::Builder& builder,
|
||||||
size_t minFields, size_t maxFields, bool create,
|
size_t minFields, size_t maxFields, bool create,
|
||||||
bool allowExpansion);
|
bool allowExpansion, bool allowSubAttributes = true);
|
||||||
|
|
||||||
/// @brief process the unique flag and add it to the json
|
/// @brief process the unique flag and add it to the json
|
||||||
static void processIndexUniqueFlag(arangodb::velocypack::Slice definition,
|
static void processIndexUniqueFlag(arangodb::velocypack::Slice definition,
|
||||||
|
|
|
@ -205,6 +205,16 @@ function TtlSuite () {
|
||||||
assertEqual(stats.runs, oldRuns);
|
assertEqual(stats.runs, oldRuns);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
testCreateIndexSubAttribute : function () {
|
||||||
|
let c = db._create(cn, { numberOfShards: 2 });
|
||||||
|
try {
|
||||||
|
c.ensureIndex({ type: "ttl", fields: ["date.created"], expireAfter: 10, unique: true });
|
||||||
|
fail();
|
||||||
|
} catch (err) {
|
||||||
|
assertEqual(ERRORS.ERROR_BAD_PARAMETER.code, err.errorNum);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
testCreateIndexUnique : function () {
|
testCreateIndexUnique : function () {
|
||||||
let c = db._create(cn, { numberOfShards: 2 });
|
let c = db._create(cn, { numberOfShards: 2 });
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue