mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-08 21:08:27 +01:00
shell: include collection names when topology statistics are unavailable (#12490)
fix(shell): include collections without live topology in list Co-authored-by: codex03 <codex03@local.invalid>
This commit is contained in:
1 parent
c147b775f9
commit
0705e20fe9
2 files changed
+55
No files matched your search
@@ -67,6 +67,7 @@ func (c *commandCollectionList) Do(args []string, commandEnv *CommandEnv, writer
|
||||
for _, c := range collections {
|
||||
cif, found := collectionInfos[c]
|
||||
if !found {
|
||||
fmt.Fprintf(writer, "collection:\"%s\"\tvolumeCount:UNKNOWN\n", c)
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(writer, "collection:\"%s\"\tvolumeCount:%d\tsize:%.0f\tfileCount:%.0f\tdeletedBytes:%.0f\tdeletion:%.0f\n", c, cif.VolumeCount, cif.Size, cif.FileCount, cif.DeletedByteCount, cif.DeleteCount)
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type offlineCollectionMaster struct {
|
||||
fakeDiscoveryServer
|
||||
topologyCalls atomic.Int32
|
||||
}
|
||||
|
||||
func (s *offlineCollectionMaster) CollectionList(context.Context, *master_pb.CollectionListRequest) (*master_pb.CollectionListResponse, error) {
|
||||
return &master_pb.CollectionListResponse{Collections: []*master_pb.Collection{{Name: "unrelated-offline"}, {Name: "prospective"}}}, nil
|
||||
}
|
||||
func (s *offlineCollectionMaster) VolumeList(context.Context, *master_pb.VolumeListRequest) (*master_pb.VolumeListResponse, error) {
|
||||
s.topologyCalls.Add(1)
|
||||
return &master_pb.VolumeListResponse{TopologyInfo: &master_pb.TopologyInfo{}}, nil
|
||||
}
|
||||
func TestCollectionListIncludesOfflineNamespace(t *testing.T) {
|
||||
lis, e := net.Listen("tcp", "127.0.0.1:0")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
server := grpc.NewServer()
|
||||
srv := &offlineCollectionMaster{}
|
||||
master_pb.RegisterSeaweedServer(server, srv)
|
||||
go server.Serve(lis)
|
||||
defer server.Stop()
|
||||
_, port, _ := net.SplitHostPort(lis.Addr().String())
|
||||
srv.leader = "127.0.0.1:0." + port
|
||||
ce, cancel := discoveryEnv(srv.leader, 3*time.Second)
|
||||
defer cancel()
|
||||
var out bytes.Buffer
|
||||
if e := (&commandCollectionList{}).Do(nil, ce, &out); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
for _, name := range []string{"unrelated-offline", "prospective"} {
|
||||
if !strings.Contains(out.String(), "collection:\""+name+"\"\tvolumeCount:UNKNOWN\n") {
|
||||
t.Fatalf("offline name omitted: %s", out.String())
|
||||
}
|
||||
}
|
||||
if !strings.Contains(out.String(), "Total 2 collections.\n") || srv.topologyCalls.Load() != 1 {
|
||||
t.Fatalf("incomplete listing: %s calls%d", out.String(), srv.topologyCalls.Load())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user