1
0
Fork 0

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:
Jan 2019-09-12 15:42:56 +02:00 committed by KVS85
parent 393ffba276
commit c7b0e68026
4 changed files with 32 additions and 7 deletions

View File

@ -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

View File

@ -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);
@ -364,7 +366,12 @@ Result IndexFactory::validateFieldsDefinition(VPackSlice definition, size_t minF
return Result(TRI_ERROR_BAD_PARAMETER, return Result(TRI_ERROR_BAD_PARAMETER,
"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()) {

View File

@ -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,

View File

@ -204,6 +204,16 @@ function TtlSuite () {
// number of runs must not have changed // number of runs must not have changed
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 });