-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Implement support for busy handler #290
Comments
Note that if your response to SQLITE_BUSY is to retry the statement, its simpler to use the The bindings don't support the |
Thanks for the advice @sqweek; I'll keep the timeout parameter in mind, which may suffice for my use case. I know the |
There's no reason not to directly support This issue was originally about sqlite3_busy__handler_ though, which adds a bit more value in terms of flexibility. Also the groundwork is already there for |
Now that database/sql supports |
@jmmv @sqweek @zombiezen |
Any update ? |
Hi,
Having a busy handler that waits for context cancellation would provide the necessary flexibility for clients to specify their own deadlines on a case by case basis. This is widely done e.g. in gRPC servers. sqlite3's own implementation of I'm not very familiar with the The handler below sleeps in exponentially incremental intervals of up to 256 ms, func sqliteContextBusyHandler(ctx context.Context, count int) int {
const maxShift = 8 // 2**8 = 256 ms
if count > maxShift {
count = maxShift
}
t := time.NewTimer((1 << count) * time.Millisecond)
select {
case <-ctx.Done():
// cancelled; cleanup and stop retrying
t.Stop()
return 0
case <-t.C:
return 1
}
} This is assuming we can receive an arbitrary argument, i.e. the third argument to sqlite3_busy_handler. That would be It would be even better to store the timer between passes and call Could someone more familiar with |
@israel-lugo The SQLite busy handler is used for the entire database connection. There wouldn't be anywhere to get a per-request There seems to be some overlap between this desire and the need to interrupt a long running query even if it isn't blocking due to In short, the SQLite C API is flawed because none of the cancellation-related functions have any mechanism for tying it back to the specific operation you are performing (i.e., the call to You could try to do something with |
Thank you @rittneje, you're right of course. I'm trying out https://pkg.go.dev/crawshaw.io as an alternative; it's not an interface for |
it is useful for me , thanks ! |
Is anyone working on this? If not I can implement it and submit a PR. |
I'm just going to assume no one's working on this, so I've created a PR here: #1278 |
I think it'd be good for these bindings to support https://www.sqlite.org/c3ref/busy_handler.html .
Use case: I'm currently writing an app that causes quite a bit of traffic to an SQLite database and am encountering contention. I wrote my own wrappers around the queries I'm issuing to handle
SQLITE_BUSY
errors and retry them... but I just discovered that SQLite3 has a built-in mechanism for this viasqlite3_busy_handler
. It would be nice if we could register a hook viaSQLiteConn
or something like that.The text was updated successfully, but these errors were encountered: