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

Partitions can end up out of order #25

Open
dpgil opened this issue Jul 13, 2021 · 2 comments
Open

Partitions can end up out of order #25

dpgil opened this issue Jul 13, 2021 · 2 comments

Comments

@dpgil
Copy link
Contributor

dpgil commented Jul 13, 2021

Let's say we have a storage instance with partition size = 2, and we insert rows at timestamp 1 and timestamp 3.

We then have a full partition with minTimestamp=1, maxTimestamp=3. On the next insert, a new partition will be created. When a new partition is created, the first time a row is inserted the minimum timestamp is set (code ref), so let's say we now insert a row at timestamp 2.

We'll now have two partitions with data points out of order. This breaks the query functionality as well.

@dpgil
Copy link
Contributor Author

dpgil commented Jul 13, 2021

One possible solution is by setting the min timestamp in the memory partition constructor, and letting the creator enforce the min timestamp to never be less than the max timestamp of the previous partition.

@nakabonne let me know if I'm missing anything with this. Also, do you think this is a real issue and is it worth working on?

@nakabonne
Copy link
Owner

@dpgil You're right. This is the issue that I've put off for a while. Basically most data points get timestamped on other programs, where timestamps are not always the same as the process tstorage runs on. Because of that, I presumed we don't determine the min timestamp until the first data point reached.

However, I was totally wrong. We can determine the next min timestamp by just incrementing to the previous max timestamp, a kind of like:

func (s *storage) ensureActiveHead() {
	head := s.partitionList.getHead()
	if head.active() {
		return
	}
	nextMin := head.maxTimestamp + 1

	// All partitions seems to be inactive so add a new partition to the list.
	p := newMemoryPartition(nextMin, s.wal, s.partitionDuration, s.timestampPrecision)

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

2 participants