-
Notifications
You must be signed in to change notification settings - Fork 137
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
walker: Use memdb for queued paths #839
Conversation
Converting to draft as there is still ongoing issue with the channel being filled up due to the fact that we only consume from the channel on a certain occasion. terraform-ls/internal/terraform/module/walker.go Lines 191 to 204 in bc219ad
This would suggest that walker is basically capped 50 paths all the time. I want to explore the possibility of moving the path queue into memdb as well since the problem we have here is basically the same as in the job scheduler and it might allow us to get rid of most sync logic within the walker. |
bc219ad
to
6cf64da
Compare
I have a draft of a solution (pushed to branch) but it's not fully finished and it looks like it would be best to first tackle #515 |
b563a34
to
a30349f
Compare
Makes use of the new WalkerCollector allowing us to pass around a single *Walker instance. This also allows us to move synchronization from within StartWalking() to tests themselves, reducing the difference between "code under test" and "code in prod".
a30349f
to
898694f
Compare
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.
👍 thanks for the helpful PR description!
I've only a small suggestion, but that isn't a blocker
This functionality has been released in v0.27.0 of the language server. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Fixes #838
The bug was originally introduced in #502 - i.e. has been around since introduction of workspace support, for about 9 months. I am therefore leaning towards just slotting this into a regular release schedule (as opposed to cutting patch release).
Previously we stored queued paths in a priority queue implemented via
container/heap
. To allow a more efficient synchronization (which is needed in tests) and a little more readable code (at least the walker code), the data was moved into a new memdb table. This means we can leverage memdb watch channels to do the synchronization and entirely avoid a separate "SyncWalker" implementation just for tests.New
walker_paths
memdb tableEach entry within the new table is represented as
WalkerPath
:terraform-ls/internal/state/walker_paths.go
Lines 23 to 27 in 898694f
WalkerCollector
A new
WalkerCollector
is introduced to collect job IDs and errors as part of walking, such that we can block & wait for completion of all these async jobs in tests and also fail tests if errors occur during walking.terraform-ls/internal/terraform/module/walker_collector.go
Lines 10 to 16 in 898694f
Synchronization in tests
A new helper function is introduced to block and wait for:
and also to flag up any errors occurred during the walk as test failures.
terraform-ls/internal/langserver/handlers/handlers_test.go
Lines 83 to 97 in 898694f
This replaces the clunkier sync mode of the walker where
StartWalk()
would optionally block under test.Future - General Purpose Walker?
As noted with the
// TODO
inline comment, I see an opportunity to further cleanup the Walker code and make it more general-purpose by extracting the logic that runs for every module found. That would likely allow us to remove most of the arguments fromNewWalker
. I just didn't want to do it in this PR which already got quite big.