thanos-io / thanos

Highly available Prometheus setup with long term storage capabilities. A CNCF Incubating project.
https://thanos.io
Apache License 2.0
13.13k stars 2.1k forks source link

receive: port expanded postings cache from Cortex #7914

Closed GiedriusS closed 1 day ago

GiedriusS commented 1 week ago

Port expanded postings cache from Cortex. Huge kudos to @alanprot for the implementation. I added a TODO item to convert our whole internal caching infra to be promise based.

alanprot commented 1 week ago

Nice.

Maybe if we have this code here, i can make cortex use it and we don't have the code duplicated across both repos. :D

GiedriusS commented 4 days ago

:+1: good point. I see a panic in iter.Pull2 from time to time so I am keeping this a draft until I figure out what's wrong.

alanprot commented 4 days ago

can you share the go routine trace when the panic happens?

GiedriusS commented 3 days ago

can you share the go routine trace when the panic happens?

I think I somehow ported some older version of the code which didn't properly check for nil before popping an item from the container. Now it works well.

Also, the coroutines in Go "eat" the original stack trace if there's a panic. This is because it just panic()s again from a different place if seq() panic. So, I added the following code to capture the stack trace:

    defer func() {
            if r := recover(); r != nil {
                st := debug.Stack()
                panic(fmt.Sprintf("panic %v in server iterator: %s", r, st))
            }
        }()