-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: implement distributed lock by gorm #1366
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
base: develop
Are you sure you want to change the base?
Conversation
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.
Pull request overview
This PR implements a distributed locking mechanism using GORM as the backend storage for lock coordination. The implementation provides a Lock interface with methods for acquiring, releasing, renewing, and checking locks, along with a convenience WithLock method for executing functions while holding a lock. The feature integrates with the existing runtime component system and is used to prevent concurrent modifications of configuration rules in the console service layer.
Key Changes
- New distributed lock abstraction with GORM-based implementation using database-backed lock records with TTL and ownership tracking
- Component lifecycle integration with automatic expired lock cleanup every 5 minutes
- Lock protection added to tag route, dynamic config, and condition route operations in console services
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 17 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/core/lock/lock.go | Defines the Lock interface with methods for acquiring, releasing, and managing distributed locks |
| pkg/core/lock/lock_model.go | Database model for lock records with unique key constraint and expiration tracking |
| pkg/core/lock/gorm_lock.go | GORM-based implementation of the Lock interface with transaction support and auto-renewal |
| pkg/core/lock/errors.go | Custom error definitions for lock-related failures |
| pkg/core/lock/component.go | Runtime component integration with store dependency and cleanup task |
| pkg/core/lock/init.go | Component registration in the runtime registry |
| pkg/core/bootstrap/bootstrap.go | Adds distributed lock initialization step in the bootstrap sequence |
| pkg/console/context/context.go | Extends console context to provide access to the lock manager |
| pkg/console/service/tag_rule.go | Adds lock protection to tag route create, update, and delete operations |
| pkg/console/service/configurator_rule.go | Adds lock protection to configurator create, update, and delete operations |
| pkg/console/service/condition_rule.go | Adds lock protection to condition route create, update, and delete operations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
robocanic
left a comment
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.
Great work! I left some tips, you can discuss it with me through wechat: robocanic
robocanic
left a comment
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.
Great work! The implementation of Gorm is very comprehensive. There are some issues about the retrieval of store. I left some comments and if you come across any problems, you can discuss it with me.
pkg/core/lock/gorm_factory.go
Outdated
| GetDataStore() any | ||
| } | ||
|
|
||
| provider, ok := storeComp.(DataStoreProvider) |
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.
Suggestion: The ResourceStore is designed for Resource, the usage here may not work correctly. How about distinguishing from the bottom layer, that is to say, using the store config to build a new connection pool just for lock.
c190d3c to
c6f0e0a
Compare
|



Please provide a description of this PR:
To help us figure out who should review this PR, please put an X in all the areas that this PR affects.
Please check any characteristics that apply to this pull request.