Documentation
¶
Index ¶
- Constants
- type BatchEntry
- type NodeTypeDataMap
- func (ntdm *NodeTypeDataMap) ExportState() *SavedState
- func (ntdm *NodeTypeDataMap) ImportLegacy(data NodeTypeTrafficMap)
- func (ntdm *NodeTypeDataMap) ImportState(state *SavedState)
- func (ntdm *NodeTypeDataMap) IncrementBatchRetry(nodeType, registerID, batchID string) int
- func (ntdm *NodeTypeDataMap) Pending() map[string]map[string][]*PendingBatch
- func (ntdm *NodeTypeDataMap) RemoveBatch(nodeType, registerID, batchID string)
- func (ntdm *NodeTypeDataMap) ResetAllBatchRetries()
- func (ntdm *NodeTypeDataMap) RetrieveWithoutReset() NodeTypeTrafficMap
- func (ntdm *NodeTypeDataMap) SealIdle(batchSize int, gen func(registerID string) string)
- func (ntdm *NodeTypeDataMap) Update(nodeType string, registerID string, userID int, data *TrafficData)
- type NodeTypeTrafficMap
- type PendingBatch
- type RegisterBuffers
- type RequestDataMap
- type RequestTrafficMap
- type SavedRegisterState
- type SavedState
- type Service
- type TrafficData
- type UserDataMap
- type UserTrafficMap
Constants ¶
const ( ServiceName = "srv_aggregator_submit" DefaultBufferSize = 2048 DefaultWorkerNum = 0 DefaultSubmitInterval = 5 * time.Minute DefaultBatchSize = 5000 // 每批次最大提交用户数,约400KB,避免请求体过大 DefaultMaxRetries = 3 // 最大重试次数,超过后丢弃数据 DefaultSubmitTimeout = 30 * time.Second // 单次提交超时,兜底防止请求卡死 )
const SaveFormatVersion = 2
SaveFormatVersion is the on-disk persistence format version. Version 2 introduced the frozen-batch model (active buffer + sealed batches with stable batch IDs). Files without a version field are treated as legacy (plain traffic, loaded into the active buffer).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BatchEntry ¶ added in v0.4.1
type BatchEntry struct {
UID int `json:"uid"`
Up uint64 `json:"up"`
Down uint64 `json:"down"`
N uint64 `json:"n"`
}
BatchEntry is one user's frozen traffic inside a sealed batch.
type NodeTypeDataMap ¶
func NewNodeTypeDataMap ¶
func NewNodeTypeDataMap() *NodeTypeDataMap
func (*NodeTypeDataMap) ExportState ¶ added in v0.4.1
func (ntdm *NodeTypeDataMap) ExportState() *SavedState
ExportState snapshots the full buffer state for persistence.
func (*NodeTypeDataMap) ImportLegacy ¶ added in v0.4.1
func (ntdm *NodeTypeDataMap) ImportLegacy(data NodeTypeTrafficMap)
ImportLegacy loads pre-v2 persisted traffic (plain nodeType/registerID/user) into the active buffer. Such data is re-sealed with fresh batch IDs.
func (*NodeTypeDataMap) ImportState ¶ added in v0.4.1
func (ntdm *NodeTypeDataMap) ImportState(state *SavedState)
ImportState restores buffer state produced by ExportState.
func (*NodeTypeDataMap) IncrementBatchRetry ¶ added in v0.4.1
func (ntdm *NodeTypeDataMap) IncrementBatchRetry(nodeType, registerID, batchID string) int
IncrementBatchRetry bumps and returns the retry counter for a batch.
func (*NodeTypeDataMap) Pending ¶ added in v0.4.1
func (ntdm *NodeTypeDataMap) Pending() map[string]map[string][]*PendingBatch
Pending returns all in-flight batches as nodeType -> registerID -> batches.
func (*NodeTypeDataMap) RemoveBatch ¶ added in v0.4.1
func (ntdm *NodeTypeDataMap) RemoveBatch(nodeType, registerID, batchID string)
RemoveBatch drops a delivered/discarded batch.
func (*NodeTypeDataMap) ResetAllBatchRetries ¶ added in v0.4.1
func (ntdm *NodeTypeDataMap) ResetAllBatchRetries()
ResetAllBatchRetries clears retry counters on every in-flight batch.
func (*NodeTypeDataMap) RetrieveWithoutReset ¶ added in v0.0.13
func (ntdm *NodeTypeDataMap) RetrieveWithoutReset() NodeTypeTrafficMap
RetrieveWithoutReset returns merged active + sealed traffic, for inspection.
func (*NodeTypeDataMap) SealIdle ¶ added in v0.4.1
func (ntdm *NodeTypeDataMap) SealIdle(batchSize int, gen func(registerID string) string)
SealIdle freezes idle active buffers into new batch generations across all nodeTypes/registerIDs. gen produces a stable batch_id for each new batch.
func (*NodeTypeDataMap) Update ¶
func (ntdm *NodeTypeDataMap) Update(nodeType string, registerID string, userID int, data *TrafficData)
type NodeTypeTrafficMap ¶ added in v0.0.17
type NodeTypeTrafficMap map[string]RequestTrafficMap
type PendingBatch ¶ added in v0.4.1
type PendingBatch struct {
BatchID string `json:"batch_id"`
Entries []BatchEntry `json:"entries"`
Retries int `json:"retries"`
}
PendingBatch is an immutable, sealed chunk of traffic awaiting delivery.
BatchID is generated once at seal time and reused on every retry so the server can deduplicate idempotently (it dedupes by batch_id). Entries never change after sealing: new traffic for the same users accumulates in the active buffer and forms a different batch in a later generation.
type RegisterBuffers ¶ added in v0.1.4
type RegisterBuffers struct {
// contains filtered or unexported fields
}
RegisterBuffers maintains the double-buffer for one registerID:
- active: new traffic still accumulating
- sealed: at most one frozen generation of batches awaiting delivery
Single-generation invariant: while sealed is non-empty the active buffer is NOT sealed again. New traffic keeps accumulating in active and is only sealed once the current generation has fully drained. This keeps each batch's content frozen so its stable batch_id stays valid across retries.
type RequestDataMap ¶ added in v0.1.0
func NewRequestDataMap ¶ added in v0.1.0
func NewRequestDataMap() *RequestDataMap
func (*RequestDataMap) RetrieveWithoutReset ¶ added in v0.1.0
func (rdm *RequestDataMap) RetrieveWithoutReset() RequestTrafficMap
RetrieveWithoutReset returns the merged active + sealed traffic per user without mutating state. Used for inspection and tests.
func (*RequestDataMap) Update ¶ added in v0.1.0
func (rdm *RequestDataMap) Update(registerID string, userID int, data *TrafficData)
Update writes new traffic into the active buffer.
type RequestTrafficMap ¶ added in v0.1.0
type RequestTrafficMap map[string]UserTrafficMap
type SavedRegisterState ¶ added in v0.4.1
type SavedRegisterState struct {
Active UserTrafficMap `json:"active"`
Sealed []*PendingBatch `json:"sealed"`
}
SavedRegisterState is the persisted form of one registerID's buffers.
type SavedState ¶ added in v0.4.1
type SavedState struct {
Version int `json:"version"`
Data map[string]map[string]*SavedRegisterState `json:"data"`
}
SavedState is the versioned on-disk format. Data is nodeType -> registerID -> state.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) AddRequest ¶
func (s *Service) AddRequest(nodeType string, registerID string, userID int, data *TrafficData)
type TrafficData ¶
type UserDataMap ¶
UserDataMap is the active buffer: a mutable map accumulating new traffic.
func NewUserDataMap ¶
func NewUserDataMap() *UserDataMap
func (*UserDataMap) RetrieveAndReset ¶
func (udm *UserDataMap) RetrieveAndReset() UserTrafficMap
RetrieveAndReset returns the non-zero traffic and replaces each retrieved slot with a fresh pooled zero value, leaving the buffer ready for new traffic.
func (*UserDataMap) RetrieveWithoutReset ¶ added in v0.0.13
func (udm *UserDataMap) RetrieveWithoutReset() UserTrafficMap
RetrieveWithoutReset returns a value copy of the non-zero traffic without mutating the buffer.
func (*UserDataMap) Update ¶
func (udm *UserDataMap) Update(userID int, data *TrafficData)
type UserTrafficMap ¶ added in v0.0.17
type UserTrafficMap map[int]*TrafficData