-
Notifications
You must be signed in to change notification settings - Fork 726
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
api: support to query whether pd has loaded region #8749
base: master
Are you sure you want to change the base?
Changes from 4 commits
c20a4f9
db574ec
64f12cc
0c50bef
9c9e931
bc7428b
df4ac32
d0d6875
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,9 +77,10 @@ type coreStorage struct { | |
Storage | ||
regionStorage endpoint.RegionStorage | ||
|
||
useRegionStorage int32 | ||
regionLoaded bool | ||
mu syncutil.Mutex | ||
useRegionStorage int32 | ||
regionLoadedFromDefault bool | ||
regionLoadedFromStorage bool | ||
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. Why do we need to distinguish these two kinds? 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. I want to avoid problems after ps.useRegionStorage switch 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. How about using string?
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. I don't think so, we just have these two ways now 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. I prefer just using a single field to store this info like: type regionSource int
const (
unloaded regionSource = iota
etcd
leveldb
) |
||
mu syncutil.RWMutex | ||
} | ||
|
||
// NewCoreStorage creates a new core storage with the given default and region storage. | ||
|
@@ -133,17 +134,22 @@ func TryLoadRegionsOnce(ctx context.Context, s Storage, f func(region *core.Regi | |
return s.LoadRegions(ctx, f) | ||
} | ||
|
||
ps.mu.Lock() | ||
defer ps.mu.Unlock() | ||
|
||
if atomic.LoadInt32(&ps.useRegionStorage) == 0 { | ||
return ps.Storage.LoadRegions(ctx, f) | ||
err := ps.Storage.LoadRegions(ctx, f) | ||
if err == nil { | ||
ps.regionLoadedFromDefault = true | ||
} | ||
return err | ||
} | ||
|
||
ps.mu.Lock() | ||
defer ps.mu.Unlock() | ||
if !ps.regionLoaded { | ||
if !ps.regionLoadedFromStorage { | ||
if err := ps.regionStorage.LoadRegions(ctx, f); err != nil { | ||
return err | ||
} | ||
ps.regionLoaded = true | ||
ps.regionLoadedFromStorage = true | ||
} | ||
return nil | ||
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. Seems we can use 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. It doesn't check ps.regionLoadedFromStorage |
||
} | ||
|
@@ -197,3 +203,14 @@ func (ps *coreStorage) Close() error { | |
} | ||
return nil | ||
} | ||
|
||
// AreRegionsLoaded returns whether the regions are loaded. | ||
func AreRegionsLoaded(s Storage) bool { | ||
ps := s.(*coreStorage) | ||
ps.mu.RLock() | ||
defer ps.mu.RUnlock() | ||
if atomic.LoadInt32(&ps.useRegionStorage) == 0 { | ||
return ps.regionLoadedFromDefault | ||
} | ||
return ps.regionLoadedFromStorage | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ type Status struct { | |
Version string `json:"version"` | ||
GitHash string `json:"git_hash"` | ||
StartTimestamp int64 `json:"start_timestamp"` | ||
Loaded bool `json:"loaded"` | ||
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. Prefer |
||
} | ||
|
||
const ( | ||
|
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 that safe to switch between using or not using RegionStore in the master branch or the latest releases now?
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.
defaultUseRegionStorage is true and only check switch when it was just elected leader.