mirror of
https://github.com/pgsty/minio.git
synced 2026-11-03 14:22:12 +03:00
fix(pools): do not panic when a rebalance stop finds no rebalance metadata
Signed-off-by: Denis Babchuk <babchukdenis@icloud.com>
This commit is contained in:
committed by
Feng Ruohang
parent
d4e7716085
commit
525ab5fa40
@@ -373,7 +373,9 @@ func (a adminAPIHandlers) RebalanceStop(w http.ResponseWriter, r *http.Request)
|
||||
// Cancel any ongoing rebalance operation
|
||||
globalNotificationSys.StopRebalance(r.Context())
|
||||
writeSuccessResponseHeadersOnly(w)
|
||||
adminLogIf(ctx, pools.saveRebalanceStats(GlobalContext, 0, rebalSaveStoppedAt))
|
||||
if err := pools.saveRebalanceStats(GlobalContext, 0, rebalSaveStoppedAt); !errors.Is(err, errRebalanceNotStarted) {
|
||||
adminLogIf(ctx, err)
|
||||
}
|
||||
globalNotificationSys.LoadRebalanceMeta(ctx, false)
|
||||
}
|
||||
|
||||
|
||||
@@ -826,6 +826,10 @@ func (z *erasureServerPools) saveRebalanceStats(ctx context.Context, poolIdx int
|
||||
// if not found, we store the memory metadata back
|
||||
// when rebalance status changed, will notify all nodes update status to memory, we can treat the memory metadata is the latest status
|
||||
if errors.Is(err, errConfigNotFound) {
|
||||
if z.rebalMeta == nil {
|
||||
// No rebalance has run, e.g. a rebalance stop without one.
|
||||
return errRebalanceNotStarted
|
||||
}
|
||||
r = z.rebalMeta
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2026 Denis Babchuk
|
||||
//
|
||||
// This file is part of Silo Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Without rebalance.bin and without in-memory metadata no rebalance has run,
|
||||
// so there is nothing to update: saving must report that instead of
|
||||
// dereferencing the missing metadata, and must not create rebalance.bin.
|
||||
func TestSaveRebalanceStatsWithoutMeta(t *testing.T) {
|
||||
z, _ := consistencyPools(t)
|
||||
for _, opts := range []rebalSaveOpts{rebalSaveStoppedAt, rebalSaveStats} {
|
||||
if err := z.saveRebalanceStats(t.Context(), 0, opts); !errors.Is(err, errRebalanceNotStarted) {
|
||||
t.Fatalf("opts %d: got %v, want %v", opts, err, errRebalanceNotStarted)
|
||||
}
|
||||
if z.rebalMeta != nil {
|
||||
t.Fatalf("opts %d: in-memory rebalance metadata was set", opts)
|
||||
}
|
||||
r := &rebalanceMeta{}
|
||||
if err := r.load(t.Context(), z.serverPools[0]); !errors.Is(err, errConfigNotFound) {
|
||||
t.Fatalf("opts %d: rebalance.bin after save: %v, want %v", opts, err, errConfigNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user