mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
durable: chunk layer state and cut counters in the volume status
A walstore-chunk volume's VolumeStatus (/status/durable) gains a Chunk section: Attached, AwaitingAuthority, Fenced, RemoteLSN and the layer's Stats (cut counters, the last cut's stats, the dirty-chunk count). Other implementations have no Chunk section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
022c9077dd
commit
d2df820002
2 files changed
+91
-1
No files matched your search
@@ -223,6 +223,20 @@ type VolumeStatus struct {
|
||||
Evidence string
|
||||
Closed bool
|
||||
WriteProfile WriteProfileStatus
|
||||
// Chunk is the chunk layer's state and cut counters; walstore-chunk
|
||||
// volumes only.
|
||||
Chunk *ChunkStatus
|
||||
}
|
||||
|
||||
// ChunkStatus is one walstore-chunk volume's chunk layer (B9 7.2-7.3).
|
||||
// AwaitingAuthority: recovered, the layer waits for master authority to
|
||||
// attach. Stats is zero until the layer is attached.
|
||||
type ChunkStatus struct {
|
||||
Attached bool
|
||||
AwaitingAuthority bool
|
||||
Fenced bool
|
||||
RemoteLSN uint64
|
||||
Stats storage.ChunkLayerStats
|
||||
}
|
||||
|
||||
// NewDurableProvider constructs a provider. view is the ONLY
|
||||
@@ -469,17 +483,33 @@ func durableIdentityConflict(got, want frontend.Identity) error {
|
||||
// volume handles. This is used by status endpoints and TestOps gates to prove
|
||||
// durable lineage latching without scraping logs.
|
||||
func (p *DurableProvider) DurableStatuses() []VolumeStatus {
|
||||
type chunkView struct {
|
||||
layer storage.ChunkLayer
|
||||
awaiting bool
|
||||
}
|
||||
p.mu.Lock()
|
||||
handles := make(map[string]*volHandle, len(p.volumes))
|
||||
chunks := map[string]chunkView{}
|
||||
for volumeID, h := range p.volumes {
|
||||
handles[volumeID] = h
|
||||
if p.cfg.Impl == ImplWALStoreChunk {
|
||||
chunks[volumeID] = chunkView{layer: h.chunk, awaiting: h.waitGen != 0}
|
||||
}
|
||||
}
|
||||
impl := string(p.cfg.Impl)
|
||||
p.mu.Unlock()
|
||||
|
||||
out := make([]VolumeStatus, 0, len(handles))
|
||||
for volumeID, h := range handles {
|
||||
out = append(out, h.backend.durableStatus(volumeID, h.path, impl))
|
||||
st := h.backend.durableStatus(volumeID, h.path, impl)
|
||||
if cv, ok := chunks[volumeID]; ok {
|
||||
cs := &ChunkStatus{AwaitingAuthority: cv.awaiting}
|
||||
if cv.layer != nil {
|
||||
cs.Attached, cs.Fenced, cs.RemoteLSN, cs.Stats = true, cv.layer.Fenced(), cv.layer.RemoteLSN(), cv.layer.Stats()
|
||||
}
|
||||
st.Chunk = cs
|
||||
}
|
||||
out = append(out, st)
|
||||
}
|
||||
sort.Slice(out, func(i, j int) bool {
|
||||
return out[i].VolumeID < out[j].VolumeID
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/durable"
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
@@ -110,3 +111,62 @@ func TestWALStoreChunk_ExplicitCutRestartsTheTimer(t *testing.T) {
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
// The volume status carries the chunk layer's state and cut counters.
|
||||
func TestWALStoreChunk_StatusCarriesChunkLayer(t *testing.T) {
|
||||
remote := storage.NewMemChunkRemote()
|
||||
view := newStubView(frontend.Projection{VolumeID: "v1", ReplicaID: "r1"}) // pre-assignment
|
||||
p, err := durable.NewDurableProvider(durable.ProviderConfig{
|
||||
Impl: durable.ImplWALStoreChunk, StorageRoot: t.TempDir(), BlockSize: 4096,
|
||||
NumBlocks: pcBlocks, ChunkBlocks: pcChunkBlocks,
|
||||
ChunkRemoteFor: func(string) (storage.ChunkRemote, error) { return remote, nil },
|
||||
}, view)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = p.Close() })
|
||||
s, err := p.EnsureStorage("v1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := p.RecoverVolume(context.Background(), "v1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st := p.DurableStatuses()
|
||||
if len(st) != 1 || st[0].Chunk == nil || !st[0].Chunk.AwaitingAuthority || st[0].Chunk.Attached {
|
||||
t.Fatalf("status before authority: %+v", st)
|
||||
}
|
||||
view.set(healthyProj(frontend.Identity{VolumeID: "v1", ReplicaID: "r1", Epoch: 3, EndpointVersion: 1}))
|
||||
if _, err := s.Write(1, block(1)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var lsn uint64
|
||||
deadline := time.Now().Add(10 * time.Second)
|
||||
for {
|
||||
if lsn, err = p.CaptureVolume(context.Background(), "v1"); err == nil {
|
||||
break
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("capture never succeeded: %v", err)
|
||||
}
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
}
|
||||
c := p.DurableStatuses()[0].Chunk
|
||||
if c == nil || !c.Attached || c.AwaitingAuthority || c.Fenced || c.RemoteLSN != lsn || c.Stats.CutsOK != 1 || c.Stats.LastCutH != lsn {
|
||||
t.Fatalf("status after a cut: %+v", c)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWALStoreChunk_StatusHasNoChunkSectionForWALStore(t *testing.T) {
|
||||
p, err := durable.NewDurableProvider(durable.ProviderConfig{
|
||||
Impl: durable.ImplWALStore, StorageRoot: t.TempDir(), BlockSize: 4096, NumBlocks: pcBlocks,
|
||||
}, v1View())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = p.Close() })
|
||||
_ = openRecovered(t, p)
|
||||
if st := p.DurableStatuses(); len(st) != 1 || st[0].Chunk != nil {
|
||||
t.Fatalf("walstore status: %+v", st)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user