mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
* filer: grow the metadata log collection on its own, fall back when it is full metaLog.volumeGrowthCount (default 2) is sent with assigns into the metadata log collection, so it grows by a few volumes instead of the master's default growth. When that collection cannot take the piece, the assign falls back to the collection the log uses without the override, so a full cluster does not stall the log. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: keep the metadata log in its own collection by default metaLog.collection now defaults to filer-meta, so purging old log days empties whole volumes instead of leaving log chunks scattered across the default collection's volumes. Setting it to "" keeps the log in the filer's -collection as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume: default -max to 10 to leave room for the metadata log collection The default collection still grows by 7 volumes; the extra slots keep the filer's metadata log collection (2 volumes by default) from taking them. Go and Rust volume servers share the new default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: bound the meta log collection's share of the assign budget A meta log collection that cannot grow (for example a replication the cluster cannot place) keeps answering with retryable errors, so the first assign used the whole shared budget and the fallback was never tried. Give it 10s, then fall back, and skip it for a minute after a failure instead of waiting on it at every flush. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: name the default meta log collection so no bucket maps to it A bucket named filer-meta mapped to the same collection, and deleting it from the admin page or weed shell drops the collection directly at the master, taking the metadata log with it. Bucket names cannot contain "_", and filer group buckets map to "<group>_<bucket>". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: clear the meta log overrides after the viper test Setting the collection back to its default value kept an explicit override, so the defaults test passed even without the SetDefault. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: retry the meta log collection once its fallback also fails The pause after a failed meta collection assign kept pieces on the shared collection for a full minute even when that assign failed too, so meta volumes that finished growing stayed unused while every flush failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: pick a default meta log collection no grouped bucket maps to Filer group "_filer" with bucket "meta" maps to "_filer_meta". The default now keeps its only "_" in front, and the test checks every group and bucket split of it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: default the meta log collection to _meta Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: keep the default meta log collection on bucket delete A filer that logs elsewhere did not treat _meta as reserved, so deleting a bucket a storage rule maps to _meta dropped the collection other filers write their logs to. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
276 lines
9.8 KiB
Go
276 lines
9.8 KiB
Go
package filer
|
|
|
|
import (
|
|
"context"
|
|
"crypto/rand"
|
|
"encoding/base64"
|
|
"encoding/binary"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"sync/atomic"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
"google.golang.org/grpc/status"
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/operation"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
)
|
|
|
|
type assignMaster struct {
|
|
collectionDeleteMaster
|
|
volumeUrl string
|
|
requests chan *master_pb.AssignRequest
|
|
}
|
|
|
|
func (m *assignMaster) Assign(ctx context.Context, req *master_pb.AssignRequest) (*master_pb.AssignResponse, error) {
|
|
m.requests <- req
|
|
location := &master_pb.Location{Url: m.volumeUrl, PublicUrl: m.volumeUrl}
|
|
return &master_pb.AssignResponse{Fid: "3,01637037d6", Count: 1, Location: location}, nil
|
|
}
|
|
|
|
type receivedPiece struct {
|
|
contentEncoding string
|
|
body []byte
|
|
}
|
|
|
|
func uploadMetaLogPiece(t *testing.T, data []byte) (*master_pb.AssignRequest, receivedPiece, *operation.UploadResult) {
|
|
t.Helper()
|
|
received := make(chan receivedPiece, 1)
|
|
volume := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
part, err := r.MultipartReader()
|
|
require.NoError(t, err)
|
|
p, err := part.NextPart()
|
|
require.NoError(t, err)
|
|
body, err := io.ReadAll(p)
|
|
require.NoError(t, err)
|
|
received <- receivedPiece{contentEncoding: p.Header.Get("Content-Encoding"), body: body}
|
|
w.WriteHeader(http.StatusCreated)
|
|
_ = json.NewEncoder(w).Encode(operation.UploadResult{Size: uint32(len(body))})
|
|
}))
|
|
t.Cleanup(volume.Close)
|
|
|
|
master := &assignMaster{
|
|
collectionDeleteMaster: collectionDeleteMaster{calls: make(chan collectionDeleteCall, 1)},
|
|
volumeUrl: strings.TrimPrefix(volume.URL, "http://"),
|
|
requests: make(chan *master_pb.AssignRequest, 1),
|
|
}
|
|
f, _ := newFilerWithMaster(t, master)
|
|
f.GrpcDialOption = grpc.WithTransportCredentials(insecure.NewCredentials())
|
|
|
|
_, uploadResult, err := f.assignAndUpload(context.Background(), string(appendTestLog), data)
|
|
require.NoError(t, err)
|
|
return <-master.requests, <-received, uploadResult
|
|
}
|
|
|
|
func metaLogRecords(t *testing.T, n int) []byte {
|
|
t.Helper()
|
|
chunks := make([]*filer_pb.FileChunk, 200)
|
|
for i := range chunks {
|
|
md5 := make([]byte, 16)
|
|
_, err := rand.Read(md5)
|
|
require.NoError(t, err)
|
|
chunks[i] = &filer_pb.FileChunk{
|
|
FileId: fmt.Sprintf("%d,%x%08x", i%7+1, i+1, binary.BigEndian.Uint32(md5)),
|
|
Offset: int64(i) * 256,
|
|
Size: 256,
|
|
ETag: base64.StdEncoding.EncodeToString(md5),
|
|
}
|
|
}
|
|
var buf []byte
|
|
for i := 0; i < n; i++ {
|
|
event, err := proto.Marshal(&filer_pb.SubscribeMetadataResponse{
|
|
Directory: "/soak",
|
|
EventNotification: &filer_pb.EventNotification{
|
|
OldEntry: &filer_pb.Entry{Name: "journal.log", Chunks: chunks[:len(chunks)-1]},
|
|
NewEntry: &filer_pb.Entry{Name: "journal.log", Chunks: chunks},
|
|
},
|
|
TsNs: int64(i + 1),
|
|
})
|
|
require.NoError(t, err)
|
|
record, err := proto.Marshal(&filer_pb.LogEntry{TsNs: int64(i + 1), Data: event})
|
|
require.NoError(t, err)
|
|
size := make([]byte, 4)
|
|
util.Uint32toBytes(size, uint32(len(record)))
|
|
buf = append(buf, size...)
|
|
buf = append(buf, record...)
|
|
}
|
|
return buf
|
|
}
|
|
|
|
func TestMetaLogPieceUploadsCompressed(t *testing.T) {
|
|
data := metaLogRecords(t, 50)
|
|
|
|
assign, piece, uploadResult := uploadMetaLogPiece(t, data)
|
|
|
|
require.Equal(t, "gzip", piece.contentEncoding)
|
|
decompressed, err := util.DecompressData(piece.body)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, data, decompressed)
|
|
assert.Less(t, len(piece.body)*5, len(data), "repeated chunk lists should compress well")
|
|
assert.Equal(t, uint64(len(piece.body)), assign.GetExpectedDataSize(), "assign sizes the bytes actually stored")
|
|
assert.Equal(t, uint32(1), uploadResult.Gzip)
|
|
assert.Equal(t, uint32(len(data)), uploadResult.Size, "chunk size and offsets stay in log bytes")
|
|
}
|
|
|
|
func TestMetaLogPieceUploadsIncompressibleAsIs(t *testing.T) {
|
|
data := make([]byte, 64*1024)
|
|
_, err := rand.Read(data)
|
|
require.NoError(t, err)
|
|
|
|
_, piece, uploadResult := uploadMetaLogPiece(t, data)
|
|
|
|
assert.Empty(t, piece.contentEncoding)
|
|
assert.Equal(t, data, piece.body)
|
|
assert.Zero(t, uploadResult.Gzip)
|
|
assert.Equal(t, uint32(len(data)), uploadResult.Size)
|
|
}
|
|
|
|
type fullCollectionMaster struct {
|
|
assignMaster
|
|
full string
|
|
fullErr error
|
|
attempts atomic.Int32
|
|
}
|
|
|
|
func (m *fullCollectionMaster) Assign(ctx context.Context, req *master_pb.AssignRequest) (*master_pb.AssignResponse, error) {
|
|
if req.Collection == m.full {
|
|
if m.attempts.Add(1) == 1 {
|
|
m.requests <- req
|
|
}
|
|
if m.fullErr != nil {
|
|
return nil, m.fullErr
|
|
}
|
|
return nil, fmt.Errorf("no free volumes left for collection %s", m.full)
|
|
}
|
|
return m.assignMaster.Assign(ctx, req)
|
|
}
|
|
|
|
func TestMetaLogPieceFallsBackWhenMetaCollectionIsFull(t *testing.T) {
|
|
volume := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusCreated)
|
|
_ = json.NewEncoder(w).Encode(operation.UploadResult{Size: 1})
|
|
}))
|
|
t.Cleanup(volume.Close)
|
|
|
|
master := &fullCollectionMaster{
|
|
assignMaster: assignMaster{
|
|
collectionDeleteMaster: collectionDeleteMaster{calls: make(chan collectionDeleteCall, 1)},
|
|
volumeUrl: strings.TrimPrefix(volume.URL, "http://"),
|
|
requests: make(chan *master_pb.AssignRequest, 2),
|
|
},
|
|
full: "filer-meta",
|
|
}
|
|
f, _ := newFilerWithMaster(t, master)
|
|
f.GrpcDialOption = grpc.WithTransportCredentials(insecure.NewCredentials())
|
|
f.metaLogTargetCollection = "filer-meta"
|
|
f.metaLogTargetReplication = "001"
|
|
f.metaLogVolumeGrowthCount = 2
|
|
f.metaLogCollection = "mydata"
|
|
|
|
_, _, err := f.assignAndUpload(context.Background(), string(appendTestLog), []byte("x"))
|
|
require.NoError(t, err)
|
|
|
|
own, shared := <-master.requests, <-master.requests
|
|
assert.Equal(t, "filer-meta", own.GetCollection())
|
|
assert.Equal(t, "001", own.GetReplication())
|
|
assert.Equal(t, uint32(2), own.GetWritableVolumeCount())
|
|
assert.Equal(t, "mydata", shared.GetCollection())
|
|
assert.Empty(t, shared.GetReplication())
|
|
assert.Zero(t, shared.GetWritableVolumeCount(), "the shared collection keeps its own growth count")
|
|
}
|
|
|
|
func TestMetaLogPieceFallsBackWhileMetaCollectionKeepsGrowing(t *testing.T) {
|
|
budget := metaLogOwnAssignBudget
|
|
metaLogOwnAssignBudget = time.Second
|
|
t.Cleanup(func() { metaLogOwnAssignBudget = budget })
|
|
|
|
volume := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusCreated)
|
|
_ = json.NewEncoder(w).Encode(operation.UploadResult{Size: 1})
|
|
}))
|
|
t.Cleanup(volume.Close)
|
|
|
|
master := &fullCollectionMaster{
|
|
assignMaster: assignMaster{
|
|
collectionDeleteMaster: collectionDeleteMaster{calls: make(chan collectionDeleteCall, 1)},
|
|
volumeUrl: strings.TrimPrefix(volume.URL, "http://"),
|
|
requests: make(chan *master_pb.AssignRequest, 3),
|
|
},
|
|
full: "meta",
|
|
fullErr: status.Error(codes.ResourceExhausted, "no writable volumes for meta, volume growth in progress"),
|
|
}
|
|
f, _ := newFilerWithMaster(t, master)
|
|
f.GrpcDialOption = grpc.WithTransportCredentials(insecure.NewCredentials())
|
|
f.metaLogTargetCollection = "meta"
|
|
f.metaLogCollection = "mydata"
|
|
|
|
start := time.Now()
|
|
_, _, err := f.assignAndUpload(context.Background(), string(appendTestLog), []byte("x"))
|
|
require.NoError(t, err)
|
|
assert.Less(t, time.Since(start), 5*time.Second, "the fallback must not wait for the whole assign budget")
|
|
assert.Equal(t, "meta", (<-master.requests).GetCollection())
|
|
assert.Equal(t, "mydata", (<-master.requests).GetCollection())
|
|
|
|
attempts := master.attempts.Load()
|
|
_, _, err = f.assignAndUpload(context.Background(), string(appendTestLog), []byte("x"))
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "mydata", (<-master.requests).GetCollection())
|
|
assert.Equal(t, attempts, master.attempts.Load(), "the next piece skips the collection that just failed")
|
|
}
|
|
|
|
func TestMetaLogPieceRetriesMetaCollectionWhenFallbackFails(t *testing.T) {
|
|
volume := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusCreated)
|
|
_ = json.NewEncoder(w).Encode(operation.UploadResult{Size: 1})
|
|
}))
|
|
t.Cleanup(volume.Close)
|
|
|
|
master := &fullCollectionMaster{
|
|
assignMaster: assignMaster{
|
|
collectionDeleteMaster: collectionDeleteMaster{calls: make(chan collectionDeleteCall, 1)},
|
|
volumeUrl: strings.TrimPrefix(volume.URL, "http://"),
|
|
requests: make(chan *master_pb.AssignRequest, 2),
|
|
},
|
|
full: "mydata",
|
|
}
|
|
f, _ := newFilerWithMaster(t, master)
|
|
f.GrpcDialOption = grpc.WithTransportCredentials(insecure.NewCredentials())
|
|
f.metaLogTargetCollection = "meta"
|
|
f.metaLogCollection = "mydata"
|
|
f.metaLogOwnAssignPausedUntil.Store(time.Now().Add(time.Hour).UnixNano())
|
|
|
|
_, _, err := f.assignAndUpload(context.Background(), string(appendTestLog), []byte("x"))
|
|
require.Error(t, err)
|
|
assert.Equal(t, "mydata", (<-master.requests).GetCollection())
|
|
|
|
_, _, err = f.assignAndUpload(context.Background(), string(appendTestLog), []byte("x"))
|
|
require.NoError(t, err, "a failed fallback ends the pause on the meta collection")
|
|
assert.Equal(t, "meta", (<-master.requests).GetCollection())
|
|
}
|
|
|
|
func TestMetaLogAssignWithoutOwnCollection(t *testing.T) {
|
|
f := &Filer{metaLogCollection: "mydata", metaLogVolumeGrowthCount: 2}
|
|
requests := f.metaLogAssignRequests(string(appendTestLog), 1)
|
|
require.Len(t, requests, 1)
|
|
assert.Equal(t, "mydata", requests[0].Collection)
|
|
assert.Zero(t, requests[0].WritableVolumeCount, "the growth count is only for the meta log collection")
|
|
|
|
f.metaLogTargetCollection = "mydata"
|
|
requests = f.metaLogAssignRequests(string(appendTestLog), 1)
|
|
require.Len(t, requests, 1)
|
|
assert.Equal(t, uint32(2), requests[0].WritableVolumeCount)
|
|
}
|