优化刷盘轮询,修复优先队列数量错误
This commit is contained in:
@@ -128,6 +128,7 @@ func (s *Server) Handler() http.Handler {
|
||||
mux.HandleFunc("/admin/priority", s.handleAdminPriority)
|
||||
mux.HandleFunc("/admin/priority/status", s.handleAdminPriorityStatus)
|
||||
mux.HandleFunc("/admin/flush", s.handleAdminFlush)
|
||||
mux.HandleFunc("/admin/flush/status", s.handleAdminFlushStatus)
|
||||
mux.HandleFunc("/admin/pending", s.handleAdminPending)
|
||||
mux.HandleFunc("/admin/workers", s.handleAdminWorkers)
|
||||
mux.HandleFunc("/admin/backlink", s.handleAdminBacklink)
|
||||
@@ -592,6 +593,29 @@ func (s *Server) handleAdminFlush(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("flushed"))
|
||||
}
|
||||
|
||||
// handleAdminFlushStatus 返回当前是否正在刷盘。
|
||||
// GET: 返回 flushing (bool)
|
||||
func (s *Server) handleAdminFlushStatus(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
if r.Method != http.MethodGet && r.Method != http.MethodOptions {
|
||||
http.Error(w, `{"error":"method not allowed"}`, 405)
|
||||
return
|
||||
}
|
||||
if r.Method == http.MethodOptions {
|
||||
w.WriteHeader(204)
|
||||
return
|
||||
}
|
||||
// flushMu.TryLock() 返回 false 表示锁被占用(正在刷盘)
|
||||
flushing := !s.flushMu.TryLock()
|
||||
if flushing {
|
||||
json.NewEncoder(w).Encode(map[string]bool{"flushing": true})
|
||||
} else {
|
||||
s.flushMu.Unlock()
|
||||
json.NewEncoder(w).Encode(map[string]bool{"flushing": false})
|
||||
}
|
||||
}
|
||||
|
||||
// handleAdminPending 返回内存中未刷盘的索引条目数量。
|
||||
func (s *Server) handleAdminPending(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
|
||||
Reference in New Issue
Block a user