mirror of
https://github.com/nolen777/eagle0.git
synced 2026-07-28 22:55:41 +00:00
Log and persist Eagle cache resume counts
This commit is contained in:
@@ -276,7 +276,11 @@ namespace eagle {
|
||||
|
||||
private void RestoreCachedStateIfAvailable(FactionId? factionId) {
|
||||
var cachedState = EagleGameStateDiskCache.Load(GameId, factionId);
|
||||
if (cachedState == null) { return; }
|
||||
if (cachedState == null) {
|
||||
_connectionLogger.LogLine(
|
||||
$"[STATE_CACHE] Cache miss game={GameId} player={factionId?.ToString() ?? "spectator"}");
|
||||
return;
|
||||
}
|
||||
|
||||
_currentModel.GsView = cachedState.GameStateView;
|
||||
_currentModel.BattalionTypes = cachedState.GameStateView.BattalionTypes.ToDictionary(
|
||||
@@ -289,16 +293,17 @@ namespace eagle {
|
||||
}
|
||||
_lastAppliedUnfilteredCount = cachedState.UnfilteredResultCount;
|
||||
|
||||
RestoreCachedShardokStates(cachedState.ShardokGames);
|
||||
var restoredShardokCount = RestoreCachedShardokStates(cachedState.ShardokGames);
|
||||
|
||||
_connectionLogger.LogLine(
|
||||
$"[STATE_CACHE] Restored game {GameId} at count " +
|
||||
$"{cachedState.UnfilteredResultCount} with " +
|
||||
$"{cachedState.ShardokGames.Count} cached Shardok game(s)");
|
||||
$"{restoredShardokCount}/{cachedState.ShardokGames.Count} cached Shardok game(s)");
|
||||
}
|
||||
|
||||
private void RestoreCachedShardokStates(
|
||||
private int RestoreCachedShardokStates(
|
||||
List<EagleGameStateDiskCache.CachedShardokGameState> cachedShardokStates) {
|
||||
int restoredCount = 0;
|
||||
foreach (var cachedShardokState in cachedShardokStates) {
|
||||
var model = MakeGameModel(cachedShardokState.ShardokGameId);
|
||||
if (model == null) { continue; }
|
||||
@@ -311,7 +316,9 @@ namespace eagle {
|
||||
_currentModel.ShardokGameModels[cachedShardokState.ShardokGameId] = model;
|
||||
_shardokResultCounts[cachedShardokState.ShardokGameId] =
|
||||
cachedShardokState.ResultCount;
|
||||
restoredCount++;
|
||||
}
|
||||
return restoredCount;
|
||||
}
|
||||
|
||||
private ShardokGameModel MakeGameModel(ShardokGameId shardokGameId) {
|
||||
@@ -423,8 +430,13 @@ namespace eagle {
|
||||
_connectionLogger.LogLine(
|
||||
"[UPDATE] Processed update and invoked UpdateAction");
|
||||
} else {
|
||||
RecordAppliedUnfilteredCount(
|
||||
updateItem.ActionResultResponse.UnfilteredResultCountAfter);
|
||||
SaveCurrentStateToCache(
|
||||
updateItem.ActionResultResponse.UnfilteredResultCountAfter);
|
||||
_connectionLogger.LogLine(
|
||||
"[UPDATE] SKIPPED - no results, has commands, token matches");
|
||||
"[UPDATE] SKIPPED - no results, has commands, token matches; " +
|
||||
"persisted accepted count");
|
||||
}
|
||||
|
||||
// Check for turn state mismatch after processing update
|
||||
@@ -736,20 +748,32 @@ namespace eagle {
|
||||
}
|
||||
|
||||
if (countAfter > _lastAppliedUnfilteredCount) {
|
||||
_lastAppliedUnfilteredCount = countAfter;
|
||||
RecordAppliedUnfilteredCount(countAfter);
|
||||
}
|
||||
SaveCurrentStateToCache(countAfter);
|
||||
}
|
||||
|
||||
private void RecordAppliedUnfilteredCount(int countAfter) {
|
||||
if (countAfter <= _lastAppliedUnfilteredCount) { return; }
|
||||
|
||||
_connectionLogger.LogLine(
|
||||
$"[STATE_CACHE] Accepted Eagle count {_lastAppliedUnfilteredCount} -> {countAfter}");
|
||||
_lastAppliedUnfilteredCount = countAfter;
|
||||
}
|
||||
|
||||
private void SaveCurrentStateToCache(int unfilteredResultCount) {
|
||||
if (unfilteredResultCount <= 0 || _currentModel.GsView == null) { return; }
|
||||
|
||||
var cachedShardokStates = CachedShardokGameStates();
|
||||
EagleGameStateDiskCache.Save(
|
||||
GameId,
|
||||
_currentModel.PlayerId,
|
||||
unfilteredResultCount,
|
||||
_currentModel.GsView,
|
||||
CachedShardokGameStates());
|
||||
cachedShardokStates);
|
||||
_connectionLogger.LogLine(
|
||||
$"[STATE_CACHE] Saved game={GameId} count={unfilteredResultCount} " +
|
||||
$"shardokGames={cachedShardokStates.Count}");
|
||||
}
|
||||
|
||||
private void SaveCurrentStateToCache() {
|
||||
|
||||
+6
-1
@@ -285,10 +285,15 @@ namespace eagle {
|
||||
lock (_pendingSubscriptionAcks) { _pendingSubscriptionAcks[gameId] = ackTcs; }
|
||||
|
||||
var shardokCount = shardokStatuses.Count();
|
||||
var streamingTextStatuses = streamGameRequest.StreamingTextStatuses;
|
||||
var completeTextCount = streamingTextStatuses.Count(status => status.KnownComplete);
|
||||
var incompleteTextCount = streamingTextStatuses.Count - completeTextCount;
|
||||
LogFlow($"SUBSCRIBE game={gameId} unfilteredCount={subscriber.LastUnfilteredResultCount} shardokGames={shardokCount}");
|
||||
_remoteEagleClientLogger.LogLine(
|
||||
$"[SUBSCRIBE] Sending StreamGameRequest for game {gameId}, " +
|
||||
$"unfilteredCount={subscriber.LastUnfilteredResultCount}");
|
||||
$"unfilteredCount={subscriber.LastUnfilteredResultCount}, " +
|
||||
$"shardokGames={shardokCount}, completeTexts={completeTextCount}, " +
|
||||
$"incompleteTexts={incompleteTextCount}");
|
||||
|
||||
var sendSuccess = await DoWithStreamingCall(async (sc) => {
|
||||
await sc.RequestStream.WriteAsync(request);
|
||||
|
||||
@@ -1104,10 +1104,19 @@ final case class GameController(
|
||||
0
|
||||
} else knownResultCount
|
||||
|
||||
val knownCompleteTextIds = streamingTextStatuses
|
||||
val knownCompleteTextIds = streamingTextStatuses
|
||||
.filter(_.knownComplete)
|
||||
.map(_.llmIdentifier)
|
||||
.toSet
|
||||
val knownIncompleteTextCount = streamingTextStatuses.count(!_.knownComplete)
|
||||
SimpleTimedLogger.printLogger.logLine(
|
||||
s"[CLIENT-CACHE] game=$gameId user=$userId clientId=$clientId " +
|
||||
s"reportedCount=$knownResultCount acceptedCount=$safeKnownResultCount " +
|
||||
s"serverCount=${fullHistory.count} delta=${fullHistory.count - safeKnownResultCount} " +
|
||||
s"shardokStatuses=${knownShardokResultCounts.size} " +
|
||||
s"knownCompleteTexts=${knownCompleteTextIds.size} " +
|
||||
s"knownIncompleteTexts=$knownIncompleteTextCount"
|
||||
)
|
||||
|
||||
this.withHumanClient(
|
||||
clientTextStore
|
||||
|
||||
Reference in New Issue
Block a user