Make SCUM logs live relay only

This commit is contained in:
npc0-hue
2026-09-01 14:26:00 +08:00
parent 3f348401a9
commit 7d9c1b7e9e
28 changed files with 1011 additions and 175 deletions
+59
View File
@@ -12,6 +12,65 @@ import (
const defaultLogQueryLimit = 100
// RelayLiveLogBatch forwards output observed by Run to live subscribers. It
// intentionally updates only stream metadata; the log body is not written to
// the platform log store. Game plugins own durable log storage and analysis.
func (svc *CoreService) RelayLiveLogBatch(batch domain.LogBatchIngest) (domain.LogBatchIngestResult, error) {
batch = domain.CopyLogBatchIngest(batch)
if err := validator.ValidateLogBatchIngest(batch); err != nil {
return domain.LogBatchIngestResult{}, err
}
if err := svc.validateRunSession(batch.RunEndpointID, batch.SessionToken); err != nil {
return domain.LogBatchIngestResult{}, err
}
lock := svc.logIngestLock(batch.ServerInstanceID)
lock.Lock()
stamp := svc.now()
stream, err := svc.store.LogStreams().Get(batch.LogStreamID)
if errors.Is(err, repo.ErrNotFound) {
if repairErr := svc.ensureLogStreamForBatch(batch, stamp); repairErr != nil {
lock.Unlock()
return domain.LogBatchIngestResult{}, repairErr
}
stream, err = svc.store.LogStreams().Get(batch.LogStreamID)
}
if err != nil {
lock.Unlock()
return domain.LogBatchIngestResult{}, err
}
if err := validateLogBatchStream(batch, stream); err != nil {
lock.Unlock()
return domain.LogBatchIngestResult{}, err
}
if batch.LastSeq > stream.LatestSeq {
stream.LatestSeq = batch.LastSeq
}
stream.UpdatedAt = stamp
if err := svc.store.LogStreams().Update(stream); err != nil {
lock.Unlock()
return domain.LogBatchIngestResult{}, err
}
lock.Unlock()
entries := domain.CopyLogEntries(batch.Entries)
// Run may be on a machine whose wall clock is skewed. Relay time is the
// authoritative observation time for this best-effort live event; using it
// keeps the SSE live boundary from treating current output as old history.
for index := range entries {
entries[index].Timestamp = stamp.Add(time.Duration(index) * time.Nanosecond)
}
svc.publishLiveLogEvents(stream, entries)
return domain.LogBatchIngestResult{
Accepted: true,
LogStreamID: batch.LogStreamID,
AcceptedFrom: batch.FirstSeq,
AcceptedTo: batch.LastSeq,
LatestSeq: stream.LatestSeq,
ServerTime: stamp,
}, nil
}
func (svc *CoreService) IngestLogBatch(batch domain.LogBatchIngest) (domain.LogBatchIngestResult, error) {
batch = domain.CopyLogBatchIngest(batch)
if err := validator.ValidateLogBatchIngest(batch); err != nil {