feat: 更新CC码监管方案业务版文档,新增摘要、UGC专项、直播专项、存量处置、误判申诉、水印嵌入、CC码生命周期、组织保障等章节;同步macode到cccode重命名及其他代码变更
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package cccode
|
||||
|
||||
import "sync"
|
||||
|
||||
// MemoryStore 是 AllocationStore 的内存实现(MVP / 测试)。
|
||||
// 生产环境应替换为 PostgreSQL 行锁或 Redis INCR,保证多实例下原子且持久。
|
||||
type MemoryStore struct {
|
||||
mu sync.Mutex
|
||||
cursors map[string]uint64 // segmentKey -> 已分配的最大序列
|
||||
}
|
||||
|
||||
// NewMemoryStore 创建内存分配存储。
|
||||
func NewMemoryStore() *MemoryStore {
|
||||
return &MemoryStore{cursors: make(map[string]uint64)}
|
||||
}
|
||||
|
||||
// Next 原子返回下一个序列:首次取 start,之后递增;超过 end 返回耗尽错误。
|
||||
func (s *MemoryStore) Next(segmentKey string, start, end uint64) (uint64, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
cur, ok := s.cursors[segmentKey]
|
||||
var next uint64
|
||||
if !ok {
|
||||
next = start
|
||||
} else {
|
||||
next = cur + 1
|
||||
}
|
||||
if next > end {
|
||||
return 0, ErrSegmentExhausted
|
||||
}
|
||||
s.cursors[segmentKey] = next
|
||||
return next, nil
|
||||
}
|
||||
|
||||
var _ AllocationStore = (*MemoryStore)(nil)
|
||||
Reference in New Issue
Block a user