From 22527a5d93606f5c8c5d5bffb2354112f161f9ce Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 10 Jun 2024 10:58:50 +0200 Subject: [PATCH] Deletes block repostore folder in container when Codex node stops. --- ProjectPlugins/CodexPlugin/CodexAccess.cs | 8 ++++++++ ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs | 2 +- ProjectPlugins/CodexPlugin/CodexNode.cs | 11 ++++++----- Tests/CodexTests/CodexDistTest.cs | 9 +++++++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/ProjectPlugins/CodexPlugin/CodexAccess.cs b/ProjectPlugins/CodexPlugin/CodexAccess.cs index b63b9f45..ffc9258b 100644 --- a/ProjectPlugins/CodexPlugin/CodexAccess.cs +++ b/ProjectPlugins/CodexPlugin/CodexAccess.cs @@ -126,6 +126,14 @@ namespace CodexPlugin return workflow.GetPodInfo(Container); } + public void DeleteRepoFolder() + { + var containerNumber = Container.Containers.First().Recipe.Number; + var dataDir = $"datadir{containerNumber}"; + var workflow = tools.CreateWorkflow(); + workflow.ExecuteCommand(Container.Containers.First(), "rm", "-Rfv", $"/codex/{dataDir}/repo"); + } + private T OnCodex(Func> action) { var result = tools.CreateHttp(CheckContainerCrashed).OnClient(client => CallCodex(client, action)); diff --git a/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs b/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs index ac29ce18..f1183779 100644 --- a/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs +++ b/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs @@ -119,7 +119,7 @@ namespace CodexPlugin } } - if(!string.IsNullOrEmpty(config.NameOverride)) + if (!string.IsNullOrEmpty(config.NameOverride)) { AddEnvVar("CODEX_NODENAME", config.NameOverride); } diff --git a/ProjectPlugins/CodexPlugin/CodexNode.cs b/ProjectPlugins/CodexPlugin/CodexNode.cs index 5179aae4..4965dbcb 100644 --- a/ProjectPlugins/CodexPlugin/CodexNode.cs +++ b/ProjectPlugins/CodexPlugin/CodexNode.cs @@ -26,6 +26,7 @@ namespace CodexPlugin CrashWatcher CrashWatcher { get; } PodInfo GetPodInfo(); ITransferSpeeds TransferSpeeds { get; } + void DeleteRepoFolder(); void Stop(bool waitTillStopped); } @@ -160,15 +161,15 @@ namespace CodexPlugin return CodexAccess.GetPodInfo(); } + public void DeleteRepoFolder() + { + CodexAccess.DeleteRepoFolder(); + } + public void Stop(bool waitTillStopped) { CrashWatcher.Stop(); Group.Stop(this, waitTillStopped); - // if (Group.Count() > 1) throw new InvalidOperationException("Codex-nodes that are part of a group cannot be " + - // "individually shut down. Use 'BringOffline()' on the group object to stop the group. This method is only " + - // "available for codex-nodes in groups of 1."); - // - // Group.BringOffline(waitTillStopped); } public void EnsureOnlineGetVersionResponse() diff --git a/Tests/CodexTests/CodexDistTest.cs b/Tests/CodexTests/CodexDistTest.cs index 1c184bcd..d3e9beb6 100644 --- a/Tests/CodexTests/CodexDistTest.cs +++ b/Tests/CodexTests/CodexDistTest.cs @@ -38,6 +38,7 @@ namespace CodexTests protected override void LifecycleStop(TestLifecycle lifecycle) { + DeleteBlockRepo(onlineCodexNodes[lifecycle]); onlineCodexNodes.Remove(lifecycle); } @@ -134,5 +135,13 @@ namespace CodexTests if (upload != null) data.Add("avgupload", upload.ToString()); if (download != null) data.Add("avgdownload", download.ToString()); } + + private void DeleteBlockRepo(List codexNodes) + { + foreach (var node in codexNodes) + { + node.DeleteRepoFolder(); + } + } } }