mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Share pack work across studio hotload steps
- Gate studio pack content through the data the trial runtime builds from instead of a second full load - Skip the registry capture's pack re-hash when the caller already verified the fingerprint - Skip boundary store fsyncs for histories whose policy does not sync
This commit is contained in:
1 parent
22c8e68007
commit
3aa302e56c
6 files changed
+70
-32
No files matched your search
@@ -92,10 +92,10 @@ record StudioGenerationUpdate(
|
||||
Path stagingRoot, VerifiedPackTree pack,
|
||||
PackTreeState sourceState) throws IOException {
|
||||
GenerationEpoch active = history.activeEpoch();
|
||||
requireLoadable(pack);
|
||||
IrisData data = IrisData.openRuntime(pack.root().toFile());
|
||||
try {
|
||||
data.useVerifiedGenerationPackFingerprint(pack.fingerprint());
|
||||
requireLoadable(pack, data);
|
||||
IrisDimension replacement = data.getDimensionLoader().load(active.dimensionContract().dimensionKey());
|
||||
if (replacement == null) {
|
||||
throw new IOException("Studio pack update is missing dimension '"
|
||||
@@ -123,8 +123,8 @@ record StudioGenerationUpdate(
|
||||
}
|
||||
}
|
||||
|
||||
private static void requireLoadable(VerifiedPackTree pack) throws IOException {
|
||||
PackValidationResult validation = PackValidator.validate(pack.root().toFile());
|
||||
private static void requireLoadable(VerifiedPackTree pack, IrisData data) throws IOException {
|
||||
PackValidationResult validation = PackValidator.validate(pack.root().toFile(), data);
|
||||
if (!validation.isLoadable()) {
|
||||
throw new IOException("Studio pack update is invalid: " + String.join("; ", validation.getBlockingErrors()));
|
||||
}
|
||||
|
||||
@@ -77,15 +77,23 @@ public final class PackValidator {
|
||||
}
|
||||
|
||||
public static PackValidationResult validate(File packFolder) {
|
||||
return validate(packFolder, true);
|
||||
return validate(packFolder, true, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gates content through {@code loadedPack} instead of a detached loader, so a caller that goes on to build a
|
||||
* runtime from the same data does not load the pack a second time. The data stays open.
|
||||
*/
|
||||
public static PackValidationResult validate(File packFolder, IrisData loadedPack) {
|
||||
return validate(packFolder, true, Objects.requireNonNull(loadedPack, "loadedPack"));
|
||||
}
|
||||
|
||||
public static PackValidationResult validateForDatapackBootstrap(File packFolder) {
|
||||
return validate(packFolder, false);
|
||||
return validate(packFolder, false, null);
|
||||
}
|
||||
|
||||
public static PackValidationResult validateForPackaging(File packFolder) {
|
||||
return validate(packFolder, false);
|
||||
return validate(packFolder, false, null);
|
||||
}
|
||||
|
||||
public static void requireValidObjectSettings(File packFolder, String dimensionKey, JSONObject dimension) {
|
||||
@@ -97,11 +105,13 @@ public final class PackValidator {
|
||||
}
|
||||
}
|
||||
|
||||
private static PackValidationResult validate(File packFolder, boolean validateLiveRegistries) {
|
||||
return PackValidationIo.withinValidationRun(() -> validateWithinRun(packFolder, validateLiveRegistries));
|
||||
private static PackValidationResult validate(File packFolder, boolean validateLiveRegistries,
|
||||
IrisData loadedPack) {
|
||||
return PackValidationIo.withinValidationRun(() -> validateWithinRun(packFolder, validateLiveRegistries, loadedPack));
|
||||
}
|
||||
|
||||
private static PackValidationResult validateWithinRun(File packFolder, boolean validateLiveRegistries) {
|
||||
private static PackValidationResult validateWithinRun(File packFolder, boolean validateLiveRegistries,
|
||||
IrisData loadedPack) {
|
||||
String packName = packFolder == null ? "<unknown>" : packFolder.getName();
|
||||
List<String> blockingErrors = new ArrayList<>();
|
||||
List<String> warnings = new ArrayList<>();
|
||||
@@ -174,7 +184,7 @@ public final class PackValidator {
|
||||
? IrisPlatforms.get().minecraftVersion()
|
||||
: null;
|
||||
List<CompatFinding> compatFindings = validateLiveRegistries
|
||||
? gateContent(packFolder, dimensionFiles, minecraftVersion, blockingErrors, warnings)
|
||||
? gateContent(packFolder, dimensionFiles, minecraftVersion, blockingErrors, warnings, loadedPack)
|
||||
: List.of();
|
||||
|
||||
// Keys the version gate already names in its own line are not repeated as unknown-key findings.
|
||||
@@ -197,14 +207,15 @@ public final class PackValidator {
|
||||
File[] dimensionFiles,
|
||||
String minecraftVersion,
|
||||
List<String> blockingErrors,
|
||||
List<String> warnings
|
||||
List<String> warnings,
|
||||
IrisData loadedPack
|
||||
) {
|
||||
if (!IrisPlatforms.isBound()) {
|
||||
return List.of();
|
||||
}
|
||||
IrisData data = null;
|
||||
try {
|
||||
data = IrisData.openRuntime(packFolder);
|
||||
data = loadedPack == null ? IrisData.openRuntime(packFolder) : loadedPack;
|
||||
if (!data.getContentGate().ready()) {
|
||||
return List.of();
|
||||
}
|
||||
@@ -218,7 +229,7 @@ public final class PackValidator {
|
||||
+ ": " + Objects.requireNonNullElse(e.getMessage(), "No failure detail."));
|
||||
return List.of();
|
||||
} finally {
|
||||
if (data != null) {
|
||||
if (data != null && data != loadedPack) {
|
||||
try {
|
||||
data.close();
|
||||
} catch (Throwable closeFailure) {
|
||||
|
||||
@@ -156,6 +156,10 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
@EqualsAndHashCode.Exclude
|
||||
private transient volatile boolean generationPackFingerprintVerifiedByCaller;
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
@EqualsAndHashCode.Exclude
|
||||
private transient volatile GenerationRegistryContract generationRegistryContract;
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
@@ -232,6 +236,7 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||
dump();
|
||||
clearLists();
|
||||
generationPackFingerprint = null;
|
||||
generationPackFingerprintVerifiedByCaller = false;
|
||||
contentGate = null;
|
||||
dimensionCustomBiomeResourceKeys.clear();
|
||||
}
|
||||
@@ -341,6 +346,11 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||
throw new IllegalStateException("Iris data already has a different generation pack fingerprint.");
|
||||
}
|
||||
generationPackFingerprint = required;
|
||||
generationPackFingerprintVerifiedByCaller = true;
|
||||
}
|
||||
|
||||
public boolean hasCallerVerifiedGenerationPackFingerprint() {
|
||||
return generationPackFingerprintVerifiedByCaller;
|
||||
}
|
||||
|
||||
public boolean hasGenerationRegistryContract() {
|
||||
@@ -710,6 +720,7 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||
IrisObjectScale.invalidate(this);
|
||||
contentGate = null;
|
||||
generationPackFingerprint = null;
|
||||
generationPackFingerprintVerifiedByCaller = false;
|
||||
synchronized (dimensionCustomBiomeResourceKeys) {
|
||||
dimensionCustomBiomeResourceKeys.clear();
|
||||
}
|
||||
|
||||
@@ -63,8 +63,14 @@ public final class GenerationBoundaryStore {
|
||||
|
||||
private final Path dimensionRoot;
|
||||
private final Path directory;
|
||||
private final EpochPolicy policy;
|
||||
|
||||
public GenerationBoundaryStore(Path dimensionRoot) {
|
||||
this(dimensionRoot, EpochPolicy.DURABLE);
|
||||
}
|
||||
|
||||
public GenerationBoundaryStore(Path dimensionRoot, EpochPolicy policy) {
|
||||
this.policy = Objects.requireNonNull(policy, "policy");
|
||||
Path root = Objects.requireNonNull(dimensionRoot, "Dimension root").toAbsolutePath().normalize();
|
||||
this.dimensionRoot = root;
|
||||
this.directory = root.resolve("iris").resolve("generation").resolve("boundaries").normalize();
|
||||
@@ -223,7 +229,7 @@ public final class GenerationBoundaryStore {
|
||||
".activation-" + activationId + SNAPSHOT_FILE_SUFFIX + ".lock"
|
||||
)) {
|
||||
ensureDirectory();
|
||||
PublishedCatalog catalog = builder.publish(directory, activationId);
|
||||
PublishedCatalog catalog = builder.publish(directory, activationId, policy);
|
||||
Path target = snapshotPath(activationId);
|
||||
if (Files.exists(target, LinkOption.NOFOLLOW_LINKS)) {
|
||||
GenerationBoundary existing = load(activationId);
|
||||
@@ -235,7 +241,7 @@ public final class GenerationBoundaryStore {
|
||||
}
|
||||
return existing;
|
||||
}
|
||||
publishAtomic(target, catalog.encoded(), "generation boundary catalog");
|
||||
publishAtomic(target, catalog.encoded(), "generation boundary catalog", policy);
|
||||
return load(activationId);
|
||||
}
|
||||
}
|
||||
@@ -263,7 +269,7 @@ public final class GenerationBoundaryStore {
|
||||
requireSafeDirectory(directory);
|
||||
}
|
||||
|
||||
private static Path ensureChildDirectory(Path parent, String name) throws IOException {
|
||||
private Path ensureChildDirectory(Path parent, String name) throws IOException {
|
||||
Path child = parent.resolve(name);
|
||||
if (Files.exists(child, LinkOption.NOFOLLOW_LINKS)) {
|
||||
requireSafeDirectory(child);
|
||||
@@ -275,7 +281,7 @@ public final class GenerationBoundaryStore {
|
||||
requireSafeDirectory(child);
|
||||
return child;
|
||||
}
|
||||
forceDirectory(parent);
|
||||
forceDirectory(parent, policy);
|
||||
return child;
|
||||
}
|
||||
|
||||
@@ -356,7 +362,8 @@ public final class GenerationBoundaryStore {
|
||||
return withChecksum(bodyBytes.toByteArray());
|
||||
}
|
||||
|
||||
private static void publishAtomic(Path target, byte[] encoded, String kind) throws IOException {
|
||||
private static void publishAtomic(Path target, byte[] encoded, String kind, EpochPolicy policy)
|
||||
throws IOException {
|
||||
Path directory = target.getParent();
|
||||
Path temporary = Files.createTempFile(directory, ".boundary-", ".tmp");
|
||||
try {
|
||||
@@ -366,14 +373,16 @@ public final class GenerationBoundaryStore {
|
||||
StandardOpenOption.TRUNCATE_EXISTING
|
||||
)) {
|
||||
writeFully(channel, ByteBuffer.wrap(encoded));
|
||||
channel.force(true);
|
||||
if (policy.syncs()) {
|
||||
channel.force(true);
|
||||
}
|
||||
}
|
||||
try {
|
||||
Files.move(temporary, target, StandardCopyOption.ATOMIC_MOVE);
|
||||
} catch (AtomicMoveNotSupportedException error) {
|
||||
throw new IOException("Generation boundary " + kind + " publication requires an atomic move", error);
|
||||
}
|
||||
forceDirectory(directory);
|
||||
forceDirectory(directory, policy);
|
||||
} finally {
|
||||
Files.deleteIfExists(temporary);
|
||||
}
|
||||
@@ -482,8 +491,8 @@ public final class GenerationBoundaryStore {
|
||||
}
|
||||
}
|
||||
|
||||
private static void forceDirectory(Path path) throws IOException {
|
||||
if (File.separatorChar == '\\') {
|
||||
private static void forceDirectory(Path path, EpochPolicy policy) throws IOException {
|
||||
if (!policy.syncs() || File.separatorChar == '\\') {
|
||||
return;
|
||||
}
|
||||
try (FileChannel channel = FileChannel.open(path, StandardOpenOption.READ)) {
|
||||
@@ -520,7 +529,7 @@ public final class GenerationBoundaryStore {
|
||||
}
|
||||
}
|
||||
|
||||
private PublishedCatalog publish(Path directory, long activationId) throws IOException {
|
||||
private PublishedCatalog publish(Path directory, long activationId, EpochPolicy policy) throws IOException {
|
||||
if (masks.size() > MAX_REGION_COUNT) {
|
||||
throw new IOException("Generation boundary exceeds the maximum region count");
|
||||
}
|
||||
@@ -528,7 +537,7 @@ public final class GenerationBoundaryStore {
|
||||
sortRegionKeys(regionKeys);
|
||||
Long2ObjectOpenHashMap<String> shardHashes = new Long2ObjectOpenHashMap<>(regionKeys.length);
|
||||
for (long regionKey : regionKeys) {
|
||||
String hash = MaskShard.publish(directory, masks.get(regionKey));
|
||||
String hash = MaskShard.publish(directory, masks.get(regionKey), policy);
|
||||
shardHashes.put(regionKey, hash);
|
||||
}
|
||||
byte[] identity = computeIdentity(activationId, chunkCount, regionKeys, shardHashes);
|
||||
@@ -545,7 +554,7 @@ public final class GenerationBoundaryStore {
|
||||
}
|
||||
|
||||
private static final class MaskShard {
|
||||
private static String publish(Path directory, byte[] mask) throws IOException {
|
||||
private static String publish(Path directory, byte[] mask, EpochPolicy policy) throws IOException {
|
||||
byte[] encoded = encode(mask);
|
||||
String hash = sha256(encoded);
|
||||
Path target = directory.resolve(maskFileName(hash));
|
||||
@@ -555,7 +564,7 @@ public final class GenerationBoundaryStore {
|
||||
return hash;
|
||||
}
|
||||
try {
|
||||
publishAtomic(target, encoded, "mask shard");
|
||||
publishAtomic(target, encoded, "mask shard", policy);
|
||||
} catch (FileAlreadyExistsException race) {
|
||||
requireRegularFile(target, "Generation boundary mask");
|
||||
read(target, hash);
|
||||
|
||||
@@ -69,7 +69,7 @@ public final class GenerationHistory {
|
||||
this.store = Objects.requireNonNull(store, "store");
|
||||
this.ownership = Objects.requireNonNull(ownership, "ownership");
|
||||
this.kernels = Objects.requireNonNull(kernels, "kernels");
|
||||
this.boundaries = new GenerationBoundaryStore(paths.dimensionRoot());
|
||||
this.boundaries = new GenerationBoundaryStore(paths.dimensionRoot(), this.packs.policy());
|
||||
this.terrainSignatures = new TerrainBoundarySignatureStore(paths.dimensionRoot());
|
||||
this.semantics = GenerationSemanticIndex.loadRequired(paths.dimensionRoot(), unpublished);
|
||||
this.savedBiomes = SavedBiomeStore.open(paths.dimensionRoot(), unpublished);
|
||||
|
||||
+12
-5
@@ -260,16 +260,23 @@ public final class GenerationRegistryContractFactory {
|
||||
addPlatformDefinitions(definitions, BLOCK_REGISTRY, referenced.blockKeys(), requiredGenerationRegistry);
|
||||
addPlatformDefinitions(definitions, ENTITY_TYPE_REGISTRY, referenced.entityKeys(), requiredGenerationRegistry);
|
||||
GenerationRegistryContract captured = contract(definitions, generatedSources, requiredGenerationRegistry).withBiomeTags(biomeTags);
|
||||
String actualPackFingerprint = GenerationPackFingerprint.compute(
|
||||
packRoot,
|
||||
GenerationPackFingerprint.CURRENT_VERSION
|
||||
);
|
||||
if (!requiredPackFingerprint.equals(actualPackFingerprint)) {
|
||||
if (!requiredPackFingerprint.equals(packFingerprintAfterCapture(requiredData, packRoot))) {
|
||||
throw new IOException("Iris generation registry capture rejected a changed pack.");
|
||||
}
|
||||
return captured;
|
||||
}
|
||||
|
||||
/**
|
||||
* A pack whose fingerprint the caller verified is immutable for the lifetime of its data, so it is not hashed
|
||||
* again to detect edits made during the capture.
|
||||
*/
|
||||
private static String packFingerprintAfterCapture(IrisData data, Path packRoot) throws IOException {
|
||||
if (data.hasCallerVerifiedGenerationPackFingerprint()) {
|
||||
return data.generationPackFingerprint();
|
||||
}
|
||||
return GenerationPackFingerprint.compute(packRoot, GenerationPackFingerprint.CURRENT_VERSION);
|
||||
}
|
||||
|
||||
public static CustomBiomeDefinition customBiomeDefinition(
|
||||
IrisData data,
|
||||
IrisDimension dimension,
|
||||
|
||||
Reference in new issue
Block a user