Commit Graph

566 Commits (master)

Author SHA1 Message Date
Stuart Carnie 31df76e1e9
refactor(tsm1): Add TimeRangeMaxTimeIterator
This commit introduces a new API for finding the maximum
timestamp of a series when iterating over the keys in a
set of TSM files.

This API will be used to determine the field type of a single
field key by selecting the series with the maximum timestamp.

It has also refactored the common functionality for iterating
TSM keys into `timeRangeBlockReader`, which is shared
between `TimeRangeIterator` and `TimeRangeMaxTimeIterator`.
2020-04-08 16:05:19 -07:00
Jonathan A. Sternberg 6e4cf7ffef
refactor: fix imports from go template files (#17615) 2020-04-03 17:40:36 -05:00
Jonathan A. Sternberg 0ae8bebd75
refactor: rewrite imports to include the /v2 suffix for version 2 2020-04-03 12:39:20 -05:00
Stuart Carnie 069820ba4b
fix(models): Added error return value; use iota; fix spelling 2020-04-02 08:34:22 -07:00
Stuart Carnie d424d7d1f5
feat(tsdb): Add new measurement based schema APIs
These APIs require a measurement, permitting an additional optimization
to reduce the search space against the TSM index. Specifically, the
search key prefix is extended from `org+bucket` to
`org+bucket,\x00=<measurement>`

* MeasurementNames
* MeasurementTagKeys
* MeasurementTagValues
* Adds an api to the models package for efficiently parsing the
  measurement tag (\x00) from a normalized series key
2020-04-02 08:33:58 -07:00
Stuart Carnie 37a97437e7
fix: Invariant violated: mixed block types for a single series
The root cause is that the Unsigned data type has no representation
in the valueType function in the cache and falls back to the default
case of 0.

0 is also a sentinel value in the entry#add function that will
result in skipping the value type check.

It therefore is possible that unsigned values followed by some other
data type is stored in the cache.

It is suspected that the write may be rejected before reaching the
cache, and therefore may not occur in practice. Specifically, the
series file stores the data types on a per-series basis and would
reject the write.

This commit turns the value types into explicit constants and
ensures all existing block types are represented. In addition,
it adds a mapping function to convert these to a known Block type,
which will be used by the `MeasurementFields` schema request to
determine the type of a series in the cache.
2020-04-01 18:42:22 -07:00
Ben Johnson 7d72b4e511 feat(tsdb): Bulk delete series performance improvement 2020-03-18 15:47:35 -06:00
Edd Robinson d96cbd4f74
Merge pull request #17016 from influxdata/er-bulk-import
feat(storage): prototype 1.x–2.x migration tooling
2020-03-18 17:57:26 +00:00
Jacob Marble 679215de97
chore: Revert "refactor(tsdb): remove read from unexported field (#17279)" (#17305)
This reverts commit 0ec2b453b9.

Fixes panic.
2020-03-16 17:48:01 -07:00
Jacob Marble 0ec2b453b9
refactor(tsdb): remove read from unexported field (#17279)
* refactor(tsdb): remove read from unexported field

* fix(tsdb): add regression test to check for panic

* fix(tsdb): detect nil without panic
2020-03-16 14:26:14 -07:00
Jacob Marble 386098da36
refactor(storage): move and remove to help cleanup tsdb package (#17275)
* refactor(tsdb): move series file config to seriesfile package

* refactor(tsdb): removed unchecked const EOF

* refactor(tsdb): unexport errors

* refactor(tsdb): remove unused TagValueIterators

* refactor(tsdb): remove SeriesIDIterator usage in tsdb/seriesfile

* refactor(tsdb): remove one-use MeasurementIterators

* refactor(tsdb): remove unused type measurementSliceIterator

* refactor(tsdb): remove unused types TagKeyIterators and tagKeySliceIterator

* refactor(storage): remove unused method Engine.ApplyFnToSeriesIDSet

* refactor(tsdb): rename AllSeriesIDs() -> SeriesIDs()
2020-03-16 12:23:15 -07:00
Jacob Marble 7dbc07beda
chore: Revert "refactor(storage): move and remove to help cleanup tsdb package (#17241)" (#17272)
This reverts commit 4b8a71b97f.

Fixes incident #inc-aws-error-rate-spi-5e6c1423
2020-03-13 17:14:51 -07:00
Jacob Marble 4b8a71b97f
refactor(storage): move and remove to help cleanup tsdb package (#17241)
* refactor(tsdb): move series file config to seriesfile package

* refactor(tsdb): removed unchecked const EOF

* refactor(tsdb): unexport errors

* refactor(tsdb): remove unused TagValueIterators

* refactor(tsdb): remove SeriesIDIterator usage in tsdb/seriesfile

* refactor(tsdb): remove one-use MeasurementIterators

* refactor(tsdb): remove unused type measurementSliceIterator

* refactor(tsdb): remove unused types TagKeyIterators and tagKeySliceIterator

* refactor(storage): remove unused method Engine.ApplyFnToSeriesIDSet

* refactor(tsdb): remove read from unexported field
2020-03-13 13:04:58 -07:00
Edd Robinson 5b437a2966 refactor: fix build 2020-03-13 15:24:53 +00:00
Edd Robinson 08add490e0 fix: ensure buckets are created properly 2020-03-13 11:00:28 +00:00
Edd Robinson bbe40aeb82 feat: prototype 1.x - 2.x migration tool 2020-03-13 11:00:28 +00:00
Jacob Marble 26ca766459
refactor(tsdb): move series file to its own package (#17224)
* refactor(storage): move type ByTagKey to the only package that uses it

* refactor(tsdb): use types in tsdb/cursors

* refactor(tsdb): remove unused type SeriesIDElems

* refactor(tsdb): inline only use of tsdb.ReadAllSeriesIDIterator

* refactor(tsdb): move series file to its own package

* refactor(storage): remove platform->influxdb aliases
2020-03-12 11:32:52 -07:00
Jacob Marble cdbf532f57
refactor(storage): remove dead code and rename a few things (#17217)
* refactor(storage): remove CursorIterators type

* refactor(storage): remove unused tsdb.MarshalTags()

* refactor(storage): remove unused package tsdb/internal

* refactor(storage): rename tsdb/metrics.go to tsdb/series_file_metrics.go

* refactor(storage): remove unused type tagValueSliceIterator

* refactor(storage): rename field row to seriesRow

* refactor(storage): rename tsdb/index.go to tsdb/series_iterators.go
2020-03-12 10:45:48 -07:00
Jacob Marble b91e3f36ab
refactor(hll): remove unused Sketch interface (#17218) 2020-03-12 08:59:05 -07:00
Ben Johnson 627b6f86bb feat(storage): Series file compaction 2020-03-11 19:31:58 -06:00
Ben Johnson ce47e57089 fix(tsdb): Fix predicate clone 2020-02-04 10:12:26 -07:00
Jacob Marble b836ab9c17
feat(storage): implement backup and restore (#16504)
* feat(backup): `influx backup` creates data backup

* feat(backup): initial restore work

* feat(restore): initial restore impl

Adds a restore tool which does offline restore of data and metadata.

* fix(restore): pr cleanup

* fix(restore): fix data dir creation

* fix(restore): pr cleanup

* chore: amend CHANGELOG

* fix: restore to empty dir fails differently

* feat(backup): backup and restore credentials

Saves the credentials file to backups and restores it from backups.

Additionally adds some logging for errors when fetching backup files.

* fix(restore): add missed commit

* fix(restore): pr cleanup

* fix(restore): fix default credentials restore path

* fix(backup): actually copy the credentials file for the backup

* fix: dirs get 0777, files get 0666

* fix: small review feedback

Co-authored-by: tmgordeeva <tanya@influxdata.com>
2020-01-21 14:22:45 -08:00
Stuart Carnie 13a248a4fb
fix(tsm1): Add multiple unit tests to verify correctness
This commit adds numerous tests for ascending and descending cursors
that generate merged blocks across multiple files, which exceed the
default fixed buffer size used by the array cursors (MaxPointsPerBlock).

Tests cover two scenarios

1. Each file has one block and the block from the second file is
   entirely contained within the first block of the first file.
   When merging, the new block is 1200 values, which exceeds the
   MaxPointsPerBlock.

2. Each file has multiple blocks, and the blocks have a mixture of
   values which interleave and overwrite.
2020-01-19 22:53:58 -07:00
Edd Robinson 91551302f9 fix(storage): ensure all block data returned
This commit prevents multiple blocks for the same series key having
values truncated when they are being read into an empty buffer.

The current cursor reader code has an optimisation that incorrectly
assumes the incoming array will be limited to 1,000 values (the maximum
block size), but arrays can contain values from multiple matching
blocks.
2020-01-19 22:03:20 +00:00
Edd Robinson f11504b987 fix(storage): prevent infinite loop in matcher
Fixes #15817

This commit addresses a potential infinite loop, caused
by series keys that contain a certain pattern of escaped
characters.
2020-01-14 15:05:07 +00:00
Edd Robinson a06dc0fd7f fix(storage): prevent data-races on predicate
Fixes #15817

This commit addresses several data-races on the `tsm1.Predicate` type
that were causing a live-lock or similar in rare cases during a delete.

Because `tsm1/FileStore.Apply` executes concurrently across TSM files
the state of the delete's predicate was being unsafely mutated.

This commit adds a `Clone` method to the `influxdb.Predicate` type,
which should be used whenever an `influxdb.Predicate` implementation
needs to be used concurrently.
2020-01-09 10:00:25 +00:00
Jacob Marble 5f19c6cace
chore: Remove several instances of WithLogger (#15996)
* chore: Remove several instances of WithLogger

* chore: unexport Logger fields

* chore: unexport some more Logger fields

* chore: go fmt

chore: fix test

chore: s/logger/log

chore: fix test

chore: revert http.Handler.Handler constructor initialization

* refactor: integrate review feedback, fix all test nop loggers

* refactor: capitalize all log messages

* refactor: rename two logger to log
2019-12-04 15:10:23 -08:00
Edd Robinson 2f86815f83 fix(storage): ensure field is 64-bit aligned 2019-11-22 13:44:58 +00:00
Edd Robinson 7146af61b0 fix(storage): enable package to build on 32-bit arch 2019-11-22 12:55:20 +00:00
Edd Robinson 2471c2468c fix(storage): fixes panic when building predicates
Fixes #15916.

If a predicate was passed in with multiple key/value matches for the
same tag key, then the value index would be incorrect. This ensures that
each tag key can only be added to the location map once.
2019-11-15 15:07:36 +00:00
Edd Robinson 0dd2d38eac fix(tsi1): index defect with negated equality filters
Fixes #15859

This commit fixes a defect in the TSI index where a filter using the
negated equality operator would result in no matching series being
returned for series stored within the `IndexFile` portions of the index.

The root cause of this was due to missing legacy-handling code in the
index for this particular iterator.
2019-11-12 13:26:23 +00:00
George 3804d50fbd
fix(storage): array cursor iterator should return stats of all observed cursors (#15731)
* fix(storage): add failing test for array cursor iterator stats

* fix(storage): make arrayCursorIterator.Stats() return stats of in-focus cursor

* fix(storage): add failing test to assert arrayCursorIterator.Stats() returns accumulated result

* fix(storage): assumulate stats in arrayCursorIterator.Stats() call across all observed cursors
2019-11-05 10:41:06 +01:00
Christopher Wolff 04bc7bf76b test(tsdb): skip flaky test
https://github.com/influxdata/influxdb/issues/15220
2019-10-30 10:40:03 -07:00
Edd Robinson dc78d7c0eb
Merge pull request #14373 from zhulongcheng/add-missing-err
fix(tsdb): add missing err in SeriesPartition.Open
2019-10-24 13:13:32 +01:00
Edd Robinson 2727ae3c25 refactor: simpify Semaphore interface 2019-10-23 19:49:48 +01:00
Edd Robinson b6e911d72c refactor: move goroutine out to function 2019-10-23 19:49:46 +01:00
Edd Robinson 8f6701d4b1 feat(storage): add full compaction semaphore
By default this feature is disabled; the full compaction behaviour does
not change. When this feature is enabled compactions can be limited
across multiple storage engines running in multiple processes.

The mechanism by which this happens is not part of the abstraction added
here.
2019-10-23 19:45:01 +01:00
Edd Robinson ef1e15a0ad
Merge pull request #15318 from influxdata/er-mv-comp-limiter
feat(storage): allow compaction limiter to be injected into engine
2019-10-09 13:11:44 +01:00
Ilya Sevostyanov 596414a3ff
fix(storage): added missing string values for CacheStatus type.
Closes: #15284.
2019-10-04 23:50:21 +03:00
Edd Robinson 179c57ab2e feat(storage): allow compaction limiter to be injected 2019-10-04 12:35:21 -07:00
elbehery 663d4bb901 test(tasks): skip flaky test 2019-09-25 18:17:59 +02:00
elbehery c0b87c657c fix(storage): remove level=0 from TSM disk bytes metrics. 2019-09-25 15:57:25 +02:00
Lorenzo Affetti 053836e5a5
Merge pull request #15203 from influxdata/flux-staging-v0.48.x
build(flux): update to Flux v0.48.0
2019-09-20 18:24:02 +02:00
Edd Robinson d714be45a4
Merge pull request #15200 from influxdata/er-retention-service
refactor(storage): add more context to traces and logs
2019-09-20 09:00:00 +01:00
Lorenzo Affetti ab835c8e0e
refactor(dependencies): use new dependency injection framework (#15174)
refactor(dependencies): use new dependency injection framework
2019-09-19 17:01:17 +02:00
Edd Robinson e2f5b2bd9d refactor(storage): add more context to traces and logs 2019-09-19 13:48:06 +01:00
Stuart Carnie 9a89900785
fix(tsm1): Fix duplicate points
All seeks must be added to the c.current slice so the
min and max read values can be updated on each read pass.
2019-09-18 17:44:27 -07:00
Ben Johnson ee3cf79ae7
fix(tsdb): Fix pull request feedback. 2019-09-13 10:00:54 -06:00
Ben Johnson d08403b658
feat(tsdb): Add SQL export for TSI indexes 2019-09-13 10:00:54 -06:00
Mark Rushakoff c2f847299c ci: use latest staticcheck
We were still referring to megacheck in tools.go; this confused
dependent projects also using staticcheck.
2019-09-04 16:34:45 -07:00
Ben Johnson 9237ee6a40
fix(tsi1): Remove TSI cardinality stats cache 2019-09-04 14:48:22 -06:00
Edd Robinson 030083e1a3 perf(storage): optimistically check compactions 2019-09-04 17:38:13 +01:00
Ben Johnson 729558d64b
fix(tsdb): Replace TSI compaction wait group with counter.
Previously the TSI partition would panic if a compaction was
started while `Wait()` was waiting. This commit removes the previous
wait group and replaces it with a simple counter. The `Wait()`
function now polls the counter until it reaches zero.
2019-09-02 09:37:35 -06:00
Edd Robinson 7efb73930b refactor: address PR feedback 2019-08-30 21:07:32 +01:00
Edd Robinson 2e5ebbe251 perf(storage): reduce allocations when deleting from cache
When deleting from the cache, each cache key must be checked to
determine if it matches the prefix we're deleting. Since the keys are
stored as strings in the cache (map keys) there were a lot of allocations
happening because `applySerial` expects `[]byte` keys.

It's beneficial to reduce allocations by refacting `applySerial` to work
on strings. Whilst some allocations now have to happen the other way
(string -> []byte), they only happen if we actually need to delete the
key from the cache. Most of the keys don't get deleted so it's better
doing it this way.

Performance on the benchmark from the previous commit improved by ~40-50%.

name                                          old time/op    new time/op    delta
Engine_DeletePrefixRange_Cache/exists-24         102ms ±11%      59ms ± 3%  -41.95%  (p=0.000 n=10+8)
Engine_DeletePrefixRange_Cache/not_exists-24    97.1ms ± 4%    45.0ms ± 1%  -53.66%  (p=0.000 n=10+10)

name                                          old alloc/op   new alloc/op   delta
Engine_DeletePrefixRange_Cache/exists-24        25.5MB ± 1%     3.1MB ± 2%  -87.83%  (p=0.000 n=10+10)
Engine_DeletePrefixRange_Cache/not_exists-24    23.9MB ± 1%     0.1MB ±86%  -99.65%  (p=0.000 n=10+10)

name                                          old allocs/op  new allocs/op  delta
Engine_DeletePrefixRange_Cache/exists-24          305k ± 1%       28k ± 1%  -90.77%  (p=0.000 n=10+10)
Engine_DeletePrefixRange_Cache/not_exists-24      299k ± 1%        1k ±63%  -99.74%  (p=0.000 n=9+10)

Raw benchmarks on a 24T/32GB/NVME machine are as follows:

goos: linux
goarch: amd64
pkg: github.com/influxdata/influxdb/tsdb/tsm1
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     300	  50379720 ns/op	 3054106 B/op	   27859 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     300	  57326032 ns/op	 3124764 B/op	   28217 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     300	  58943855 ns/op	 3162146 B/op	   28527 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     300	  60565115 ns/op	 3138811 B/op	   28176 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     200	  59775969 ns/op	 3087910 B/op	   27921 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     300	  59530451 ns/op	 3120986 B/op	   28207 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     300	  59185532 ns/op	 3113066 B/op	   28302 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     300	  59295867 ns/op	 3100832 B/op	   28108 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     300	  59599776 ns/op	 3100686 B/op	   28113 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     200	  62065907 ns/op	 3048527 B/op	   27879 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     300	  44979062 ns/op	  123026 B/op	    1244 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     300	  44733344 ns/op	   52650 B/op	     479 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     300	  44534180 ns/op	   35119 B/op	     398 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     300	  45179881 ns/op	  105256 B/op	     706 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     300	  44918964 ns/op	   47426 B/op	     621 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     300	  45000465 ns/op	   63164 B/op	     564 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     300	  45332999 ns/op	  117008 B/op	    1146 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     300	  45652342 ns/op	   66221 B/op	     616 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     300	  45083957 ns/op	  154354 B/op	    1143 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     300	  44560228 ns/op	   65024 B/op	     724 allocs/op
PASS
ok  	github.com/influxdata/influxdb/tsdb/tsm1	1690.583s
2019-08-30 20:35:05 +01:00
Edd Robinson eba4dec7e6 perf(storage): reduce lock contention on Cache entries
The cache is essentially a set of maps, where a key in each map is a
series key, and the value is a slice of values associated with that key.
The cache is sharded and series keys are hashed to determine which shard
(map) they live in.

When deleting from the cache we have to check each key to see if it
matches the delete command (predicate and timestamp). If it does then
the entries for that range are removed. As part of this work we check if
the entries are already empty (already removed) and if so we don't check
if the key is valid.

This involved a lot of mutex grabbing, which has now been replaced with
atomic operations.

Benchmarking this commit against the previous commit in this branch
shows a 9% improvement:

name                                          old time/op    new time/op    delta
Engine_DeletePrefixRange_Cache/exists-24         113ms ± 8%     102ms ±11%   -9.40%  (p=0.000 n=10+10)
Engine_DeletePrefixRange_Cache/not_exists-24    95.6ms ± 2%    97.1ms ± 4%     ~     (p=0.089 n=10+10)

name                                          old alloc/op   new alloc/op   delta
Engine_DeletePrefixRange_Cache/exists-24        29.6MB ± 1%    25.5MB ± 1%  -13.71%  (p=0.000 n=10+10)
Engine_DeletePrefixRange_Cache/not_exists-24    24.3MB ± 2%    23.9MB ± 1%   -1.48%  (p=0.000 n=10+10)

name                                          old allocs/op  new allocs/op  delta
Engine_DeletePrefixRange_Cache/exists-24          334k ± 0%      305k ± 1%   -8.67%  (p=0.000 n=8+10)
Engine_DeletePrefixRange_Cache/not_exists-24      302k ± 1%      299k ± 1%   -1.25%  (p=0.000 n=10+9)

Raw benchmarks on a 24T / 32GB / NVME machine:

goos: linux
goarch: amd64
pkg: github.com/influxdata/influxdb/tsdb/tsm1
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     200	  91035525 ns/op	25557809 B/op	  305258 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     200	  99416796 ns/op	25385052 B/op	  303584 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     100	 100149484 ns/op	25570062 B/op	  305761 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     100	 100222516 ns/op	25474372 B/op	  303089 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     200	 101868258 ns/op	25531572 B/op	  304736 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     100	 106268683 ns/op	25648213 B/op	  306768 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     100	 102905477 ns/op	25572314 B/op	  305798 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     100	 108742857 ns/op	25483068 B/op	  304788 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     100	 103292149 ns/op	25401388 B/op	  303401 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     100	 107178026 ns/op	25573602 B/op	  305821 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     200	  95082692 ns/op	23942491 B/op	  299116 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     200	  96088487 ns/op	23957028 B/op	  298545 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     200	  94279165 ns/op	23620981 B/op	  294536 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     200	  94509000 ns/op	23989593 B/op	  299453 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     200	  98530062 ns/op	23935846 B/op	  299237 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     200	  98008093 ns/op	23821683 B/op	  297875 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     200	  97603172 ns/op	23878336 B/op	  298350 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     200	  96867920 ns/op	23782588 B/op	  296236 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     200	  99148908 ns/op	23997702 B/op	  299277 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     100	 100866840 ns/op	24019916 B/op	  300339 allocs/op
PASS
ok  	github.com/influxdata/influxdb/tsdb/tsm1	1144.213s
2019-08-30 20:35:05 +01:00
Edd Robinson da2fb27cb9 perf(storage): reduce amount of tracing
In a previous PR I added some tracing to help investigate delete
performance within the cache. Ironically this makes performance
significantly worse when you have a very high cardinality cache.

This keeps the main benefits of the tracing, but reduces the number of
spans created. The remaining spans are smarter with context, and include
useful information about the size of the operation being traced.

Performance on a benchmark shows a significant improvement:

name                                          old time/op    new time/op    delta
Engine_DeletePrefixRange_Cache/exists-24         262ms ± 6%     113ms ± 8%  -57.06%  (p=0.000 n=10+10)
Engine_DeletePrefixRange_Cache/not_exists-24     266ms ± 4%      96ms ± 2%  -64.09%  (p=0.000 n=8+10)

name                                          old alloc/op   new alloc/op   delta
Engine_DeletePrefixRange_Cache/exists-24        62.7MB ± 0%    29.6MB ± 1%  -52.82%  (p=0.000 n=9+10)
Engine_DeletePrefixRange_Cache/not_exists-24    59.2MB ± 0%    24.3MB ± 2%  -59.03%  (p=0.000 n=8+10)

name                                          old allocs/op  new allocs/op  delta
Engine_DeletePrefixRange_Cache/exists-24          711k ± 0%      334k ± 0%  -53.07%  (p=0.000 n=9+8)
Engine_DeletePrefixRange_Cache/not_exists-24      700k ± 0%      302k ± 1%  -56.79%  (p=0.000 n=8+10)

Raw benchmarks on a 24T/32GB/Nvme machine:

goos: linux
goarch: amd64
pkg: github.com/influxdata/influxdb/tsdb/tsm1
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     100	 104851012 ns/op	29442514 B/op	  333599 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     100	 107838824 ns/op	29485649 B/op	  334369 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     100	 108020671 ns/op	29443324 B/op	  333610 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     100	 106507506 ns/op	29977931 B/op	  338597 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     100	 116393032 ns/op	29443516 B/op	  333614 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     100	 112581877 ns/op	29691455 B/op	  334699 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      50	 119833106 ns/op	29444712 B/op	  333625 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	     100	 113851895 ns/op	29921119 B/op	  337419 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      50	 121735395 ns/op	29445551 B/op	  333634 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      50	 115387319 ns/op	29444513 B/op	  333627 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     100	  94474658 ns/op	24696698 B/op	  306702 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     100	  94767020 ns/op	24004763 B/op	  300066 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     100	  97869523 ns/op	24556560 B/op	  305827 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     100	  93916119 ns/op	24172163 B/op	  301244 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     100	  96591891 ns/op	24006021 B/op	  300081 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     100	  93521244 ns/op	24266467 B/op	  303190 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     100	  95419569 ns/op	24006501 B/op	  300087 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     100	  96694570 ns/op	24521126 B/op	  306041 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     100	  95075965 ns/op	24299409 B/op	  301649 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	     100	  97182864 ns/op	24007644 B/op	  300101 allocs/op
PASS
ok  	github.com/influxdata/influxdb/tsdb/tsm1	490.287s
2019-08-30 20:35:05 +01:00
Edd Robinson 15ade8c162 perf(storage): remeove erroneous variable
This commit removes an unused slice that was being built up. Comparting
to the base-line performance yields a slight improvement when deleting
from the cache.

name                                          old time/op    new time/op    delta
Engine_DeletePrefixRange_Cache/exists-24         268ms ± 5%     262ms ± 6%    ~     (p=0.218 n=10+10)
Engine_DeletePrefixRange_Cache/not_exists-24     265ms ± 5%     266ms ± 4%    ~     (p=0.965 n=10+8)

name                                          old alloc/op   new alloc/op   delta
Engine_DeletePrefixRange_Cache/exists-24        64.1MB ± 0%    62.7MB ± 0%  -2.16%  (p=0.000 n=9+9)
Engine_DeletePrefixRange_Cache/not_exists-24    59.2MB ± 0%    59.2MB ± 0%    ~     (p=0.505 n=8+8)

name                                          old allocs/op  new allocs/op  delta
Engine_DeletePrefixRange_Cache/exists-24          711k ± 0%      711k ± 0%  -0.00%  (p=0.000 n=9+9)
Engine_DeletePrefixRange_Cache/not_exists-24      700k ± 0%      700k ± 0%    ~     (p=0.687 n=8+8)

Raw benchmarks using a 24T / 32GB / NVME machine:

goos: linux
goarch: amd64
pkg: github.com/influxdata/influxdb/tsdb/tsm1
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      30	 267664312 ns/op	62689106 B/op	  711400 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      30	 255017152 ns/op	62688809 B/op	  711398 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      30	 258136039 ns/op	62689626 B/op	  711404 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      30	 273982453 ns/op	62688325 B/op	  711395 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      30	 252670795 ns/op	62688704 B/op	  711397 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      30	 277700985 ns/op	61801204 B/op	  702520 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      30	 272353886 ns/op	62688767 B/op	  711403 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      30	 258717468 ns/op	62689461 B/op	  711408 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      30	 252909070 ns/op	62688949 B/op	  711404 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      30	 255436837 ns/op	62689712 B/op	  711409 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 241173429 ns/op	59202122 B/op	  700036 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 247961098 ns/op	60507541 B/op	  714102 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      20	 263380230 ns/op	59202750 B/op	  700044 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 266035285 ns/op	59202758 B/op	  700043 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 266512878 ns/op	59202759 B/op	  700044 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 262065769 ns/op	59202726 B/op	  700043 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 270485538 ns/op	59202733 B/op	  700043 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 263355678 ns/op	62562757 B/op	  727794 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 260440337 ns/op	59203324 B/op	  700050 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 276122362 ns/op	59203316 B/op	  700050 allocs/op
PASS
ok  	github.com/influxdata/influxdb/tsdb/tsm1	259.435s
2019-08-30 20:35:05 +01:00
Edd Robinson f2d6c93e65 test: add benchmark to track cache deletion perf
Benchmarks using a 24T / 32GB / NVME disk machine:

goos: linux
goarch: amd64
pkg: github.com/influxdata/influxdb/tsdb/tsm1
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      20	 280039668 ns/op	64073374 B/op	  711421 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      30	 271810284 ns/op	64073207 B/op	  711420 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      30	 263464797 ns/op	64072589 B/op	  711415 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         		      30	 269460489 ns/op	64073344 B/op	  711420 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      30	 268319443 ns/op	64073947 B/op	  711425 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      30	 254945449 ns/op	64073463 B/op	  711421 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      30	 270202990 ns/op	65616337 B/op	  724440 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      30	 274113444 ns/op	64074764 B/op	  711435 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      30	 264234897 ns/op	64073748 B/op	  711428 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/exists-24         	      30	 264406196 ns/op	64073797 B/op	  711429 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 250130623 ns/op	59202124 B/op	  700036 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 255092042 ns/op	59552365 B/op	  706287 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 274121068 ns/op	59202753 B/op	  700043 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 273088065 ns/op	59202702 B/op	  700043 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 264184087 ns/op	59202724 B/op	  700043 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 268075364 ns/op	59202718 B/op	  700043 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 265067057 ns/op	59202709 B/op	  700043 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 254749976 ns/op	60118957 B/op	  701435 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 266953837 ns/op	59203376 B/op	  700051 allocs/op
BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24     	      30	 275083559 ns/op	59203329 B/op	  700050 allocs/op
PASS
ok  	github.com/influxdata/influxdb/tsdb/tsm1	261.273s
2019-08-30 20:35:05 +01:00
Max U 36d3a6ea82 refactor(tsi1): address comments to clean up tool 2019-08-23 14:08:00 -07:00
Max U 9fc99c2724 feat(tsi1): port the dump-tsi tool to 2.x 2019-08-23 14:07:30 -07:00
Nathaniel Cook 6f5c81f0dc feat(inspect): add verify-seriesfile to 2.x 2019-08-22 11:01:02 -07:00
Edd Robinson d160585a34 refactor(storage): add deeper tracing around deletes 2019-08-22 11:08:33 +01:00
Stuart Carnie 9964312bad
feat(cursors): Implement Size method so it doesn't panic
Returns the size (in bytes) of the associated array. Used by
the reads.ResponseWriter to estimate the size of buffered data.
2019-08-16 10:34:43 -07:00
Edd Robinson 9f3cbdc80e test(storage): add benchmark for series creation
This benchmark exercises creating (or checking if series need creating)
in the TSI index and the Series File.
2019-08-12 13:50:02 +01:00
Edd Robinson 396c6b0364 refactor(storage): ensure tests clean up 2019-08-12 13:49:52 +01:00
maxunt 62d1474442
Merge pull request #14246 from influxdata/mu-tsm-clean-14058
Clears tsm files when replace fails
2019-08-07 11:34:17 -07:00
maxunt 757fb4f80c
Merge pull request #14280 from influxdata/er-rename
feat(fs): API for replacing os calls
2019-08-07 11:33:57 -07:00
Edd Robinson a2fc43ff0c
Merge pull request #14470 from influxdata/mu-reportTSI-2.x
feat(tsi1): add report-tsi tool to 2.x
2019-08-07 19:30:58 +01:00
Max U ad188d6465 refactor(tsi1): remove extraneous logging 2019-08-05 13:21:13 -07:00
Max U 64747e9781 refactor(tsi1): address config changes to report-tsi tool 2019-08-05 10:03:32 -07:00
jlapacik 945f16ff4b docs(tsm1): TagKeys and TagValues return partial results with non-nil errors 2019-08-01 13:47:11 -07:00
jlapacik e7a0068e46 fix(tsm1): TagKeys/TagValues returns when context canceled 2019-08-01 13:47:11 -07:00
jlapacik 66662dca7f test(tsm1): TagKeys/TagValues stops scanning when context is canceled 2019-08-01 13:47:11 -07:00
Adam Perlin 4fef1683a0 refactor(tsi1): address review comments for report-tsi tool 2019-07-26 16:21:11 -07:00
Adam Perlin a0f4d714ea chore(tsi1): rename tsi1_report.go -> report.go 2019-07-26 11:17:02 -07:00
Adam Perlin d47a578258 fix(tsi1): map org to bucket in report-tsi tool so output is more useful 2019-07-26 11:17:02 -07:00
Adam Perlin 7ce1b8109f chore(tsi1): Clean up flags and naming in report-tsi tool; add comments 2019-07-26 11:16:59 -07:00
Max U 9bd6200f15 fix(tsi1): make mergeable 2019-07-26 11:16:12 -07:00
Max U 2c1f3e2987 fix(tsi1): remove obnoxious log messages 2019-07-26 11:16:12 -07:00
Max U 17b1dd8562 feat(tsi1): add shorthand for --top flag as -t, plus cleaning 2019-07-26 11:12:15 -07:00
Max U aa2f7a8ff7 feat(tsi1): add a --top flag for limiting output, output now sorted 2019-07-26 11:12:15 -07:00
Adam Perlin 32b283d25a feat(tsi1/report): Add ability to filter by measurement; add additional maps for efficient retrieval of total org/bucket cardinalities 2019-07-26 11:12:15 -07:00
Max U 5e5fa96c5b feat(tsi1): add flags for --org-id and --bucket-id 2019-07-26 11:12:15 -07:00
Max U bfd38d93d8 feat(tsi1): provide API tooling for use in testing 2019-07-26 11:12:15 -07:00
Max U 8f99d20deb feat(tsi1): port report-tsi tool to influxdb 2.x 2019-07-26 11:12:15 -07:00
Max U eb6d0f4478 feat(tsi): report cardinality for all indexes, still needs to be cleaned
Fix iteration logic and clean up
2019-07-26 11:12:00 -07:00
Max U 36e578122e feat(tsi): placeholder 2019-07-26 11:11:22 -07:00
Max U 41cc23cc35 fix(tsi1): clean up some error checking 2019-07-26 11:10:47 -07:00
Max U b9ede87508 fix(tsi): error trace for engine failure, not working 2019-07-26 11:09:40 -07:00
zhulongcheng fc1dc37886 fix(tsdb): add missing err in SeriesPartition.Open
Signed-off-by: zhulongcheng <zhulongcheng.me@gmail.com>
2019-07-26 10:48:32 +08:00
Max U 550da3c5a5 fix(fs): merge branch 'master' into HEAD 2019-07-25 10:23:48 -07:00
Edd Robinson ce3f58d9f0
Merge pull request #13787 from zhulongcheng/KeyCursor-overlapping
fix(tsm1): check if blocks are overlapping in KeyCursor.Next
2019-07-24 15:36:39 +01:00
tmgordeeva 48ee7ada04
fix(storage): move retention snapshot out of per bucket calls (#14420)
* fix(storage): move retention snapshot out of per bucket calls

Also adds tracking for snapshots from retention and full compactions.
2019-07-23 11:40:05 -07:00
Max U 979c075931 Merge branch 'master' into HEAD 2019-07-22 10:21:59 -07:00
kelwang 1d56544587
Merge pull request #14263 from zhulongcheng/keyRange
fix(storage): add key field to keyRange
2019-07-15 22:46:39 -04:00
Stuart Carnie 00561d5a1b
feedback: Move verify routines to `tsm1` package for consistency
Should have left it there to begin with 🤣
2019-07-09 09:00:41 +10:00
Stuart Carnie 46952afe37
feat(influxd): New influxd verify tsm-blocks command
This command performs verification of TSM blocks

* expected and actual CRC-32 checksums match
* expected and actual min and max timestamps match decoded
  data
2019-07-09 09:00:41 +10:00
Max U fe2aceb5e4 Merge branch 'master' into mu-tsm-clean-14058 2019-07-08 15:19:41 -04:00
Max U 6f14314e97 change log level from info to error 2019-07-08 14:49:14 -04:00
Max U 2202d727da fixes merge conflicts 2019-07-08 14:07:04 -04:00
maxunt ca5a599261
Merge branch 'master' into er-rename 2019-07-08 13:42:24 -04:00
Max U 39f51969e9 replaced os.Create calls w API calls to fs.CreateFile, includes unit test 2019-07-08 13:01:42 -04:00
Edd Robinson 12f2eeda1f fix(storage): ensure query range is (start, stop] 2019-07-05 17:10:56 +01:00
zhulongcheng 94d4c846a8 fix(storage): add key field to keyRange
Signed-off-by: zhulongcheng <zhulongcheng.me@gmail.com>
2019-07-05 00:14:19 +08:00
Ben Johnson 150165e92f
fix(tsdb): Fix tsm1 block merge. (#14254)
fix(tsdb): Fix tsm1 block merge.
2019-07-04 08:35:43 -06:00
Max U 948f04ef8d allow for compaction to same file with fs api 2019-07-03 14:28:27 -04:00
Max U c669a32ff3 change fs.RenameFile to fs.RenameFileWithReplacement when compacting partition stats files as they must go to the same place 2019-07-03 14:23:21 -04:00
Max U fe748128e3 replaces os.Rename calls w api calls to fs.RenameFile. tests now are failing 2019-07-03 13:14:43 -04:00
Ben Johnson 10a2063dcc
fix(tsdb): Fix tsm1 block merge.
Fixes the `tsm1.BlockIterator` so that it returns the current
key if there are still additional entries remaining. This previously
caused multiple entries not to be merged together during compaction
because the iterator would check if the next key matched the current
key but the key for the next set of entries was returned.
2019-07-03 10:08:51 -06:00
Stuart Carnie a42ff1628d
fix(influxd): --pattern flag matches specified substring
Previously the logic was inverted so `--pattern` matched
everything but the specified value.
2019-07-03 12:02:19 +10:00
Max U af257e93ff initial commit for clearing tsm files when replace fails 2019-07-02 13:48:31 -04:00
Ben Johnson 08e24faf4c
feat(tsdb): Add block exporter.
Adds export tooling to `influxd inspect export-blocks` so that we
can dump out block data in SQL format for better analysis during
the debugging process.
2019-07-01 10:10:52 -06:00
Tanya Gordeeva fe4333e8e0 fix(storage): fix tracking disk bytes in memory 2019-06-27 16:36:00 -07:00
Tanya Gordeeva 3ff15a8b41 fix(storage): fix counts for level 4+ files
The counts wreen't adding all the level 4+ files, so the last one to be counted
would override the rest.
2019-06-27 16:36:00 -07:00
Ben Johnson b3d7986d4b
chore(tsdb): Fix read metrics declaration. 2019-06-27 09:25:27 -06:00
Ben Johnson 12549c859e
feat(tsdb): Add basic tsdb read metrics
Adds a total cursor counter and seek location counter to a new
`readMetrics` that is added to each `Engine`. Default labels group
by `engine_id` and `node_id`.
2019-06-26 16:16:24 -06:00
tmgordeeva fb69c5d06c
Merge pull request #13698 from influxdata/tg-fix-metrics
fix(storage): reduce tsm level metrics cardinality
2019-06-20 17:57:37 -07:00
Tanya Gordeeva 6428cdbce6 fix(storage): initialize tsm file metrics, update after compaction
These metrics weren't being properly intialized on opening the file store, and
weren't being properly updated on compaction.
2019-06-20 14:37:53 -07:00
Tanya Gordeeva 85dc52a93b fix(storage): reduce tsm level metrics cardinality
This should have cut off TSM file levels at 4+.
2019-06-20 14:37:33 -07:00
Ben Johnson 14980d55b8
fix(storage): Add WithCurrentGenerationFunc() for generation injection.
Adds the ability to set the current generation to use when compacting
the cache only. Previously, we used the current generation for all
files but this causes issues and we should only use the current
generation for level 1 compaction.
2019-06-20 08:54:38 -06:00
Ben Johnson a181e60d70
fix(tsdb): Fix series file count (#13770)
fix(tsdb): Fix series file count
2019-06-11 10:07:12 -06:00
Christopher Wolff a82e2cb180 chore(tsdb): skip flaky test 2019-05-30 16:29:31 -07:00
Alirie Gray 576da8f9d2 fix(swagger): add log property to task runs endpoint docs 2019-05-17 14:08:10 -07:00
Nathaniel Cook faa5fddf7b Merge branch 'master' into flux-staging 2019-05-15 10:12:14 -06:00
Christopher Wolff 52a98aae2b chore(tsdb): skip flaky test
https://github.com/influxdata/influxdb/issues/13755
2019-05-14 12:52:37 -07:00
Jacob Marble 95f28cb571
fix(series file): Sync series segment after truncate (#13836) (#13859) 2019-05-10 11:25:43 -07:00
Jacob Marble aa5c77409d
backport: Fix open/close race in SeriesFile (#13837) 2019-05-08 11:39:24 -07:00
zhulongcheng fbd6e9f5c4 fix(tsm1): check if blocks are overlapping in KeyCursor 2019-05-04 22:25:09 +08:00
Edd Robinson 3588c0505e fix(storage): don't remap renamed TSM file
There exists a possibility for an in-flight read on a TSMReader to read
a stale reference to an mmapped TSM file index, which has become
unmapped.

This commit resolves that issue by simply renaming the file, leaving the
original file handler open and the data mapped. The path is updated so
that if any callers need to refer to the name of the TSM file after it's
renamed, the new name will be reflected.

The orphaned file handler will be closed when the TSM file is closed.
2019-05-03 22:36:35 +01:00
Ben Johnson a5ccf5ce9a
fix(tsdb): Fix series file count
Previously the series file did not include tombstones in the total
count. This commit now includes tombstones in the count as well as
fixes an issue where replayed tombstone records could exist but
their underlying ID did not exist. This caused the count to become
negative and with the count being `uint64` it caused the count to
rollover to `math.Uint64Max`.
2019-05-03 09:58:13 -06:00
Jeff Wendling ef0768db31
tsm1: predicate deletes (#13371)
tsm1: predicate deletes
2019-05-03 14:27:25 +00:00
Stuart Carnie bf774b66ce
fix(storage): Ensure Tag(Keys|Values) APIs never return (nil, nil)
Formalized this post condition in the documentation and added additional
unit tests.

Added a nil guard and unit test to WriteStringIterator.
2019-05-02 09:45:38 -07:00
Jeff Wendling 16e9eb4cb9 tsdb: respond to feedback and improve test coverage
predicate.go:
	UnmarshalPredicate       100.0%
	NewProtobufPredicate     100.0%
	Matches                  100.0%
	Marshal                  100.0%
	walkPredicateNodes       100.0%
	buildPredicateNode       100.0%
	newPredicateState        100.0%
	Reset                    100.0%
	Set                      100.0%
	newPredicateCache        100.0%
	Cached                   100.0%
	Store                    100.0%
	Update                   100.0%
	Update                   92.9%
	Update                   94.1%
	predicateEval            90.9%
	predicatePopTag          100.0%
	predicatePopTagEscape    100.0%
2019-05-01 13:40:40 -06:00
Jeff Wendling 4b4a814d7d storage: fix predicate matching on field tags 2019-05-01 13:40:40 -06:00
Jeff Wendling 740d669514 tsm1: teach the cache about predicates 2019-05-01 13:40:40 -06:00
Jeff Wendling 4fb7bf1730 tsm1: implement predicate matcher from protobufs 2019-05-01 13:40:40 -06:00
Jeff Wendling 4096f93891 tsm1: implement reading and writing predicates in tombstone files 2019-05-01 13:40:40 -06:00
Jeff Wendling dcf797f111 tsm1: basic predicate implementation at index layer
Only wires it up. No tests, no tombstone tracking, nothing.
2019-05-01 13:40:40 -06:00
Jeff Wendling 7403fd8aa9 tsm1: rename engine method to DeletePrefixRange
The storage/engine knows about buckets, but the tsm1/engine doesn't, so
name the tsm1/engine method Prefix and keep the storage/engine named
Bucket.
2019-05-01 13:40:40 -06:00
Jacob Marble 8c269e0153
chore(log): Put trace_id back in logs (#13712)
* chore(log): Put trace_id back in logs

* fix tests
2019-04-30 18:51:22 -07:00
Stuart Carnie 65e4e3c5de
Merge pull request #13701 from influxdata/sgc/bp/2.x/13687
Don't panic when encoding string blocks and length of source slice is too large
2019-04-30 10:02:40 -07:00
Stuart Carnie 369a4610e6
fix(storage): Don't panic when length of source slice is too large
StringArrayEncodeAll will panic if the total length of strings
contained in the src slice is > 0xffffffff. This change adds a unit
test to replicate the issue and an associated fix to return an error.

This also raises an issue that compactions will be unable to make
progress under the following condition:

* multiple string blocks are to be merged to a single block and
* the total length of all strings exceeds the maximum block size that
  snappy will encode (0xffffffff)

The observable effect of this is errors in the logs indicating a
compaction failure.

Fixes #13687
2019-04-29 13:29:41 -07:00
Jeff Wendling 9cd7c0f7e3 tsi1: don't do verbose debug logging unless test fails 2019-04-29 14:01:45 -06:00
Stuart Carnie 7b97a41dcb
feat(storage): Teach TagKeys, TagValues how to accumulate statistics
This commit teaches the storage schema APIs how to track statistics
and make them available via the returned `cursors.StringIterator`.

Statistics are only tracked when decoding TSM blocks or when scanning
the in-memory cache.

Closes #13541
2019-04-24 11:14:22 -07:00
Stuart Carnie ed344d25f8
feat(storage): Teach storage how to find a distinct set of tag keys
The TagValues API will perform a linear scan if there is no predicate;
otherwise, it will use the index to find a list of candidate series
keys.

TagKeys expects the predicate to be transformed such that
`_measurement` and `_field` are remapped to `\x00` and `\xff`
respectively.

There is one TODO marked to analyze the predicate for a
`\x00 = '<measurement>'` pattern. If found, the predicate can be
eliminated and fall back to a linear prefix scan by combining the org,
bucket and measurement. This is tracked by issue #13497.
2019-04-24 11:14:22 -07:00
Ben Johnson 272f340c30
Merge point parse & explode. 2019-04-24 10:12:15 -06:00
Jeff Wendling 59279837e5 tsi1: partition close deadlock
When a tsi1 partition closes, it waits on the wait group for compactions
and then acquires the lock. Unfortunately, a compaction may start in the
mean time, holding on to some resources. Then, close will attempt to
close those resources while holding the lock. That will block until
the compaction has finished, but it also needs to acquire the lock
in order to finish, leading to deadlock.

One cannot just move the wait group wait into the lock because, once
again, the compaction must acquire the lock before finishing. Compaction
can't finish before acquiring the lock because then it might be operating
on an invalid resource.

This change splits the locks into two: one to protect just against
concurrent Open and Close calls, and one to protect all of the other
state. We then just close the partition, acquire the lock, then free
the resources. Starting a compaction requires acquiring a resource
to the partition itself, so that it can't start one after it has
started closing.

This change also introduces a cancellation channel into a reference
to a resource that is closed when the resource is being closed, allowing
processes that have acquired a reference to clean up quicker if someone
is trying to close the resource.
2019-04-22 09:06:32 -06:00
Tanya Gordeeva 97572ee878 feat(storage): add tsm level metrics
Adds prometheus metrics recording compaction levels for TSM files.
2019-04-19 13:33:52 -07:00
Stuart Carnie d5341a1a4a
feedback: Fix comments in template 2019-04-18 16:19:19 -07:00
Stuart Carnie 972cda1775
feedback: Changes in response to PR feedback 2019-04-18 16:19:18 -07:00
Stuart Carnie 904c91aecc
chore: Fix staticcheck complaints 2019-04-18 16:19:18 -07:00
Stuart Carnie d3790aa072
feat: Teach storage engine how to find tag values for a given key
The TagValues API will perform a linear scan if there is no predicate;
otherwise, it will use the index to find a list of candidate series
keys.

TagValues expects the predicate to be transformed such that
`_measurement` and `_field` are remapped to `\x00` and `\xff`
respectively.

There is one TODO marked to analyze the predicate for a
`\x00 = '<measurement>'` pattern. If found, the predicate can be
eliminated and fall back to a linear prefix scan by combining the org,
bucket and measurement.
2019-04-18 16:19:18 -07:00
Stuart Carnie 35e0094a28
feat: TimeRangeIterator for checking if keys have data in a TSM file
The TimeRangeIterator permits linear or random index scans and
can answer whether the current key has data for the specified time
interval, considering any tombstones.

When there are no tombstones there are some opportunities for
optimization to skip decoding blocks. Specifically, if the
queried time interval overlaps any boundaries of the TSM index entries.
2019-04-18 16:19:18 -07:00
Stuart Carnie 7544ea0a5b
feat: Teach Values how to determine it contains data for a time interval
Add a Contains API which is a peer to the TimestampArray.Contains
function. This is used by the schema APIs to determine if data exists
in the cache for a given key and time interval.
2019-04-18 16:19:18 -07:00
Stuart Carnie 1ddd0445d8
feat(tsm1): Add Seek API to TSMIndexIterator
Permits random access of the iterator, correctly maintaining state,
so that Next may be called to iterator from a given key.

This API will be used by the schema APIs when a predicate is specified,
typically requiring random access.
2019-04-18 16:19:18 -07:00
Stuart Carnie 36a33bcb9f
feat(tsdb): Teach storage how to only decode timestamps from a block
TimestampArray.Contains(min,max) API performs a binary search to
determine if timestamps exist for the given time interval.

It also implements Exclude to drop timestamps that have been tombstoned.

DecodeTimestampArrayBlock decodes only the timestamps of the provided
block.
2019-04-18 16:19:18 -07:00
Stuart Carnie 7fc9661b7b
chore: Move StringIterator to cursors package for wider reuse 2019-04-18 16:19:17 -07:00
Stuart Carnie e74f2f8e08
chore(cursors): Remove unused field 2019-04-18 16:19:17 -07:00
Stuart Carnie d67b1ef245
fix(cursors): Add go:generate directive 2019-04-18 16:19:17 -07:00
Todd Persen 138c17f22c Fix typos in tsdb package 2019-04-17 12:55:38 -07:00
Ben Johnson 2b3ce82852
fix(tsdb): Remove TSI stats file cache
Removes the `STATS` file generated during TSI compaction as it had
potential for becoming inconsistent with the index data. Instead,
stats are recalculated on start up and on each compaction on a
per-partition basis.

Computing stats for 10M series across 10K measurements takes
approximately 0.171s.
2019-04-17 09:34:32 -06:00
Jacob Marble f56c42794b
chore(tracing): Cleanup (#13296)
* chore(tracing): Cleanup

* broken test

* fix unused var

* fix test
2019-04-10 19:28:21 -07:00
Ben Johnson 307bb6af9c
Improve bulk series file writes. 2019-04-05 14:38:58 -06:00
Jeff Wendling 96a01eecf2 change an inaccurate comment 2019-03-30 10:24:15 -06:00
Jeff Wendling cbefaeb7f5 tsm1: make cache limit error a type
This makes it easier and more robust to check if an error is due
to the cache memory limit being exceeded.
2019-03-30 10:24:15 -06:00
Jeff Wendling 647deb475c tsm1: move cache entry to its own file 2019-03-30 10:24:15 -06:00
Jeff Wendling fad1e07d1d tsm1: clean up some dead/useless code in the cache
The storer interface isn't necessary if the init/Free logic is
removed, which is unnecessary in a world with only one shard.
Additionally, there were some cases where an init/Free call could
race and cause data loss in the cache. Not doing it at all fixes
all of those races.
2019-03-30 10:24:15 -06:00
Jeff Wendling 591e94dad9 tsm1: rings are fixed at 16 partitions
The code actually didn't work if 16 wasn't passed. Indeed, the
benchmarks weren't even working. Fix up all that, and reduce
the complexity some.
2019-03-30 10:24:15 -06:00
Jonas Hahnfeld 89ced057cb Fix compaction logic on infrequent cache snapshots
This change fixes #10511 that manifests when a shard is considered cold
faster than its cache is snapshotted. Previously the code only looked at
the last modification of compacted tsm1 files. Instead the (restored)
Engine.lastModified() also takes the cache into account.

Ports #10522 to master where engine.go has moved and Engine.LastModified()
was deleted because it was unused.
2019-03-28 22:21:59 +01:00
Edd Robinson 9a42202b53 PR feedback 2019-03-26 09:57:01 +00:00
Edd Robinson aa4e652e43 Add reason to total compaction metric
This commit adds a reason label to the total compaction metric. For
snapshots, the reason will indicate why the cache was snapshotted. For
other compactions, the reason label will be blank.
2019-03-25 15:25:03 +00:00
Edd Robinson dbca30dac5 Add integration tests for cache snapshotting 2019-03-25 11:44:01 +00:00
Edd Robinson 55e9ed689f Allow the tsm1.Cache to be snapshotted due to age
This commit adds a new Cache option, via the
`tsm1.CacheConfig.SnapshotAgeDuration` field, which controls the maximum
age the cache can reach before it is snapshotted to a TSM file.

The default value for this option is `0`, which means that the cache
will never be snapshotted based only on age. Setting this value to, for
example, 10 seconds, would result in the cache snapshotting every 10
seconds.

Snapshotting the cache more frequently can provide better durability
guarantees in some circumstances, though more, smaller TSM files will
lead to more work needed to compact them down to larger, more dense
files.

When using InfluxDB with a WAL there isn't really a strong reason to
alter `tsm1.CacheConfig.SnapshotAgeDuration` from `0`.
2019-03-25 11:44:01 +00:00
Edd Robinson af3f7bc9cb Add new cache configuration value 2019-03-25 11:44:01 +00:00
Edd Robinson 4022db03c2 Provide explicit cache snapshot reasons 2019-03-25 11:44:01 +00:00
Edd Robinson c4cc3ca7bc Fix 2019-03-19 15:12:35 +00:00
Edd Robinson f383ec9225 Add ability to use report-tsm programmatically 2019-03-19 14:29:25 +00:00
Edd Robinson 3b39832ba5 Reduce garbage 2019-03-19 14:28:51 +00:00
Edd Robinson a6447b6ca5 Refactor tsm report for 2.0 2019-03-19 14:25:53 +00:00
Edd Robinson fdae1ae5ea Expose field key sep 2019-03-19 14:25:53 +00:00
zhulongcheng a33c325890 storage: pr review changes 2019-03-12 22:15:28 +08:00
zhulongcheng 2554f1c5dd storage: add SeriesOffsetSize constant 2019-03-12 10:51:22 +08:00
Jacob Marble 603a1f26e0 use tracing.StartSpanFromContext 2019-03-07 12:12:31 -07:00
Edd Robinson 582ed6834c ddress PR feedback 2019-03-07 09:56:07 +00:00
Edd Robinson 1cb20b654d ExplodePoints now complies with new keys 2019-03-07 09:56:07 +00:00
Edd Robinson f029f1645d Change location and value for internal tag keys 2019-03-07 09:56:07 +00:00
Jeff Wendling f53f9cd949 storage: detect conflicting types in a single batch of points
When the WAL was moved up, the validation that happened at the cache
was skipped. This moves the field type validation for a batch of
points up ahead of the WAL again.
2019-03-06 10:30:52 -07:00
Jacob Marble b9c7ec439e
feat(influxd): Tracing refactor (#12318)
* feat(launcher): Tracing to log disabled by default

* remove traceLogger and use opentracing directly

* add Jaeger tracing

* go vet && go fmt
2019-03-04 11:48:11 -08:00
Jeff Wendling 052421d5d6
Merge pull request #12207 from influxdata/jmw-fix-resource-ownership
storage: fix problems with keeping resources alive
2019-03-04 10:58:46 -07:00
Ben Johnson 12d35f1a50
Revert "Merge point parse & explode."
This reverts commit 1004abc3e1.
2019-03-02 06:23:04 -07:00
Ben Johnson 1004abc3e1
Merge point parse & explode. 2019-03-01 15:55:37 -07:00
Jeff Wendling ef425b7bf9 tsdb: fix disabling metrics in the series index
During Recover, we forgot to propagate the disabled flag to the
keyIDMap options like we do during Open. Since we still do propagate
the singleton `ims` which is initialized lazily, if the first
initialization has a different set of labels, it will cause an
inconsistent usage even if the metrics are disabled.
2019-03-01 12:11:16 -07:00
Jeff Wendling 0fae44e219 storage: fix problems with keeping resources alive
This commit adds the pkg/lifecycle.Resource to help manage opening,
closing, and leasing out references to some resource. A resource
cannot be closed until all acquired references have been released.
If the debug_ref tag is enabled, all resource acquisitions keep
track of the stack trace that created them and have a finalizer
associated with them to print on stderr if they are leaked. It also
registers a handler on SIGUSR2 to dump all of the currently live
resources.

Having resources tracked in a uniform way with a data type allows us
to do more sophisticated tracking with the debug_ref tag, as well.
For example, we could panic the process if a resource cannot be
closed within a certain time frame, or attempt to figure out the
DAG of resource ownership dynamically.

This commit also fixes many issues around resources, correctness
during error scenarios, reporting of errors, idempotency of
close, tracking of memory for some data structures, resource leaks
in tests, and out of order dependency closes in tests.
2019-02-28 10:22:01 -07:00
Jacob Marble 4e5253d581
Feat/add zeros to tsm filename (#12174)
* unit tests to confirm The Old Way®

* feat: Increase TSM generation max value to 1 trillion
2019-02-27 14:59:38 -08:00
zhulongcheng 4f9f85de84 tsdb: cleanup shard errors 2019-02-18 21:25:30 +08:00
Jeff Wendling 26ca30e97a Ensure that cached series id sets are Go heap backed 2019-02-12 16:33:35 -07:00
Ben Johnson cf29b6bca4
Convert TagValueSeriesIDCache to use string fields 2019-02-12 14:45:38 -07:00
Edd Robinson 0858b2570d Rename --> RenameFileWithReplacement for clarity 2019-02-12 12:41:10 +00:00
Edd Robinson bd8a167a3e Rename file package to fs 2019-02-12 11:24:11 +00:00