-
Notifications
You must be signed in to change notification settings - Fork 728
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
storage/endpoint: Add a new component GCStateStorage
and GCStateProvider
to storage/endpoints as the new storage layer for GC related metadata
#9109
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: MyonKeminta <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #9109 +/- ##
==========================================
+ Coverage 76.29% 76.37% +0.07%
==========================================
Files 473 474 +1
Lines 71663 72034 +371
==========================================
+ Hits 54677 55016 +339
- Misses 13559 13578 +19
- Partials 3427 3440 +13
Flags with carried forward coverage won't be shown. Click here to find out more. |
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
/retest |
pkg/storage/endpoint/gc_states.go
Outdated
"github.com/tikv/pd/pkg/utils/keypath" | ||
) | ||
|
||
// ServiceSafePoint is the safepoint for a specific service |
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.
How about adding more comments to explain which component or feature will use ServiceSafePoint/GCBarrier/TxnSafePoint?
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'll add comments to the start of this file to describe the related concepts. But ths interfaces in this file is only expected to be used in GCStateManager
, which will come in another PR.
|
||
// keyspaceGCSafePoint is the data structure when writing | ||
type keyspaceGCSafePoint struct { | ||
KeyspaceID uint32 `json:"keyspace_id"` |
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.
What is the ID used for?
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.
Nothing but for keeping the data format compatible with the exisiting design of the "GC API V2". I forgot to finish the comments of this type. I'll fix it.
pkg/storage/endpoint/gc_states.go
Outdated
} | ||
|
||
// loadJSON loads a specific key from the StorageEndpoint, and parses it as JSON into type T. | ||
func loadJSON[T any](se *StorageEndpoint, key string) (T, error) { |
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.
Shall we move loadJSON and loadJSONByPrefix to endpoint.go?
// In the transaction, reads can be performed on the GCStateProvider as usual, while writes should only be performed | ||
// through the GCStateWriteBatch. | ||
func (p GCStateProvider) RunInGCStateTransaction(f func(wb *GCStateWriteBatch) error) error { | ||
revisionKey := keypath.GCStateRevisionPath() |
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.
Is it possible to use the revision provided by etcd?
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.
Yes but hard to provide it over the abstracted kv.Base
interface.
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.
And it needs a single centrialized key anyway.
pkg/storage/endpoint/gc_states.go
Outdated
txn := p.storage.CreateRawTxn() | ||
result, err := txn.If(condition).Then(ops...).Commit() | ||
if err != nil { | ||
return errors.AddStack(err) |
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.
How about return errs.ErrEtcdTxnInternal.Wrap(err).GenWithStackByArgs()
return errs.ErrEtcdTxnConflict.GenWithStackByArgs() | ||
} | ||
|
||
if len(ops) != len(result.Responses) { |
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.
If this happens, do we need to rollback or manually fix it?
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.
If I understanding is correct, etcd shoudl guarantee this to be true. I expect that this path is never reachable. If this happen, I think it should be a bug in etcd or etcd-client and it doesn't look possible to automatically fix it in a simple way. And as the Commit
returns no error here, it seems we no longer have chance to roll it back atomically. I think if this does happen, we may have no choice but to manually recover it.
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
/retest |
1 similar comment
/retest |
@@ -0,0 +1,541 @@ | |||
// Copyright 2024 TiKV Project Authors. |
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.
// Copyright 2024 TiKV Project Authors. | |
// Copyright 2025 TiKV Project Authors. |
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.
Time went too fast before I noticed it😕
gcSafePointV2PathFormat = "/pd/%d/keyspaces/gc_safe_point/%08d" // "/pd/{cluster_id}/keyspaces/gc_safe_point/{keyspace_id}" | ||
serviceSafePointV2PathFormat = "/pd/%d/keyspaces/service_safe_point/%08d/%s" // "/pd/{cluster_id}/keyspaces/service_safe_point/{keyspace_id}/{service_id}" | ||
gcStateRevisionPathFormat = "/pd/%d/gc/gc_state_revision" // "/pd/{cluster_id}/gc/gc_state_revision" | ||
gcSafePointPathFormat = "/pd/%d/gc/safe_point" // "/pd/{cluster_id}/gc/safe_point" |
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.
How about naming this variable globalGCSafePointPathFormat directly? Other developers might have questions about the relationship between gcSafePointPathFormat and keyspaceGCSafePointPathFormat: keyspaceGCSafePointPathFormat.
return fmt.Sprintf(gcStateRevisionPathFormat, ClusterID()) | ||
} | ||
|
||
// GCSafePointPath returns the key path of the global (NullKeyspace) GC safe point. |
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.
How about explicitly introducing and explaining the relationship between global and NullKeyspace in the code comments? This can help everyone understand its meaning clearly.
What problem does this PR solve?
Issue Number: Ref #8978
What is changed and how does it work?
Check List
Tests
Code changes
Side effects
Related changes
Release note