-
Notifications
You must be signed in to change notification settings - Fork 753
*: expose SetGlobalGCBarrier/DeleteGlobalGCBarrier API for pd client #9361
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
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
5c82fdb
add SetGlobalGCBarrier API and update AdvanceTxnSafePoint
tiancaiamao 1cf3791
Merge branch 'master' into global-gc-barrier
tiancaiamao c4df2aa
add the grpc api
tiancaiamao 4e674cd
add unit test
tiancaiamao b6caf12
make fmt
tiancaiamao 2ffe7a4
add integration test
tiancaiamao 0007cde
make fmt
tiancaiamao 5a90975
address comment
tiancaiamao c8c26e5
update go.mod for latest kvproto
tiancaiamao efd6f3d
fix tests
tiancaiamao 4a52539
Merge branch 'master' into global-gc-barrier
tiancaiamao c3a1b95
update pd client to provide global gc barriers API
tiancaiamao 09c6e98
update GetAllKeyspacesGCStates and add test
tiancaiamao 085e37b
Merge branch 'master' into update-pdclient
tiancaiamao 880cdbd
end
tiancaiamao 588e7b2
Merge branch 'master' into update-pdclient
tiancaiamao 53b0cd7
checkout go.mod
tiancaiamao 3041687
lint?
tiancaiamao 5febb98
make check
tiancaiamao 574545b
Merge branch 'master' into update-pdclient
tiancaiamao cff1b51
address comment
tiancaiamao 5684113
address comment
tiancaiamao b93c24f
address comment
tiancaiamao 10fd788
Merge branch 'master' into update-pdclient
tiancaiamao faf6d9b
imporve test coverage a bit
tiancaiamao a06ad66
address comment
tiancaiamao 0ed0fa1
make lint happy
tiancaiamao 11701da
Merge branch 'master' into update-pdclient
tiancaiamao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,43 @@ type GCStatesClient interface { | |
| // When this method is called on a keyspace without keyspace-level GC enabled, it will be equivalent to calling it on | ||
| // the NullKeyspace. | ||
| GetGCState(ctx context.Context) (GCState, error) | ||
| // SetGlobalGCBarrier sets a global GC barrier, which blocks GC like how GC barriers do, but is effective for all | ||
| // keyspaces. This API is designed for some special needs to block GC of all keyspaces. | ||
| // | ||
| // The usage is the similar to SetGCBarrier, but is not affected by the keyspace context of the current GCStatesClient | ||
| // instance. Note that normal GC barriers and global GC barriers are separated. | ||
| // One can not use SetGCBarrier and DeleteGCBarrier to operate a global GC barrier set by SetGlobalGCBarrier, and vice | ||
| // versa. | ||
| // | ||
| // Once a global GC barrier is set, it will block the txn safe points of all keyspaces from being advanced over the | ||
| // barrierTS, until the global GC barrier is expired (defined by ttl) or manually deleted (by calling | ||
| // DeleteGlobalGCBarrier). | ||
| // | ||
| // When this method is called on an existing global GC barrier, it updates the barrierTS and ttl of the existing global | ||
| // GC barrier and the expiration time will become the current time plus the ttl. | ||
| // This means that calling this method on an existing global GC barrier can extend its lifetime arbitrarily. | ||
| // | ||
| // Passing non-positive value to ttl is not allowed. Passing `time.Duration(math.MaxInt64)` to ttl indicates that the | ||
| // global GC barrier should never expire. The ttl might be rounded up, and the actual ttl is guaranteed no less than the | ||
| // specified duration. | ||
| // | ||
| // The barrierID must be non-empty. | ||
| // | ||
| // The given barrierTS must be greater than or equal to the current txn safe points of all keyspaces, | ||
| // otherwise an error will be returned. | ||
| // | ||
| // Currently, the caller is responsible for guaranteeing the given barrierTS does not exceed any of the max allocated | ||
| // timestamps of all TSOs in the cluster. Note that a cluster might have multiple TSOs for different keyspaces. | ||
| // | ||
| // When this function executes successfully, its result is never nil. | ||
| SetGlobalGCBarrier(ctx context.Context, barrierID string, barrierTS uint64, ttl time.Duration) (*GlobalGCBarrierInfo, error) | ||
| // DeleteGlobalGCBarrier deletes a global GC barrier. | ||
| DeleteGlobalGCBarrier(ctx context.Context, barrierID string) (*GlobalGCBarrierInfo, error) | ||
| // Get the GC states from all keyspaces. | ||
|
Comment on lines
+106
to
+108
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider also expand these comments.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I'm trying my best already |
||
| // The return value includes both GC states and global GC barriers information. | ||
| // If a keyspace's state is not ENABLED(like DISABLE/ARCHIVED/TOMBSTONE), that keyspace is skipped. | ||
| // If a keyspace is not configured with keyspace level GC, its GCState data is missing. | ||
| GetAllKeyspacesGCStates(ctx context.Context) (ClusterGCStates, error) | ||
| } | ||
|
|
||
| // InternalController is the interface for controlling GC execution. | ||
|
|
@@ -141,6 +178,16 @@ type GCBarrierInfo struct { | |
| getReqStartTime time.Time | ||
| } | ||
|
|
||
| // GlobalGCBarrierInfo represents the information of a global GC barrier. | ||
| type GlobalGCBarrierInfo struct { | ||
| BarrierID string | ||
| BarrierTS uint64 | ||
| TTL time.Duration | ||
| // The time when the RPC that fetches the GC barrier info. | ||
| // It will be used as the basis for determining whether the barrier is expired. | ||
| getReqStartTime time.Time | ||
| } | ||
|
|
||
| // TTLNeverExpire is a special value for TTL that indicates the barrier never expires. | ||
| const TTLNeverExpire = time.Duration(math.MaxInt64) | ||
|
|
||
|
|
@@ -171,6 +218,28 @@ func (b *GCBarrierInfo) isExpiredImpl(now time.Time) bool { | |
| return now.Sub(b.getReqStartTime) > b.TTL | ||
| } | ||
|
|
||
| // NewGlobalGCBarrierInfo creates a new GCBarrierInfo instance. | ||
| func NewGlobalGCBarrierInfo(barrierID string, barrierTS uint64, ttl time.Duration, getReqStartTime time.Time) *GlobalGCBarrierInfo { | ||
| return &GlobalGCBarrierInfo{ | ||
| BarrierID: barrierID, | ||
| BarrierTS: barrierTS, | ||
| TTL: ttl, | ||
| getReqStartTime: getReqStartTime, | ||
| } | ||
| } | ||
|
|
||
| // IsExpired checks whether the barrier is expired. | ||
| func (b *GlobalGCBarrierInfo) IsExpired() bool { | ||
| return b.isExpiredImpl(time.Now()) | ||
| } | ||
|
|
||
| func (b *GlobalGCBarrierInfo) isExpiredImpl(now time.Time) bool { | ||
| if b.TTL == TTLNeverExpire { | ||
| return false | ||
| } | ||
| return now.Sub(b.getReqStartTime) > b.TTL | ||
| } | ||
|
|
||
| // GCState represents the information of the GC state. | ||
| // | ||
| //nolint:revive | ||
|
|
@@ -181,3 +250,11 @@ type GCState struct { | |
| GCSafePoint uint64 | ||
| GCBarriers []*GCBarrierInfo | ||
| } | ||
|
|
||
| // ClusterGCStates represents the information of the GC state for all keyspaces. | ||
| type ClusterGCStates struct { | ||
| // Maps from keyspace id to GC state of that keyspace. | ||
| GCStates map[uint32]GCState | ||
| // All existing global GC barriers. | ||
| GlobalGCBarriers []*GlobalGCBarrierInfo | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.