Skip to content

Commit

Permalink
Revert "Add max-chunk-lifetime setting used by chunk gc (SpongePowere…
Browse files Browse the repository at this point in the history
…d#3167) - fixed (SpongePowered#3206)"

This reverts commit a0a5428
  • Loading branch information
PolyacovYury committed Jan 9, 2021
1 parent ebb9bfc commit 6805a59
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ public interface ChunkBridge {

boolean bridge$isQueuedForUnload();

long bridge$getLastSaveTime();

boolean bridge$isChunkDirty();

void bridge$markChunkDirty();

boolean bridge$isActive();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,6 @@ public class WorldCategory extends ConfigCategory {
+ "and increases the chance for a drop in tps. (Default: 100)")
private int maxChunkUnloads = 100;

@Setting(value = "max-chunk-lifetime", comment = ""
+ "The number of ticks a chunk will stay in memory without saving.\n"
+ "Note: this setting only applies to chunks gc forcibly saving chunks\n"
+ "(controlled by 'chunk-gc-tick-interval' and 'chunk-gc-load-threshold')\n"
+ "Note: Useless if 'auto-save-interval' is enabled and less than this value\n"
+ "Note: 'auto-save-interval' becomes mostly useless if both are enabled and\n"
+ "it is bigger than this value\n"
+ "(Default: 0)")
private int maxChunkLifetime = 0;

@Setting(value = "chunk-gc-load-threshold", comment = ""
+ "The number of newly loaded chunks before triggering a forced cleanup.\n"
+ "Note: When triggered, the loaded chunk threshold will reset and start incrementing.\n"
Expand Down Expand Up @@ -238,10 +228,6 @@ public int getMaxChunkUnloads() {
return this.maxChunkUnloads;
}

public int getMaxChunkLifetime() {
return this.maxChunkLifetime;
}

public double getItemMergeRadius() {
return this.itemMergeRadius;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public abstract class ChunkMixin implements ChunkBridge, CacheKeyBridge {
@Shadow private boolean loaded;
@Shadow private boolean dirty;
@Shadow public boolean unloadQueued;
@Shadow private long lastSaveTime;

@Shadow @Nullable public abstract TileEntity getTileEntity(BlockPos pos, net.minecraft.world.chunk.Chunk.EnumCreateEntityType p_177424_2_);
@Shadow public abstract void generateSkylightMap();
Expand Down Expand Up @@ -156,21 +155,11 @@ public abstract class ChunkMixin implements ChunkBridge, CacheKeyBridge {
this.dirty = true;
}

@Override
public boolean bridge$isChunkDirty() {
return this.dirty;
}

@Override
public boolean bridge$isQueuedForUnload() {
return this.unloadQueued;
}

@Override
public long bridge$getLastSaveTime() {
return this.lastSaveTime;
}

@Override
public boolean bridge$isPersistedChunk() {
return this.impl$persistedChunk;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public abstract class ChunkProviderServerMixin implements ChunkProviderServerBri
private boolean impl$forceChunkRequests = false;
private long impl$chunkUnloadDelay = Constants.World.DEFAULT_CHUNK_UNLOAD_DELAY;
private int impl$maxChunkUnloads = Constants.World.MAX_CHUNK_UNLOADS;
private int impl$maxChunkLifetime = Constants.World.MAX_CHUNK_LIFETIME;

@Shadow @Final private WorldServer world;
@Shadow @Final private IChunkLoader chunkLoader;
Expand All @@ -109,7 +108,6 @@ public abstract class ChunkProviderServerMixin implements ChunkProviderServerBri
this.impl$denyChunkRequests = worldCategory.getDenyChunkRequests();
this.impl$chunkUnloadDelay = worldCategory.getChunkUnloadDelay() * 1000;
this.impl$maxChunkUnloads = worldCategory.getMaxChunkUnloads();
this.impl$maxChunkLifetime = worldCategory.getMaxChunkLifetime();
}

@Override
Expand Down Expand Up @@ -270,34 +268,22 @@ public boolean tick()
final Iterator<Chunk> iterator = this.loadedChunks.values().iterator();
int chunksUnloaded = 0;
final long now = System.currentTimeMillis();
final long world_time = this.world.getTotalWorldTime();
while (chunksUnloaded < this.impl$maxChunkUnloads && iterator.hasNext()) {
final Chunk chunk = iterator.next();
final ChunkBridge spongeChunk = (ChunkBridge) chunk;
if (chunk == null || spongeChunk.bridge$isPersistedChunk()) {
continue;
}
if (chunk.unloadQueued) {
if (chunk != null && chunk.unloadQueued && !spongeChunk.bridge$isPersistedChunk()) {
if (this.bridge$getChunkUnloadDelay() > 0) {
if ((now - spongeChunk.bridge$getScheduledForUnload()) < this.impl$chunkUnloadDelay) {
continue;
}
spongeChunk.bridge$setScheduledForUnload(-1);
}
chunk.onUnload();
}
// max lifetime only applies to chunks that should stay loaded but still need saving once in a while
else if (this.impl$maxChunkLifetime <= 0 // if setting is disabled
|| !spongeChunk.bridge$isChunkDirty() // no need to save non-dirty chunks
|| world_time - spongeChunk.bridge$getLastSaveTime() < this.impl$maxChunkLifetime) {
continue; // don't save chunk data
}
this.saveChunkData(chunk);
this.saveChunkExtraData(chunk);
if (chunk.unloadQueued) { // chunks not queued to unload stay loaded
this.saveChunkData(chunk);
this.saveChunkExtraData(chunk);
iterator.remove();
chunksUnloaded++;
}
chunksUnloaded++;
}
((WorldServerBridge) this.world).bridge$getTimingsHandler().doChunkUnload.stopTiming();
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/spongepowered/common/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ public static final class World {
public static final UUID INVALID_WORLD_UUID = java.util.UUID.fromString("00000000-0000-0000-0000-000000000000");
public static final int DEFAULT_CHUNK_UNLOAD_DELAY = 15000;
public static final int MAX_CHUNK_UNLOADS = 100;
public static final int MAX_CHUNK_LIFETIME = 0;
public static final String GENERATE_BONUS_CHEST = "GenerateBonusChest";
public static final int CHUNK_UNLOAD_DELAY = 30000;
public static final int END_DIMENSION_ID = 1;
Expand Down

0 comments on commit 6805a59

Please sign in to comment.