-
Notifications
You must be signed in to change notification settings - Fork 499
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
all: Refactor db.Session to take ctx into each call, instead of storing it on the session level #3545
Conversation
767ad96
to
0efc871
Compare
@@ -74,8 +75,9 @@ func (*DatabaseBackend) IsPrepared(ledgerRange Range) (bool, error) { | |||
|
|||
// GetLatestLedgerSequence returns the most recent ledger sequence number present in the database. | |||
func (dbb *DatabaseBackend) GetLatestLedgerSequence() (uint32, error) { | |||
ctx := context.TODO() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will change the behavior because now we cannot cancel a query via context termination. maybe it's best to move changes to this file to the ledgerbackend PR as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fixed, with the new changes, but double-check me on that, please.
0efc871
to
3440590
Compare
Stuff here is difficult without including the ledgerbackend changes. Going to try doing those first, and see if that makes this change simpler. Edit: It did not. Updating the LedgerBackend interface changes in DatabaseBackend, depends on these changes. Instead, added some temporary code to simplify this and pull the LedgerBackend interface changes out of this PR. |
ea1b038
to
73dce08
Compare
One catch with this, is that we now need to call an explicit Places where I've found that so far:
|
3f3b26d
to
e94f3fb
Compare
42d1a30
to
2f9863f
Compare
@@ -26,21 +27,32 @@ var _ LedgerBackend = (*DatabaseBackend)(nil) | |||
|
|||
// DatabaseBackend implements a database data store. | |||
type DatabaseBackend struct { | |||
cancel context.CancelFunc | |||
ctx context.Context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it stored instead of using it in method calls? (it would only be OK if a database backend is ephemeral)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Belt-and-braces (for now) to ensure shutdown. Normally the parent should call Close()
, but apparently there are some intricacies around shutdown ordering, so I wanted to keep the existing behaviour (when the parent ctx is cancelled, this ends as well).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear, it's two separate contexts. This one, to shut down the whole backend; and the one passed in method calls which is per-call.
@@ -67,6 +67,7 @@ type RemoteCaptiveStellarCore struct { | |||
client *http.Client | |||
lock *sync.Mutex | |||
cancel context.CancelFunc | |||
parentCtx context.Context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
PR Checklist
PR Structure
otherwise).
services/friendbot
, orall
ordoc
if the changes are broad or impact manypackages.
Thoroughness
.md
files, etc... affected by this change). Take a look in the
docs
folder for a given service,like this one.
Release planning
needed with deprecations, added features, breaking changes, and DB schema changes.
semver, or if it's mainly a patch change. The PR is targeted at the next
release branch if it's not a patch change.
What
The root change is:
And changing all the
db.Session
methods (where needed) to take actx context.Context
params. Then passing that through all the places to get it there.Why
For #3344, we want to pass different timeouts in different contexts. This change makes that easier, and generally follows the go norms of passing the context late into the method.
Known limitations
It's big. Will be difficult to review and merge. Most of the param passing is pretty mechanical. The interesting parts are around where we create the contexts initially. But, most of that is in tests.
Questions
Bonus
I also fixedTestOpen_openAndPingFails
, because it was intermittently failing and being annoying.