From 9c2590747acfdd14f3ecfaa20100772682eafc16 Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Tue, 28 May 2024 14:40:05 +0700 Subject: [PATCH] Try invalidating NFS cache by doing a write Instead of calling `sync`, which doesn't seem to be invalidating the correct NFS dir cache, we'll try to force the NFS cache to be sent to the server by writing a file into the .hg folder, then trying to do an `ls` on the other side. --- backend/LexBoxApi/Services/HgService.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/backend/LexBoxApi/Services/HgService.cs b/backend/LexBoxApi/Services/HgService.cs index 847615f58..baf485f6f 100644 --- a/backend/LexBoxApi/Services/HgService.cs +++ b/backend/LexBoxApi/Services/HgService.cs @@ -69,7 +69,9 @@ await Task.Run(() => { InitRepoAt(new DirectoryInfo(PrefixRepoFilePath(code))); }); - await Process.Start("sync").WaitForExitAsync(); // TODO: Put behind an OS check so we don't break Windows + // TODO 789: In theory this shouldn't need an invalidate call? Try with and without + await InvalidateDirCache(code); + // await Process.Start("sync").WaitForExitAsync(); // TODO: Put behind an OS check so we don't break Windows await WaitForRepoEmptyState(code, RepoEmptyState.Empty); } @@ -108,8 +110,8 @@ public async Task ResetRepo(string code) await SoftDeleteRepo(code, $"{FileUtils.ToTimestamp(DateTimeOffset.UtcNow)}__reset"); //we must init the repo as uploading a zip is optional tmpRepo.MoveTo(PrefixRepoFilePath(code)); - await Process.Start("sync").WaitForExitAsync(); // TODO: Put behind an OS check so we don't break Windows - // await InvalidateDirCache(code); // TODO 789: Sometimes NFS hasn't finished the MoveTo above! So we need to find a way to wait until InvalidateDirCache sees an *empty* repo... + // await Process.Start("sync").WaitForExitAsync(); // TODO: Put behind an OS check so we don't break Windows + await InvalidateDirCache(code); // TODO 789: Does this work now? await WaitForRepoEmptyState(code, RepoEmptyState.Empty); } @@ -144,8 +146,8 @@ await Task.Run(() => // Now we're ready to move the new repo into place, replacing the old one await DeleteRepo(code); tempRepo.MoveTo(PrefixRepoFilePath(code)); - // await InvalidateDirCache(code); - await Process.Start("sync").WaitForExitAsync(); // TODO: Put behind an OS check so we don't break Windows + await InvalidateDirCache(code); + // await Process.Start("sync").WaitForExitAsync(); // TODO: Put behind an OS check so we don't break Windows await WaitForRepoEmptyState(code, RepoEmptyState.NonEmpty); // TODO: Either catch the case where someone uploaded a .zip of an empty .hg repo, or set a timeout in WaitForRepoEmptyState } @@ -274,7 +276,12 @@ public async Task ExecuteHgRecover(string code, CancellationToken t public Task InvalidateDirCache(string code) { - return ExecuteHgCommandServerCommand(code, "invalidatedircache", default); + // TODO: Ensure we don't accidentally re-create a repo we tried to delete by doing the line below + // I.e., check if PrefixRepoFilePath(code) exists and if it doesn't, create and delete it alone + var d = Directory.CreateDirectory(Path.Join(PrefixRepoFilePath(code), ".tmp-invalidate")); // Try to force NFS to invalidate + var result = ExecuteHgCommandServerCommand(code, "invalidatedircache", default); + try { if (d.Exists) d.Delete(); } catch(Exception) {} // Clean up no matter what + return result; } public async Task GetTipHash(string code)