Merge pull request #18664 from influxdata/storage-engine-write-validation-enabled

feat(storage): Add option to disable WritePoints() validation.
pull/18705/head
Ben Johnson 2020-06-24 08:43:29 -06:00 committed by GitHub
commit 50efc73210
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 32 deletions

View File

@ -3230,3 +3230,11 @@ func BenchmarkParsePointsWithOptions(b *testing.B) {
})
}
}
func BenchmarkValidToken(b *testing.B) {
token := []byte("Hello世界")
b.ReportAllocs()
for i := 0; i < b.N; i++ {
models.ValidToken(token)
}
}

View File

@ -64,6 +64,8 @@ type Engine struct {
defaultMetricLabels prometheus.Labels
writePointsValidationEnabled bool
// Tracks all goroutines started by the Engine.
wg sync.WaitGroup
@ -156,6 +158,13 @@ func WithCompactionSemaphore(s influxdb.Semaphore) Option {
}
}
// WithWritePointsValidationEnabled sets whether written points should be validated.
func WithWritePointsValidationEnabled(v bool) Option {
return func(e *Engine) {
e.writePointsValidationEnabled = v
}
}
// NewEngine initialises a new storage engine, including a series file, index and
// TSM engine.
func NewEngine(path string, c Config, options ...Option) *Engine {
@ -164,6 +173,8 @@ func NewEngine(path string, c Config, options ...Option) *Engine {
path: path,
defaultMetricLabels: prometheus.Labels{},
logger: zap.NewNop(),
writePointsValidationEnabled: true,
}
// Initialize series file.
@ -482,6 +493,8 @@ func (e *Engine) WritePoints(ctx context.Context, points []models.Point) error {
}
for iter := collection.Iterator(); iter.Next(); {
// Skip validation if it has already been performed previously in the call stack.
if e.writePointsValidationEnabled {
tags := iter.Tags()
// Not enough tags present.
@ -522,6 +535,7 @@ func (e *Engine) WritePoints(ctx context.Context, points []models.Point) error {
dropPoint(iter.Key(), fmt.Sprintf("key contains invalid unicode: %q", iter.Key()))
continue
}
}
collection.Copy(j, iter.Index())
j++