-
-
Notifications
You must be signed in to change notification settings - Fork 404
Non locking and async API #459
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
Conversation
2427f58 to
830d12e
Compare
30507e0 to
508366c
Compare
|
I think allowing concurrent DB access is not enough - we need to make sure package pool and published repositories are safe to be used concurrently (which is not the case today), so DB lock protects today implicitly package pool/published repos. |
|
Yes this is not enough. Our approach to this has actually developed over time. Now we do a locking on a task basis and each task can define what resources it requires. I haven't gotten to update the PR... will do so when I find time but if you wanna have a look see master branch of our fork: |
|
That sounds interesting, and I think locking on per-resource level might be the way to go here... |
|
@smira In general are there two core concepts:
Let me know what you think. |
|
Thanks, I'll schedule it for post-1.1.0 as this looks scary enough for planned June release (already a lot of changes queued). |
|
I agree properly better to postpone it and polish it a bit more. What I want to note is though that we already use this code in production and it proved to be stable. |
c05f09b to
e46568c
Compare
e46568c to
744a2d9
Compare
|
@smira I have updated PR so it should cleanly apply to master again. As version 1.1.0 is now released it would be great if you could comment on this PR what you think and have we shall move forward to possible integrate into the next version. I am happy to adjust the code as needed. |
40dc02b to
4a249e5
Compare
4a249e5 to
bf1d5b5
Compare
5a34d47 to
9d7ef2c
Compare
9d7ef2c to
5a5ac23
Compare
|
I love the idea. Considering this changes return values of existing endpoints I'd say this needs some compatibility adjustments. Specifically, everything should get an additional new route Food for thought: I am wondering if a websocket isn't the more "modern" and flexible approach to this. i.e. instead of getting a taskid the client gets a websocket URI, then the client connects to the socket to get task updates from it. Calling Taking it a step further, I could imagine this enabling us to put the CLI ontop of the API, so you could actually operate a remote aptly instance via your local CLI! Well, one can dream 😸 |
|
@apachelogger Totally agree that we should make this change in a backwards compatible fashion and the way you outlined should be straight forward. I love the idea of web sockets... I think though we should make using web sockets on the api only an additional feature and not required per default though so simple REST client script are still possible. This way we can also get the async api merged and add web sockets in a future release (which would then also let the CLI use the API). |
Codecov Report
@@ Coverage Diff @@
## master #459 +/- ##
=========================================
+ Coverage 60.64% 60.94% +0.3%
=========================================
Files 50 54 +4
Lines 6276 6422 +146
=========================================
+ Hits 3806 3914 +108
- Misses 2033 2081 +48
+ Partials 437 427 -10
Continue to review full report at Codecov.
|
this is needed so concurrent reads and writes are possible.
This way db usage is safe.
Progress is not safe so for api its always nil and code needs to take care of this
|
I wonder if it could be HTTP/2 Push events in the end. I want to look into this more, but I don't see why exactly we can't make async return optional? So that sync/async options are both available. In the end in the local network environment, there's nothing unusual about setting HTTP response timeout to say 10 minutes and waiting for API completion in one call. Long polling, async response makes more sense when API is not local and we can't control timeouts on the way to aptly service endpoint. |
|
I would like to try to see if it's possible to split into a smaller PRs and commit them one by one, with thorough review for each one. |
This is spin-off of changes from aptly-dev#459. Transactions are not being used yet, but batches are updated to work with the new API. `database/` package was refactored to split abstract interfaces and implementation via goleveldb. This should make it easier to implement new database types.
This is spin-off of changes from aptly-dev#459. Transactions are not being used yet, but batches are updated to work with the new API. `database/` package was refactored to split abstract interfaces and implementation via goleveldb. This should make it easier to implement new database types.
This is spin-off of changes from aptly-dev#459. Transactions are not being used yet, but batches are updated to work with the new API. `database/` package was refactored to split abstract interfaces and implementation via goleveldb. This should make it easier to implement new database types.
This is spin-off of changes from #459. Transactions are not being used yet, but batches are updated to work with the new API. `database/` package was refactored to split abstract interfaces and implementation via goleveldb. This should make it easier to implement new database types.
For any action which is multi-step (requires updating more than 1 DB key), use transaction to make update atomic. Also pack big chunks of updates (importing packages for importing and mirror updates) into single transaction to improve aptly performance and get some isolation. Note that still layers up (Collections) provide some level of isolation, so this is going to shine with the future PRs to remove collection locks. Spin-off of aptly-dev#459
For any action which is multi-step (requires updating more than 1 DB key), use transaction to make update atomic. Also pack big chunks of updates (importing packages for importing and mirror updates) into single transaction to improve aptly performance and get some isolation. Note that still layers up (Collections) provide some level of isolation, so this is going to shine with the future PRs to remove collection locks. Spin-off of #459
Part of PR aptly-dev#459 This prepares for more methods to be exposed via the API.
Part of PR #459 This prepares for more methods to be exposed via the API.
Goal is when a write happens on api reading should still be possible and multiple processes should run simultaneously.
To accomplish this following needed to change:
Example how the new task API works:
(1) POST /api/repos/:name/snapshots ...
Snapshot repository. This will return status code 202 to
indicate that process is accepted but not finished yet.
Additionally will task id be returned to follow status of
running task.
(2) GET /api/tasks/.../output
Get log of currently running task
(3) GET /api/tasks/.../wait
Waits till task is finished
This also solves the problem with mirror api integration as task can run in the background (as mentioned in #166 ).
Mirror api integration based on this PR see #573
As this is a lengthy PR once its core concept is agreed upon I will be happy to update the documentation as well.
Checklist
AUTHORS