Add erasure-coded multi-lane spread foundation.
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Server Reed-Solomon 4+2 shard encode on deploy plans when erasure_lanes_enabled; agents reassemble from parallel lane URLs as staging fallback with BGP/Path Tracer hints.
This commit is contained in:
71
server/internal/erasure/store.go
Normal file
71
server/internal/erasure/store.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package erasure
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// ShardStore holds encoded shard bytes keyed by deploy-plan token.
|
||||
type ShardStore struct {
|
||||
mu sync.RWMutex
|
||||
plans map[string][][]byte
|
||||
params map[string]Params
|
||||
}
|
||||
|
||||
// NewShardStore creates an in-memory shard cache for public erasure-shard endpoints.
|
||||
func NewShardStore() *ShardStore {
|
||||
return &ShardStore{
|
||||
plans: make(map[string][][]byte),
|
||||
params: make(map[string]Params),
|
||||
}
|
||||
}
|
||||
|
||||
// Put stores shards for a token.
|
||||
func (s *ShardStore) Put(token string, p Params, shards [][]byte) {
|
||||
if s == nil || token == "" || len(shards) == 0 {
|
||||
return
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
cp := make([][]byte, len(shards))
|
||||
for i, sh := range shards {
|
||||
cp[i] = append([]byte(nil), sh...)
|
||||
}
|
||||
s.plans[token] = cp
|
||||
s.params[token] = p
|
||||
}
|
||||
|
||||
// Get returns one shard by index.
|
||||
func (s *ShardStore) Get(token string, index int) ([]byte, bool) {
|
||||
if s == nil || token == "" {
|
||||
return nil, false
|
||||
}
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
shards, ok := s.plans[token]
|
||||
if !ok || index < 0 || index >= len(shards) {
|
||||
return nil, false
|
||||
}
|
||||
return append([]byte(nil), shards[index]...), true
|
||||
}
|
||||
|
||||
// ParamsFor returns encoding params for a token.
|
||||
func (s *ShardStore) ParamsFor(token string) (Params, bool) {
|
||||
if s == nil || token == "" {
|
||||
return Params{}, false
|
||||
}
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
p, ok := s.params[token]
|
||||
return p, ok
|
||||
}
|
||||
|
||||
// Delete removes a token (tests / TTL sweeps).
|
||||
func (s *ShardStore) Delete(token string) {
|
||||
if s == nil || token == "" {
|
||||
return
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
delete(s.plans, token)
|
||||
delete(s.params, token)
|
||||
}
|
||||
Reference in New Issue
Block a user