fix(tsm1): delimit tsmKeyPrefix with appended comma (#18785)
* fix(tsm1): delimit tsmKeyPrefix with appended comma Fixes #7589. Append a comma to the TSM key prefix when matching a full measurement name to avoid erroneously matching other measurement names that include the prefix in their own name. For example, this prevents matching a measurement "cpu1" when targeting "cpu" by updating the prefix to "cpu,". This relies on the fact that tag key-value pairs are separated by commas. * fix(tsm1): regression tests for tsmKeyPrefix comma delimitingpull/18824/head
parent
96d84b9126
commit
34ebc852c0
|
@ -348,6 +348,7 @@ func (e *Engine) fieldsPredicate(ctx context.Context, orgID influxdb.ID, bucketI
|
|||
|
||||
mt := models.Tags{models.NewTag(models.MeasurementTagKeyBytes, measurement)}
|
||||
tsmKeyPrefix := mt.AppendHashKey(orgBucketEsc)
|
||||
tsmKeyPrefix = append(tsmKeyPrefix, ',')
|
||||
|
||||
var canceled bool
|
||||
|
||||
|
@ -453,6 +454,7 @@ func (e *Engine) fieldsNoPredicate(ctx context.Context, orgID influxdb.ID, bucke
|
|||
|
||||
mt := models.Tags{models.NewTag(models.MeasurementTagKeyBytes, measurement)}
|
||||
tsmKeyPrefix := mt.AppendHashKey(orgBucketEsc)
|
||||
tsmKeyPrefix = append(tsmKeyPrefix, ',')
|
||||
|
||||
var stats cursors.CursorStats
|
||||
var canceled bool
|
||||
|
|
|
@ -532,6 +532,29 @@ memB,host=EB,os=macOS value=1.3 201`)
|
|||
exp: nil,
|
||||
expStats: cursors.CursorStats{ScannedValues: 0, ScannedBytes: 0},
|
||||
},
|
||||
{
|
||||
name: "prefix substring without predicate",
|
||||
args: args{
|
||||
org: 1,
|
||||
m: "cpu",
|
||||
key: "host",
|
||||
min: 0,
|
||||
max: 1000,
|
||||
},
|
||||
expStats: cursors.CursorStats{},
|
||||
},
|
||||
{
|
||||
name: "prefix substring with predicate",
|
||||
args: args{
|
||||
org: 1,
|
||||
m: "cpu",
|
||||
key: "host",
|
||||
min: 0,
|
||||
max: 1000,
|
||||
expr: `os = 'linux'`,
|
||||
},
|
||||
expStats: cursors.CursorStats{},
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
|
@ -793,6 +816,27 @@ mem,mem1=v,mem2=v f=1 201`)
|
|||
exp: nil,
|
||||
expStats: cursors.CursorStats{ScannedValues: 0, ScannedBytes: 0},
|
||||
},
|
||||
{
|
||||
name: "prefix substring without predicate",
|
||||
args: args{
|
||||
org: 0,
|
||||
m: "cp",
|
||||
min: 0,
|
||||
max: 1000,
|
||||
},
|
||||
expStats: cursors.CursorStats{},
|
||||
},
|
||||
{
|
||||
name: "prefix substring with predicate",
|
||||
args: args{
|
||||
org: 0,
|
||||
m: "cp",
|
||||
min: 0,
|
||||
max: 1000,
|
||||
expr: `cpu = 'v'`,
|
||||
},
|
||||
expStats: cursors.CursorStats{},
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(fmt.Sprintf("org%d/%s", tc.args.org, tc.name), func(t *testing.T) {
|
||||
|
@ -1066,6 +1110,29 @@ m10,foo=v barS="60" 501
|
|||
exp: nil,
|
||||
expStats: makeStats(0),
|
||||
},
|
||||
{
|
||||
name: "prefix substring without predicate",
|
||||
args: args{
|
||||
org: 0,
|
||||
m: "m0",
|
||||
min: 0,
|
||||
max: 1000,
|
||||
},
|
||||
exp: nil,
|
||||
expStats: makeStats(0),
|
||||
},
|
||||
{
|
||||
name: "prefix substring with predicate",
|
||||
args: args{
|
||||
org: 0,
|
||||
m: "m0",
|
||||
min: 0,
|
||||
max: 1000,
|
||||
expr: `tag10 = 'v10'`,
|
||||
},
|
||||
exp: nil,
|
||||
expStats: makeStats(0),
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(fmt.Sprintf("org%d/%s", tc.args.org, tc.name), func(t *testing.T) {
|
||||
|
|
|
@ -53,6 +53,7 @@ func (e *Engine) tagValuesNoPredicate(ctx context.Context, orgID, bucketID influ
|
|||
// append the measurement tag key to the prefix
|
||||
mt := models.Tags{models.NewTag(models.MeasurementTagKeyBytes, measurement)}
|
||||
tsmKeyPrefix = mt.AppendHashKey(tsmKeyPrefix)
|
||||
tsmKeyPrefix = append(tsmKeyPrefix, ',')
|
||||
}
|
||||
|
||||
// TODO(sgc): extend prefix when filtering by \x00 == <measurement>
|
||||
|
@ -181,6 +182,7 @@ func (e *Engine) tagValuesPredicate(ctx context.Context, orgID, bucketID influxd
|
|||
// append the measurement tag key to the prefix
|
||||
mt := models.Tags{models.NewTag(models.MeasurementTagKeyBytes, measurement)}
|
||||
tsmKeyPrefix = mt.AppendHashKey(tsmKeyPrefix)
|
||||
tsmKeyPrefix = append(tsmKeyPrefix, ',')
|
||||
}
|
||||
|
||||
var canceled bool
|
||||
|
@ -349,6 +351,7 @@ func (e *Engine) tagKeysNoPredicate(ctx context.Context, orgID, bucketID influxd
|
|||
// append the measurement tag key to the prefix
|
||||
mt := models.Tags{models.NewTag(models.MeasurementTagKeyBytes, measurement)}
|
||||
tsmKeyPrefix = mt.AppendHashKey(tsmKeyPrefix)
|
||||
tsmKeyPrefix = append(tsmKeyPrefix, ',')
|
||||
}
|
||||
|
||||
var keyset models.TagKeysSet
|
||||
|
@ -474,6 +477,7 @@ func (e *Engine) tagKeysPredicate(ctx context.Context, orgID, bucketID influxdb.
|
|||
// append the measurement tag key to the prefix
|
||||
mt := models.Tags{models.NewTag(models.MeasurementTagKeyBytes, measurement)}
|
||||
tsmKeyPrefix = mt.AppendHashKey(tsmKeyPrefix)
|
||||
tsmKeyPrefix = append(tsmKeyPrefix, ',')
|
||||
}
|
||||
|
||||
var canceled bool
|
||||
|
|
Loading…
Reference in New Issue