mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 19:17:28 +01:00
90 lines
3.0 KiB
Go
90 lines
3.0 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore"
|
|
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout"
|
|
"github.com/seaweedfs/seaweed-block/core/lifecycle"
|
|
)
|
|
|
|
// layoutVolumeCreator writes only the master's initial VOLUME and unclaimed
|
|
// HEAD. layout.CreateVolume performs exclusive writes and heals a replay
|
|
// stopped between them without minting another identity.
|
|
func layoutVolumeCreator(cat *chunkstore.BCatalog) func(context.Context, lifecycle.VolumeSpec) error {
|
|
return func(ctx context.Context, spec lifecycle.VolumeSpec) error {
|
|
if cat == nil {
|
|
return fmt.Errorf("master: layout catalog is unavailable")
|
|
}
|
|
id, err := layout.ParseVolumeID(spec.LayoutID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_, err = cat.CreateVolume(ctx, chunkstore.VolumeRef{Name: spec.VolumeID, ID: id}, layout.Geometry{
|
|
SizeBytes: spec.SizeBytes, BlockSize: spec.BlockSize, ChunkBytes: spec.ChunkBytes,
|
|
})
|
|
return err
|
|
}
|
|
}
|
|
|
|
func layoutVolumeReader(cat *chunkstore.BCatalog) func(context.Context, lifecycle.VolumeSpec) (layout.Volume, error) {
|
|
return func(ctx context.Context, spec lifecycle.VolumeSpec) (layout.Volume, error) {
|
|
id, err := layout.ParseVolumeID(spec.LayoutID)
|
|
if err != nil {
|
|
return layout.Volume{}, err
|
|
}
|
|
return cat.ReadVolume(ctx, chunkstore.VolumeRef{Name: spec.VolumeID, ID: id})
|
|
}
|
|
}
|
|
|
|
func layoutHeadReader(cat *chunkstore.BCatalog) func(context.Context, lifecycle.VolumeSpec) (layout.Head, error) {
|
|
return func(ctx context.Context, spec lifecycle.VolumeSpec) (layout.Head, error) {
|
|
id, err := layout.ParseVolumeID(spec.LayoutID)
|
|
if err != nil {
|
|
return layout.Head{}, err
|
|
}
|
|
h, found, err := cat.ReadHead(ctx, chunkstore.VolumeRef{Name: spec.VolumeID, ID: id})
|
|
if err != nil {
|
|
return layout.Head{}, err
|
|
}
|
|
if !found {
|
|
return layout.Head{}, layout.ErrHeadAbsent
|
|
}
|
|
return h, nil
|
|
}
|
|
}
|
|
|
|
func layoutTargetCreator(cat *chunkstore.BCatalog) func(context.Context, lifecycle.VolumeSpec, lifecycle.VolumeSpec, string) error {
|
|
return func(ctx context.Context, source, target lifecycle.VolumeSpec, snapshot string) error {
|
|
sid, err := layout.ParseVolumeID(source.LayoutID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
tid, err := layout.ParseVolumeID(target.LayoutID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_, err = cat.Restore(ctx,
|
|
chunkstore.VolumeRef{Name: source.VolumeID, ID: sid}, snapshot,
|
|
chunkstore.VolumeRef{Name: target.VolumeID, ID: tid})
|
|
return err
|
|
}
|
|
}
|
|
|
|
// newRetirementHeadReader opens only a read transport. The serving catalog has
|
|
// already validated the endpoint; retirement must not repeat its write probes
|
|
// or start another probe-cleanup worker.
|
|
func newRetirementHeadReader(cfg chunkstore.SWFSConfig) (func(context.Context, lifecycle.VolumeSpec) (layout.Head, error), *chunkstore.SWFS, error) {
|
|
client, err := chunkstore.DialSWFS(cfg)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
cat, err := chunkstore.NewBCatalog(client, client, cfg.AssignPath)
|
|
if err != nil {
|
|
_ = client.Close()
|
|
return nil, nil, err
|
|
}
|
|
return layoutHeadReader(cat), client, nil
|
|
}
|