moved saveAll call into the call method of ExecutableBackup and then submitting it to server to execute. my hope is to help with #81 while still repairing #81. Also solved #125

This commit is contained in:
szymon 2023-09-10 22:02:00 +02:00
parent 1eb407338d
commit 8d5740af80
4 changed files with 63 additions and 17 deletions

View File

@ -14,12 +14,11 @@ cloth_version=11.1.106
#ModMenu
modmenu_version=7.2.2
databreaker_version=0.2.10
lazydfu_version=0.1.3
#Hash of commit form which parallel gzip will be build
pgzip_commit_hash=af5f5c297e735f3f2df7aa4eb0e19a5810b8aff6
# Mod Properties
mod_version = 3.1.1
mod_version = 3.1.1-b
maven_group = net.szum123321
archives_base_name = textile_backup

View File

@ -0,0 +1,35 @@
package net.szum123321.textile_backup.core;
import net.minecraft.registry.RegistryKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.World;
import java.util.HashSet;
import java.util.Set;
public class WorldSavingState {
private final Set<RegistryKey<World>> data;
private WorldSavingState(Set<RegistryKey<World>> data) {
this.data = data;
}
public static WorldSavingState disable(MinecraftServer server) {
Set<RegistryKey<World>> data = new HashSet<>();
for (ServerWorld serverWorld : server.getWorlds()) {
if (serverWorld == null || serverWorld.savingDisabled) continue;
serverWorld.savingDisabled = true;
data.add(serverWorld.getRegistryKey());
}
return new WorldSavingState(data);
}
public void enable(MinecraftServer server) {
for (ServerWorld serverWorld : server.getWorlds()) {
if (serverWorld != null && data.contains(serverWorld.getRegistryKey()))
serverWorld.savingDisabled = false;
}
}
}

View File

@ -9,6 +9,7 @@ import net.szum123321.textile_backup.config.ConfigHelper;
import net.szum123321.textile_backup.core.ActionInitiator;
import net.szum123321.textile_backup.core.Cleanup;
import net.szum123321.textile_backup.core.Utilities;
import net.szum123321.textile_backup.core.WorldSavingState;
import net.szum123321.textile_backup.core.create.compressors.ParallelZipCompressor;
import net.szum123321.textile_backup.core.create.compressors.ZipCompressor;
import net.szum123321.textile_backup.core.create.compressors.tar.AbstractTarArchiver;
@ -20,7 +21,9 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.time.LocalDateTime;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicReference;
public record ExecutableBackup(@NotNull MinecraftServer server,
ServerCommandSource commandSource,
@ -68,11 +71,24 @@ public record ExecutableBackup(@NotNull MinecraftServer server,
log.trace("Outfile is: {}", outFile);
try {
//I think I should synchronise these two next calls...
Utilities.disableWorldSaving(server);
AtomicReference<Optional<WorldSavingState>> state = new AtomicReference<>(Optional.empty());
try {
//Globals.INSTANCE.disableWatchdog = true;
//I think I should synchronise these two next calls...
//Execute following call on the server executor
server.submitAndJoin(() -> {
if (save) { //save the world
// We need to flush everything as next thing we'll be copying all the files.
// this is mostly the reason for #81 - minecraft doesn't flush during scheduled saves.
log.sendInfoAL(this.commandSource, "Saving server...");
server.saveAll(true, true, false);
}
state.set(Optional.of(WorldSavingState.disable(server)));
});
Globals.INSTANCE.disableWatchdog = true;
Globals.INSTANCE.updateTMPFSFlag(server);
log.sendInfoAL(this, "Starting backup");
@ -128,8 +144,11 @@ public record ExecutableBackup(@NotNull MinecraftServer server,
throw e;
} finally {
Utilities.enableWorldSaving(server);
Globals.INSTANCE.disableWatchdog = false;
if (state.get().isPresent()) {
state.get().get().enable(server);
}
//Utilities.enableWorldSaving(server);
//Globals.INSTANCE.disableWatchdog = false;
}
return null;
@ -221,13 +240,6 @@ public record ExecutableBackup(@NotNull MinecraftServer server,
if(announce) v.announce();
if (save) { //save the world
// We need to flush everything as next thing we'll be copying all the files.
// this is mostly the reason for #81 - minecraft doesn't flush during scheduled saves.
log.sendInfoAL(this.commandSource, "Saving server...");
server.saveAll(true, true, false);
}
return v;
}
}