Merge pull request #141 from Szum123321/81_125_test
Merging fixes for the asyn save fiasco
This commit is contained in:
commit
0f467c627e
@ -1,12 +1,12 @@
|
|||||||
# Done to increase the memory available to gradle.
|
# Done to increase the memory available to gradle.
|
||||||
org.gradle.jvmargs=-Xmx1G
|
org.gradle.jvmargs=-Xmx1G
|
||||||
|
|
||||||
minecraft_version=1.20.1
|
minecraft_version=1.20.2-pre3
|
||||||
yarn_mappings=1.20.1+build.10
|
yarn_mappings=1.20.2-pre3+build.5
|
||||||
loader_version=0.14.22
|
loader_version=0.14.22
|
||||||
|
|
||||||
#Fabric api
|
#Fabric api
|
||||||
fabric_version=0.88.1+1.20.1
|
fabric_version=0.88.3+1.20.2
|
||||||
|
|
||||||
#Cloth Config
|
#Cloth Config
|
||||||
cloth_version=11.1.106
|
cloth_version=11.1.106
|
||||||
@ -14,12 +14,11 @@ cloth_version=11.1.106
|
|||||||
#ModMenu
|
#ModMenu
|
||||||
modmenu_version=7.2.2
|
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
|
#Hash of commit form which parallel gzip will be build
|
||||||
pgzip_commit_hash=af5f5c297e735f3f2df7aa4eb0e19a5810b8aff6
|
pgzip_commit_hash=af5f5c297e735f3f2df7aa4eb0e19a5810b8aff6
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 3.1.1
|
mod_version = 3.1.2
|
||||||
maven_group = net.szum123321
|
maven_group = net.szum123321
|
||||||
archives_base_name = textile_backup
|
archives_base_name = textile_backup
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,7 @@ import net.szum123321.textile_backup.config.ConfigHelper;
|
|||||||
import net.szum123321.textile_backup.core.ActionInitiator;
|
import net.szum123321.textile_backup.core.ActionInitiator;
|
||||||
import net.szum123321.textile_backup.core.Cleanup;
|
import net.szum123321.textile_backup.core.Cleanup;
|
||||||
import net.szum123321.textile_backup.core.Utilities;
|
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.ParallelZipCompressor;
|
||||||
import net.szum123321.textile_backup.core.create.compressors.ZipCompressor;
|
import net.szum123321.textile_backup.core.create.compressors.ZipCompressor;
|
||||||
import net.szum123321.textile_backup.core.create.compressors.tar.AbstractTarArchiver;
|
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.nio.file.Path;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
public record ExecutableBackup(@NotNull MinecraftServer server,
|
public record ExecutableBackup(@NotNull MinecraftServer server,
|
||||||
ServerCommandSource commandSource,
|
ServerCommandSource commandSource,
|
||||||
@ -68,11 +71,24 @@ public record ExecutableBackup(@NotNull MinecraftServer server,
|
|||||||
|
|
||||||
log.trace("Outfile is: {}", outFile);
|
log.trace("Outfile is: {}", outFile);
|
||||||
|
|
||||||
try {
|
AtomicReference<Optional<WorldSavingState>> state = new AtomicReference<>(Optional.empty());
|
||||||
//I think I should synchronise these two next calls...
|
|
||||||
Utilities.disableWorldSaving(server);
|
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);
|
Globals.INSTANCE.updateTMPFSFlag(server);
|
||||||
|
|
||||||
log.sendInfoAL(this, "Starting backup");
|
log.sendInfoAL(this, "Starting backup");
|
||||||
@ -128,8 +144,11 @@ public record ExecutableBackup(@NotNull MinecraftServer server,
|
|||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
Utilities.enableWorldSaving(server);
|
if (state.get().isPresent()) {
|
||||||
Globals.INSTANCE.disableWatchdog = false;
|
state.get().get().enable(server);
|
||||||
|
}
|
||||||
|
//Utilities.enableWorldSaving(server);
|
||||||
|
//Globals.INSTANCE.disableWatchdog = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -221,13 +240,6 @@ public record ExecutableBackup(@NotNull MinecraftServer server,
|
|||||||
|
|
||||||
if(announce) v.announce();
|
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;
|
return v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ public class ZipCompressor extends AbstractCompressor {
|
|||||||
|
|
||||||
if(input.getPath().isEmpty()) {
|
if(input.getPath().isEmpty()) {
|
||||||
entry = new ZipArchiveEntry(input.getName());
|
entry = new ZipArchiveEntry(input.getName());
|
||||||
|
|
||||||
//It's basically just
|
//It's basically just
|
||||||
byte[] buff = new byte[(int)input.size()];
|
byte[] buff = new byte[(int)input.size()];
|
||||||
int len = input.getInputStream().read(buff);
|
int len = input.getInputStream().read(buff);
|
||||||
|
Loading…
Reference in New Issue
Block a user