add additional logging to save thread, stop winsocknetlayer listning on server shutdown

This commit is contained in:
sylvessa 2026-04-06 21:29:32 -05:00
parent 098582dea8
commit 0ccd327b3f
4 changed files with 59 additions and 20 deletions

View file

@ -731,20 +731,37 @@ void ConsoleSaveFileOriginal::Flush(bool autosave, bool updateThumbnail )
s_bgSaveActive.store(true, std::memory_order_release);
std::thread([snap, fileSize, thumb, thumbSz, meta, metaLen, this]() {
app.DebugPrintf("bg-save: thread started, fileSize=%u (%.1f MB)\n", fileSize, fileSize / (1024.0f * 1024.0f));
unsigned int compLen = fileSize + 8;
app.DebugPrintf("bg-save: AllocateSaveData(%u) attempt 1\n", compLen);
byte *buf = static_cast<byte *>(StorageManager.AllocateSaveData(compLen));
if (!buf)
{
// FAIL!! attempt precalc
app.DebugPrintf("bg-save: first alloc failed, computing compressed size...\n");
compLen = 0;
LARGE_INTEGER pcFreq, pcStart, pcEnd;
QueryPerformanceFrequency(&pcFreq);
QueryPerformanceCounter(&pcStart);
Compression::getCompression()->Compress(nullptr, &compLen, snap, fileSize);
QueryPerformanceCounter(&pcEnd);
float precalcSec = (float)(pcEnd.QuadPart - pcStart.QuadPart) / (float)pcFreq.QuadPart;
compLen += 8;
app.DebugPrintf("bg-save: precalc done in %.3f sec, compressed size=%u (%.1f MB)\n", precalcSec, compLen, compLen / (1024.0f * 1024.0f));
app.DebugPrintf("bg-save: AllocateSaveData(%u) attempt 2\n", compLen);
buf = static_cast<byte *>(StorageManager.AllocateSaveData(compLen));
}
if (buf)
{
// COM,PRESS
app.DebugPrintf("bg-save: compressing %u bytes...\n", fileSize);
LARGE_INTEGER pcFreq, pcStart, pcEnd;
QueryPerformanceFrequency(&pcFreq);
QueryPerformanceCounter(&pcStart);
Compression::getCompression()->Compress(buf + 8, &compLen, snap, fileSize);
QueryPerformanceCounter(&pcEnd);
float compSec = (float)(pcEnd.QuadPart - pcStart.QuadPart) / (float)pcFreq.QuadPart;
app.DebugPrintf("bg-save: compressed %u -> %u bytes (%.1f MB -> %.1f MB) in %.3f sec\n",
fileSize, compLen, fileSize / (1024.0f * 1024.0f), compLen / (1024.0f * 1024.0f), compSec);
ZeroMemory(buf, 8);
memcpy(buf + 4, &fileSize, sizeof(fileSize));
@ -757,13 +774,15 @@ void ConsoleSaveFileOriginal::Flush(bool autosave, bool updateThumbnail )
memcpy(s_bgResult.textMeta, meta, sizeof(meta));
s_bgResult.textMetaBytes = metaLen;
s_bgResult.pending = true;
app.DebugPrintf("bg-save: result stored, pending flush on main thread\n");
}
else
{
app.DebugPrintf("save buf alloc failed\n");
app.DebugPrintf("bg-save: ALLOC FAILED - both attempts failed for %u byte world\n", fileSize);
s_bgSaveActive.store(false, std::memory_order_release);
}
delete[] snap;
app.DebugPrintf("bg-save: snapshot freed, thread exiting\n");
}).detach();
return;
}
@ -936,6 +955,7 @@ int ConsoleSaveFileOriginal::SaveSaveDataCallback(LPVOID lpParam,bool bRes)
ConsoleSaveFile *pClass=static_cast<ConsoleSaveFile *>(lpParam);
#ifdef MINECRAFT_SERVER_BUILD
app.DebugPrintf("bg-save: SaveSaveDataCallback fired, success=%d\n", bRes ? 1 : 0);
s_bgSaveActive.store(false, std::memory_order_release);
#endif
@ -1194,13 +1214,14 @@ void ConsoleSaveFileOriginal::flushPendingBackgroundSave()
if (!s_bgResult.pending)
return;
app.DebugPrintf("bg-save: flushing to StorageManager (thumbSize=%u, metaBytes=%d)\n", s_bgResult.thumbSize, s_bgResult.textMetaBytes);
StorageManager.SetSaveImages(
s_bgResult.thumbData, s_bgResult.thumbSize,
nullptr, 0, s_bgResult.textMeta, s_bgResult.textMetaBytes);
StorageManager.SaveSaveData(&ConsoleSaveFileOriginal::SaveSaveDataCallback, s_bgResult.owner);
s_bgResult.pending = false;
// the actual write isnt done until SaveSaveDataCallback fires
app.DebugPrintf("bg-save: StorageManager.SaveSaveData dispatched, awaiting callback\n");
}
bool ConsoleSaveFileOriginal::hasPendingBackgroundSave()