Several fixes to actual, probable and possible synchronocity issues (#691)

* Several fixes to actual, probable and possible synchronocity issues
 - Ensure that all edits are queued onto the same AsyncNotifyQueue by actually delegating to the parent player in PlayerProxy
 - Ensure that the order editsessions are being remembered on the LocalSession is being respected by using a fair ReentrentLock
 - Ensure a chunk cannot be called when an update is being called

* Don't add locks to GetBlocks
Dieser Commit ist enthalten in:
dordsor21 2020-10-08 21:15:05 +01:00 committet von MattBDev
Ursprung e19c537f62
Commit 0021aeb40a
6 geänderte Dateien mit 111 neuen und 97 gelöschten Zeilen

Datei anzeigen

@ -106,7 +106,7 @@ public class BukkitGetBlocks_1_15_2_Copy extends BukkitGetBlocks_1_15_2 {
}
protected void storeSection(int layer) {
update(layer, blocks[layer]);
blocks[layer] = update(layer, null).clone();
}
@Override

Datei anzeigen

@ -107,7 +107,7 @@ public class BukkitGetBlocks_1_16_1_Copy extends BukkitGetBlocks_1_16_1 {
}
protected void storeSection(int layer) {
update(layer, blocks[layer]);
blocks[layer] = update(layer, null).clone();
}
@Override

Datei anzeigen

@ -107,7 +107,7 @@ public class BukkitGetBlocks_1_16_2_Copy extends BukkitGetBlocks_1_16_2 {
}
protected void storeSection(int layer) {
update(layer, blocks[layer]);
blocks[layer] = update(layer, null).clone();
}
@Override

Datei anzeigen

@ -92,9 +92,12 @@ import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Random;
import java.util.TimeZone;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -116,7 +119,7 @@ public class LocalSession implements TextureHolder {
// Session related
private transient RegionSelector selector = new CuboidRegionSelector();
private transient boolean placeAtPos1 = false;
private transient List<Object> history = Collections.synchronizedList(new LinkedList<Object>() {
private final transient List<Object> history = Collections.synchronizedList(new LinkedList<Object>() {
@Override
public Object get(int index) {
Object value = super.get(index);
@ -135,6 +138,7 @@ public class LocalSession implements TextureHolder {
private transient volatile Integer historyNegativeIndex;
private transient ClipboardHolder clipboard;
private transient final Object clipboardLock = new Object();
private transient final Lock historyWriteLock = new ReentrantLock(true);
private transient boolean superPickaxe = false;
private transient BlockTool pickaxeMode = new SinglePickaxe();
private final transient Int2ObjectOpenHashMap<Tool> tools = new Int2ObjectOpenHashMap<>(0);
@ -439,7 +443,9 @@ public class LocalSession implements TextureHolder {
return null;
}
public synchronized void remember(Identifiable player, World world, ChangeSet changeSet, FaweLimit limit) {
public void remember(Identifiable player, World world, ChangeSet changeSet, FaweLimit limit) {
historyWriteLock.lock();
try {
if (Settings.IMP.HISTORY.USE_DISK) {
LocalSession.MAX_HISTORY_SIZE = Integer.MAX_VALUE;
}
@ -480,9 +486,14 @@ public class LocalSession implements TextureHolder {
historySize -= size;
}
}
} finally {
historyWriteLock.unlock();
}
}
public synchronized void remember(EditSession editSession, boolean append, int limitMb) {
public void remember(EditSession editSession, boolean append, int limitMb) {
historyWriteLock.lock();
try {
if (Settings.IMP.HISTORY.USE_DISK) {
LocalSession.MAX_HISTORY_SIZE = Integer.MAX_VALUE;
}
@ -491,12 +502,6 @@ public class LocalSession implements TextureHolder {
if (editSession.getChangeSet() == null || limitMb == 0 || historySize >> 20 > limitMb && !append) {
return;
}
/*
// Don't store anything if no changes were made
if (editSession.size() == 0) {
return;
}
*/
ChangeSet changeSet = editSession.getChangeSet();
if (changeSet.isEmpty()) {
@ -543,6 +548,9 @@ public class LocalSession implements TextureHolder {
long size = MainUtil.getSize(item);
historySize -= size;
}
} finally {
historyWriteLock.unlock();
}
}
/**

Datei anzeigen

@ -684,6 +684,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
* @param async TODO description
* @return false if the task was ran or queued
*/
@Override
public boolean runAction(Runnable ifFree, boolean checkFree, boolean async) {
if (checkFree) {
if (runningCount.get() != 0) {

Datei anzeigen

@ -83,6 +83,11 @@ public class PlayerProxy extends AbstractPlayerActor {
return basePlayer.getBlockInHand(handSide);
}
@Override
public boolean runAction(Runnable ifFree, boolean checkFree, boolean async) {
return basePlayer.runAction(ifFree, checkFree, async);
}
@Override
public UUID getUniqueId() {
return basePlayer.getUniqueId();