-
Notifications
You must be signed in to change notification settings - Fork 724
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 2 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 |
---|---|---|
|
@@ -27,10 +27,11 @@ import ( | |
// Status is the status of PD server. | ||
// NOTE: This type is exported by HTTP API. Please pay more attention when modifying it. | ||
type Status struct { | ||
BuildTS string `json:"build_ts"` | ||
Version string `json:"version"` | ||
GitHash string `json:"git_hash"` | ||
StartTimestamp int64 `json:"start_timestamp"` | ||
BuildTS string `json:"build_ts"` | ||
Version string `json:"version"` | ||
GitHash string `json:"git_hash"` | ||
StartTimestamp int64 `json:"start_timestamp"` | ||
AreRegionsLoaded bool `json:"are_regions_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 to use 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.
? 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. yes |
||
} | ||
|
||
const ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ package api | |
import ( | ||
"net/http" | ||
|
||
"github.com/tikv/pd/pkg/storage" | ||
"github.com/tikv/pd/pkg/versioninfo" | ||
"github.com/tikv/pd/server" | ||
"github.com/unrolled/render" | ||
|
@@ -39,11 +40,13 @@ func newStatusHandler(svr *server.Server, rd *render.Render) *statusHandler { | |
// @Success 200 {object} versioninfo.Status | ||
// @Router /status [get] | ||
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 am not sure whether it is suitable. ref #8748 (comment) 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 /member or /health? 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. /members return all member info according etcd.ListEtcdMembers 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. status is more like some fixed information to me, at least for the current definition. 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.
Yes, as I said in the issue. |
||
func (h *statusHandler) GetPDStatus(w http.ResponseWriter, _ *http.Request) { | ||
areRegionsLoaded := storage.AreRegionsLoaded(h.svr.GetStorage()) | ||
version := versioninfo.Status{ | ||
BuildTS: versioninfo.PDBuildTS, | ||
GitHash: versioninfo.PDGitHash, | ||
Version: versioninfo.PDReleaseVersion, | ||
StartTimestamp: h.svr.StartTimestamp(), | ||
BuildTS: versioninfo.PDBuildTS, | ||
GitHash: versioninfo.PDGitHash, | ||
Version: versioninfo.PDReleaseVersion, | ||
StartTimestamp: h.svr.StartTimestamp(), | ||
AreRegionsLoaded: areRegionsLoaded, | ||
} | ||
|
||
h.rd.JSON(w, http.StatusOK, version) | ||
|
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.