Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shrink time window incorrectly with overlaped data block #23354

Open
foobar opened this issue May 18, 2022 · 3 comments
Open

shrink time window incorrectly with overlaped data block #23354

foobar opened this issue May 18, 2022 · 3 comments

Comments

@foobar
Copy link
Contributor

foobar commented May 18, 2022

We are running influxdb 1.8 and have a single shard with 2TB TSM files. Recently some simple queries with 'ORDER BY TIME DESC' failed to return and hogged both cpu and memory resources.

I took time to investigate and found a possible bug when reading from overlapped data blocks, though following code has been there for around 6 years:

if cur.entry.MinTime < minT {
minT = cur.entry.MinTime
}

it's supposed to shrink the window but actually is expanding the window.
If a block has a long time range and it overlaps with many blocks with small time range, the bug causes lots of blocks being merged. The merge operation is expensive and might cause the function to run for a couple of hours.

Please confirm if my understanding is correct and I can send a PR to fix it.

@lesam lesam self-assigned this May 24, 2022
@philjb
Copy link
Contributor

philjb commented May 24, 2022

Hi @foobar - seems possible with a brief initial look. We'd welcome your PR as we continue to examine it ourselves. @lesam mentioned to me that the the logic may be incorrect (reserved) for narrowing the window for the maxT case too.

@lesam
Copy link
Contributor

lesam commented May 25, 2022

@foobar looking at this code, I think a better strategy to calculate the minT, maxT range to merge would be to just find the minimum minTime and the minimum maxTime (for ascending cursors), something like:

		for i := 0; i < len(c.current); i++ {
			cur := c.current[i]
			if cur.entry.MinTime < minT && !cur.read() {
				minT = cur.entry.MinTime
			}
			if cur.entry.MaxTime < maxT && !cur.read() {
				maxT = cur.entry.MaxTime
			}
		}

This is pretty deep stuff though, it would need a lot of careful testing before merge.

@foobar
Copy link
Contributor Author

foobar commented Jun 5, 2022

		for i := 0; i < len(c.current); i++ {
			cur := c.current[i]
			if cur.entry.MinTime < minT && !cur.read() {
				minT = cur.entry.MinTime
			}
			if cur.entry.MaxTime < maxT && !cur.read() {
				maxT = cur.entry.MaxTime
			}
		}

this looks good but seems it would make the same result as calling OverlapsTimeRange.
Anyway we need more testing and investigations.

@lesam lesam removed their assignment Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants