Files
seaweedfs/weed/storage/blockvol/storage_profile.go
T
Ping QiuandClaude Opus 4.6 74e8a4ce68 feat: CP11A-1 storage profile type, superblock persistence, and validation
Add StorageProfile enum (single=0, striped=1 reserved) persisted at
superblock offset 105. Existing volumes auto-map to single via zero-pad
backward compatibility. CreateBlockVol rejects striped and invalid
profile values before file creation. ParseStorageProfile is
case-insensitive and whitespace-tolerant.

13 tests: enum string/parse, superblock persistence, backward compat,
create/open/reopen, striped rejection, invalid profile rejection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 21:52:00 -07:00

49 lines
1.3 KiB
Go

package blockvol
import (
"errors"
"fmt"
"strings"
)
// StorageProfile controls the data layout strategy for a block volume.
// - ProfileSingle (0): single-server, one file (default, backward-compat)
// - ProfileStriped (1): multi-server striping (reserved, not yet implemented)
type StorageProfile uint8
const (
ProfileSingle StorageProfile = 0 // zero-value = backward compat
ProfileStriped StorageProfile = 1 // reserved — rejected at creation time
)
var (
ErrInvalidStorageProfile = errors.New("blockvol: invalid storage profile")
ErrStripedNotImplemented = errors.New("blockvol: striped profile is not yet implemented")
)
// ParseStorageProfile converts a string to StorageProfile.
// Empty string is treated as "single" for backward compatibility.
// Parsing is case-insensitive.
func ParseStorageProfile(s string) (StorageProfile, error) {
switch strings.ToLower(strings.TrimSpace(s)) {
case "", "single":
return ProfileSingle, nil
case "striped":
return ProfileStriped, nil
default:
return 0, fmt.Errorf("%w: %q", ErrInvalidStorageProfile, s)
}
}
// String returns the canonical string representation.
func (p StorageProfile) String() string {
switch p {
case ProfileSingle:
return "single"
case ProfileStriped:
return "striped"
default:
return fmt.Sprintf("unknown(%d)", p)
}
}