This commit is contained in:
iceBear67 committed 2025-10-02 12:05:00 +08:00
1 parent 482b975c79
commit 072482c12b
5 files changed
+15 -65

No files matched your search

@@ -33,7 +33,6 @@ public class BundleReader {
}
public void extract(Path bundle, Path destination) throws IOException {
var symbolsToLink = new HashMap<String, String>();
var readMaps = new HashMap<String, Long>();
try (var zstd = new ZstdInputStreamNoFinalizer(Files.newInputStream(bundle, StandardOpenOption.READ));
var in = new EntryInputStream(zstd)) {
@@ -119,7 +119,7 @@ public class RegionParser implements Closeable {
case 2 -> new DeflaterInputStream(new ByteBufInputStream(in));
case 3 -> new ByteBufInputStream(in);
case 4 -> new LZ4BlockInputStream(new ByteBufInputStream(in));
// user defined compression algorithm, no going to support.
// user defined compression algorithm, not going to support.
// (or mcc)
default -> throw new IOException("Unsupported compression type. " + compressionType);
};
@@ -44,7 +44,6 @@ public record BackupWorker(
// tmp file path
log.info("Creating bundle {}", tmpBundle);
BundleWriter.createBundle(tmpBundle, subject.changedFiles(), config);
return strategy.createBackup(subject.name(), subject.root(), tmpBundle);
} catch (Exception e) {
throw e;
} finally {
@@ -55,7 +54,9 @@ public record BackupWorker(
log.error("Expect BACKUP state but got {}", BACKUP_LOCK.get());
Thread.sleep(2000);
}
Files.deleteIfExists(tmpBundle);
}
var result = strategy.createBackup(subject.name(), subject.root(), tmpBundle);
Files.deleteIfExists(tmpBundle);
return result;
}
}
@@ -1,60 +0,0 @@
package io.ib67.sfcraft;
import lombok.SneakyThrows;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
public record WorldDir(
Path root
) {
public Path region() {
return root.resolve("region");
}
public Path poi() {
return root.resolve("poi");
}
public Path entities() {
return root.resolve("entities");
}
@SneakyThrows
public List<WorldDir> otherDimensions() {
try (var w = Files.walk(root)) {
return w.filter(it -> Files.exists(it.resolve("region")) && Files.exists(it.resolve("poi")))
.map(WorldDir::new)
.toList();
}
}
/**
* @return Files expect poi, region, entities, playerdata and things in dimension folder.
*/
@SneakyThrows
public List<Path> otherFiles() {
var otherDimensions = otherDimensions();
try (var f = Files.walk(root)) {
return f.filter(it -> Files.isRegularFile(it)
&& otherDimensions.stream().noneMatch(a -> it.startsWith(a.root)))
.filter(it -> !it.getFileName().toString().contains("session.lock"))
.toList();
}
}
@SneakyThrows
public List<Path> everything() {
try (var f = Files.walk(root)) {
return f.filter(Files::isRegularFile)
.filter(it -> !it.getFileName().toString().contains("session.lock"))
.toList();
}
}
}
@@ -31,8 +31,18 @@ public abstract class MixinRegionBasedStorage {
if (witness == IOState.BACKUP) {
// yield out and keep blocking.
// The backup worker will wait for us setting this back to backup.
int i =0;
Globals.BACKUP_LOCK.set(IOState.BACKUP);
while (Globals.BACKUP_LOCK.getAcquire() == IOState.BACKUP) {
if(i==0){
System.out.println("Server is performing backup, ChunkIO will wait for it.");
}
if(i++ > 3000){
System.err.println("WARNING: BACKUP_LOCK is holding for 10 minutes!");
System.err.println("ChunkIO will not wait for backup anymore, writting to disk...");
System.err.println("You may adjust this behaviour in configuration");
break;
}
Thread.sleep(2000);
}
}
@@ -42,7 +52,7 @@ public abstract class MixinRegionBasedStorage {
value.sync();
}
} finally {
// we asserts that there are no other threads calling sync()
// we assert that there are no other threads calling sync()
// so we can just jump back to the witness value.
// witness: AUTO_SAVE or IDLE
Globals.BACKUP_LOCK.compareAndExchange(IOState.STORAGE_SYNC, witness);