BTrDB / btrdb-server

Berkeley Tree Database (BTrDB) server
http://btrdb.io
MIT License
909 stars 66 forks source link

Aligned Window Query Start/End Inclusivity is Inconsistent #45

Closed samkumar closed 7 years ago

samkumar commented 7 years ago

When BTrDB receives an aligned windows query, it rounds the start/end timestamps down to the nearest point boundary.

If pw < 32, it returns all points from start (inclusive) to end (exclusive), after rounding down. If pw >= 32, it returns all points from start (inclusive) to end (inclusive), after rounding down.

I believe this is a bug. This causes rendering artifacts in the WaveViewer plotter.

The following Python3 script reproduces this issue (I've emailed this to Michael). All timestamps used are point-aligned, so the rounding down behavior isn't tested.

#!/usr/bin/env python3
import btrdb4
import time
import uuid

uu = uuid.UUID("80741975-8247-4d12-9b73-becf9eb8ff31")

conn = btrdb4.Connection("compound-3.cs.berkeley.edu:4410")
b = conn.newContext()

print("Connected to compound-3.cs.berkeley.edu:4410")

s = b.streamFromUUID(uu)
assert(s.exists())

print("All of the endpoints of these queries are pointwidth-aligned.")

print()
print("Making a query at pw=31 from 1458040387951132672 to 1458040396541067264")
for statpoint, version in s.alignedWindows(1458040387951132672, 1458040396541067264, 31):
    print(statpoint)

print()
print("Making a query at pw=31 from 1458040387951132672 to 1458040398688550912")
for statpoint, version in s.alignedWindows(1458040387951132672, 1458040398688550912, 31):
    print(statpoint)

print()
print("The above two queries show that BTrDB is treating the endpoint as exclusive.")
print("The point at 1458040396541067264 is not in the result of the first query, but such a point does exist with count != 0.")

print()
print("Making a query at pw=31 from 1458040387951132672 to 1458040396541067264")
for statpoint, version in s.alignedWindows(1458040387951132672, 1458040396541067264, 31):
    print(statpoint)

print()
print("Making a query at pw=32 from 1458040387951132672 to 1458040396541067264")
for statpoint, version in s.alignedWindows(1458040387951132672, 1458040396541067264, 32):
    print(statpoint)

print()
print("The last query shows that BTrDB is treating the endpoint as inclusive.")
print("The point at 1458040396541067264 is in the result of the query.")

print()
print("In conclusion, it seems that at pw=32, BTrDB treats the endpoint as inclusive, but at pw=31, BTrDB treats the endpoint as exclusive.")
immesys commented 7 years ago

My bet is that it is not about the PW its about the depth of the tree. The condition might be different for leaf vs core node. Probably a quick fix, I'll take a look this week

immesys commented 7 years ago

@samkumar I think I fixed this. I have deployed on compound-3, email me your IP and I can open up the firewall

samkumar commented 7 years ago

@immesys As we discussed earlier, your fix didn't work; this is still an issue

samkumar commented 7 years ago

OK, see Pull Request #48. I think that will fix this issue.

immesys commented 7 years ago

Fixed with different fix