Skip to content

Commit

Permalink
Merge pull request #120 from Szum123321/validate_backups_research_1
Browse files Browse the repository at this point in the history
Validate backups research 1
  • Loading branch information
Szum123321 authored Jun 4, 2023
2 parents ef4c69b + 4b4d42c commit 955fbd0
Show file tree
Hide file tree
Showing 61 changed files with 1,483 additions and 873 deletions.
19 changes: 4 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.0-SNAPSHOT'
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'maven-publish'
}

Expand All @@ -17,17 +17,6 @@ repositories {
mavenCentral()
}

loom {
runs {
testServer {
server()
ideConfigGenerated project.rootProject == project
name = "Testmod Server"
source sourceSets.test
}
}
}

dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
Expand All @@ -46,8 +35,8 @@ dependencies {
modImplementation("com.terraformersmc:modmenu:${project.modmenu_version}")

//General compression library
implementation "org.apache.commons:commons-compress:1.21"
include "org.apache.commons:commons-compress:1.21"
implementation "org.apache.commons:commons-compress:1.22"
include "org.apache.commons:commons-compress:1.22"

//LZMA support
implementation 'org.tukaani:xz:1.9'
Expand Down Expand Up @@ -116,7 +105,7 @@ publishing {
}

static def getMcMinor(ver) {
String[] arr = ((String)ver).split("\\.")
String[] arr = ((String)ver).split("[.-]")

if(arr.length < 2) return ver

Expand Down
17 changes: 8 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G

minecraft_version=1.19.2
yarn_mappings=1.19.2+build.28
loader_version=0.14.10
minecraft_version=1.20-rc1
yarn_mappings=1.20-rc1+build.2
loader_version=0.14.21

#Fabric api
fabric_version=0.64.0+1.19.2
fabric_version=0.83.0+1.20

#Cloth Config
cloth_version=8.2.88
cloth_version=11.0.98

#ModMenu
modmenu_version=4.1.0
modmenu_version=7.0.0-beta.2

#Lazy DFU for faster dev start
lazydfu_version=v0.1.3
databreaker_version=0.2.10

#Hash of commit form which parallel gzip will be build
pgzip_commit_hash=af5f5c297e735f3f2df7aa4eb0e19a5810b8aff6

# Mod Properties
mod_version = 2.5.0
mod_version = 3.0.0
maven_group = net.szum123321
archives_base_name = textile_backup
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
82 changes: 61 additions & 21 deletions src/main/java/net/szum123321/textile_backup/Globals.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
/*
* A simple backup mod for Fabric
* Copyright (C) 2022 Szum123321
* A simple backup mod for Fabric
* Copyright (C) 2022 Szum123321
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package net.szum123321.textile_backup;

import net.minecraft.server.MinecraftServer;
import net.szum123321.textile_backup.core.digest.BalticHash;
import net.szum123321.textile_backup.core.digest.Hash;
import net.szum123321.textile_backup.core.Utilities;
import net.szum123321.textile_backup.core.create.MakeBackupRunnable;

import net.szum123321.textile_backup.core.restore.AwaitThread;
import org.apache.commons.io.FileUtils;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.format.DateTimeFormatter;
Expand All @@ -34,19 +37,48 @@
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import java.util.zip.CRC32;

public class Globals {
public static final Globals INSTANCE = new Globals();
private final static TextileLogger log = new TextileLogger(TextileBackup.MOD_NAME);
public final static DateTimeFormatter defaultDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss");
private static final TextileLogger log = new TextileLogger(TextileBackup.MOD_NAME);
public static final DateTimeFormatter defaultDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss");
public static final Supplier<Hash> CHECKSUM_SUPPLIER = BalticHash::new;/*() -> new Hash() {
private final CRC32 crc = new CRC32();
@Override
public void update ( int b){
crc.update(b);
}
@Override
public void update ( long b) {
ByteBuffer v = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN);
v.putLong(b);
crc.update(v.array());
}
@Override
public void update ( byte[] b, int off, int len){
crc.update(b, off, len);
}
private ExecutorService executorService = null;// = Executors.newSingleThreadExecutor();
@Override
public long getValue () {
return crc.getValue();
}
};*/

private ExecutorService executorService = null;//TODO: AAAAAAAAAAAAAAA MEMORY LEAK!!!!!!!!!
public final AtomicBoolean globalShutdownBackupFlag = new AtomicBoolean(true);
public boolean disableWatchdog = false;
private boolean disableTMPFiles = false;
private AwaitThread restoreAwaitThread = null;
private Path lockedPath = null;

private String combinedVersionString;

private Globals() {}

public ExecutorService getQueueExecutor() { return executorService; }
Expand All @@ -64,8 +96,8 @@ public void shutdownQueueExecutor(long timeout) {
if(!executorService.awaitTermination(timeout, TimeUnit.MICROSECONDS)) {
log.error("Timeout occurred while waiting for currently running backups to finish!");
executorService.shutdownNow().stream()
.filter(r -> r instanceof MakeBackupRunnable)
.map(r -> (MakeBackupRunnable)r)
// .filter(r -> r instanceof ExecutableBackup)
// .map(r -> (ExecutableBackup)r)
.forEach(r -> log.error("Dropping: {}", r.toString()));
if(!executorService.awaitTermination(1000, TimeUnit.MICROSECONDS))
log.error("Couldn't shut down the executor!");
Expand All @@ -84,8 +116,8 @@ public void shutdownQueueExecutor(long timeout) {
public Optional<Path> getLockedFile() { return Optional.ofNullable(lockedPath); }
public void setLockedFile(Path p) { lockedPath = p; }

public boolean disableTMPFS() { return disableTMPFiles; }
public void updateTMPFSFlag(MinecraftServer server) {
public synchronized boolean disableTMPFS() { return disableTMPFiles; }
public synchronized void updateTMPFSFlag(MinecraftServer server) {
disableTMPFiles = false;
Path tmp_dir = Path.of(System.getProperty("java.io.tmpdir"));
if(
Expand All @@ -103,4 +135,12 @@ public void updateTMPFSFlag(MinecraftServer server) {

if(disableTMPFiles) log.error("Might cause: https://github.com/Szum123321/textile_backup/wiki/ZIP-Problems");
}

public String getCombinedVersionString() {
return combinedVersionString;
}

public void setCombinedVersionString(String combinedVersionString) {
this.combinedVersionString = combinedVersionString;
}
}
65 changes: 37 additions & 28 deletions src/main/java/net/szum123321/textile_backup/TextileBackup.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/*
A simple backup mod for Fabric
Copyright (C) 2020 Szum123321
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
* A simple backup mod for Fabric
* Copyright (C) 2022 Szum123321
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package net.szum123321.textile_backup;

Expand All @@ -26,6 +26,7 @@
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.command.ServerCommandSource;
import net.szum123321.textile_backup.commands.create.CleanupCommand;
import net.szum123321.textile_backup.commands.create.StartBackupCommand;
Expand All @@ -38,9 +39,9 @@
import net.szum123321.textile_backup.config.ConfigHelper;
import net.szum123321.textile_backup.config.ConfigPOJO;
import net.szum123321.textile_backup.core.ActionInitiator;
import net.szum123321.textile_backup.core.create.BackupContext;
import net.szum123321.textile_backup.core.create.BackupScheduler;
import net.szum123321.textile_backup.core.create.MakeBackupRunnableFactory;
import net.szum123321.textile_backup.core.create.ExecutableBackup;
import net.szum123321.textile_backup.test.BalticHashTest;

public class TextileBackup implements ModInitializer {
public static final String MOD_NAME = "Textile Backup";
Expand All @@ -51,7 +52,13 @@ public class TextileBackup implements ModInitializer {

@Override
public void onInitialize() {
log.info("Starting Textile Backup by Szum123321");
Globals.INSTANCE.setCombinedVersionString(
FabricLoader.getInstance().getModContainer(MOD_ID).orElseThrow().getMetadata().getVersion().getFriendlyString() +
":" +
FabricLoader.getInstance().getModContainer("minecraft").orElseThrow().getMetadata().getVersion().getFriendlyString()
);

log.info("Starting Textile Backup {} by Szum123321", Globals.INSTANCE.getCombinedVersionString());

ConfigHelper.updateInstance(AutoConfig.register(ConfigPOJO.class, JanksonConfigSerializer::new));

Expand All @@ -63,19 +70,21 @@ public void onInitialize() {
Globals.INSTANCE.updateTMPFSFlag(server);
});

//Wait 60s for already submited backups to finish. After that kill the bastards and run the one last if required
//Wait 60s for already submitted backups to finish. After that kill the bastards and run the one last if required
ServerLifecycleEvents.SERVER_STOPPED.register(server -> {
Globals.INSTANCE.shutdownQueueExecutor(60000);

if (config.get().shutdownBackup && Globals.INSTANCE.globalShutdownBackupFlag.get()) {
MakeBackupRunnableFactory.create(
BackupContext.Builder
.newBackupContextBuilder()
.setServer(server)
.setInitiator(ActionInitiator.Shutdown)
.setComment("shutdown")
.build()
).run();
try {
ExecutableBackup.Builder
.newBackupContextBuilder()
.setServer(server)
.setInitiator(ActionInitiator.Shutdown)
.setComment("shutdown")
.announce()
.build()
.call();
} catch (Exception ignored) {}
}
});

Expand Down
15 changes: 8 additions & 7 deletions src/main/java/net/szum123321/textile_backup/TextileLogger.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* A simple backup mod for Fabric
* Copyright (C) 2021 Szum123321
* Copyright (C) 2022 Szum123321
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -23,7 +23,7 @@
import net.minecraft.text.MutableText;
import net.minecraft.util.Formatting;
import net.szum123321.textile_backup.core.Utilities;
import net.szum123321.textile_backup.core.create.BackupContext;
import net.szum123321.textile_backup.core.create.ExecutableBackup;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -94,7 +94,7 @@ boolean sendFeedback(Level level, ServerCommandSource source, String msg, Object
else if(level.intLevel() <= Level.WARN.intLevel()) text.formatted(Formatting.RED);
else text.formatted(Formatting.WHITE);

source.sendFeedback(prefixText.copy().append(text), false);
source.sendFeedback(() -> prefixText.copy().append(text), false);

return true;
} else {
Expand All @@ -112,15 +112,16 @@ public void sendInfo(ServerCommandSource source, String msg, Object... args) {
sendFeedback(Level.INFO, source, msg, args);
}

public void sendInfo(BackupContext context, String msg, Object... args) {
public void sendInfo(ExecutableBackup context, String msg, Object... args) {
sendInfo(context.commandSource(), msg, args);
}

public void sendError(ServerCommandSource source, String msg, Object... args) {
sendFeedback(Level.ERROR, source, msg, args);
}

public void sendError(BackupContext context, String msg, Object... args) {

public void sendError(ExecutableBackup context, String msg, Object... args) {
sendError(context.commandSource(), msg, args);
}

Expand All @@ -134,15 +135,15 @@ public void sendInfoAL(ServerCommandSource source, String msg, Object... args) {
sendToPlayerAndLog(Level.INFO, source, msg, args);
}

public void sendInfoAL(BackupContext context, String msg, Object... args) {
public void sendInfoAL(ExecutableBackup context, String msg, Object... args) {
sendInfoAL(context.commandSource(), msg, args);
}

public void sendErrorAL(ServerCommandSource source, String msg, Object... args) {
sendToPlayerAndLog(Level.ERROR, source, msg, args);
}

public void sendErrorAL(BackupContext context, String msg, Object... args) {
public void sendErrorAL(ExecutableBackup context, String msg, Object... args) {
sendErrorAL(context.commandSource(), msg, args);
}
}
Loading

0 comments on commit 955fbd0

Please sign in to comment.