forked from SteamWar/SteamWar
Wrap CheckpointUtils for OpenJDK support, remove Border debug messages
This commit is contained in:
@@ -64,7 +64,6 @@ public class Border {
|
|||||||
|
|
||||||
ghostBarriers.put(player.getUniqueId(), new HashSet<>());
|
ghostBarriers.put(player.getUniqueId(), new HashSet<>());
|
||||||
lastLocation.put(player.getUniqueId(), player.getLocation());
|
lastLocation.put(player.getUniqueId(), player.getLocation());
|
||||||
FightSystem.getPlugin().getLogger().log(Level.INFO, () -> player.getName() + " was added to border " + name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(Player player) {
|
public boolean contains(Player player) {
|
||||||
@@ -72,7 +71,6 @@ public class Border {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removePlayer(Player player) {
|
public void removePlayer(Player player) {
|
||||||
FightSystem.getPlugin().getLogger().log(Level.INFO, () -> player.getName() + " was removed from border " + name);
|
|
||||||
lastLocation.remove(player.getUniqueId());
|
lastLocation.remove(player.getUniqueId());
|
||||||
Set<Block> blocks = ghostBarriers.remove(player.getUniqueId());
|
Set<Block> blocks = ghostBarriers.remove(player.getUniqueId());
|
||||||
if(blocks == null || !player.isOnline())
|
if(blocks == null || !player.isOnline())
|
||||||
|
|||||||
@@ -45,103 +45,122 @@ public class CheckpointUtils {
|
|||||||
private CheckpointUtils() {}
|
private CheckpointUtils() {}
|
||||||
|
|
||||||
public static void signalHandler() {
|
public static void signalHandler() {
|
||||||
Signal.handle(new Signal("USR1"), signal -> Bukkit.getScheduler().runTask(Core.getInstance(), CheckpointUtils::freeze));
|
try {
|
||||||
|
J9Wrapper.signalHandler();
|
||||||
|
} catch (NoClassDefFoundError e) {
|
||||||
|
//ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void freeze() {
|
public static void freeze() {
|
||||||
String checkpointFile = System.getProperty("checkpoint");
|
|
||||||
if(!CRIUSupport.isCheckpointAllowed() || checkpointFile == null) {
|
|
||||||
Bukkit.shutdown();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Bukkit.getOnlinePlayers().forEach(player -> player.kickPlayer(null));
|
|
||||||
|
|
||||||
List<?> networkManagers = TinyProtocol.networkManagers.get(TinyProtocol.getServerConnection(Core.getInstance()));
|
|
||||||
if(!Bukkit.getOnlinePlayers().isEmpty() || !networkManagers.isEmpty()) {
|
|
||||||
Core.getInstance().getLogger().log(Level.INFO, "Waiting for players to disconnect for checkpointing");
|
|
||||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), CheckpointUtils::freeze, 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Path path = FileSystems.getDefault().getPath(checkpointFile);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
freezeInternal(path);
|
J9Wrapper.freeze();
|
||||||
} catch (Exception e) {
|
} catch (NoClassDefFoundError e) {
|
||||||
String message = e.getMessage() != null ? e.getMessage() : "";
|
//ignore
|
||||||
if(message.contains("Connected TCP socket")) {
|
}
|
||||||
Core.getInstance().getLogger().log(Level.INFO, "Connected TCP socket, waiting for checkpointing");
|
}
|
||||||
|
|
||||||
|
private static class J9Wrapper {
|
||||||
|
private static void signalHandler() {
|
||||||
|
Signal.handle(new Signal("USR1"), signal -> Bukkit.getScheduler().runTask(Core.getInstance(), CheckpointUtils::freeze));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void freeze() {
|
||||||
|
String checkpointFile = System.getProperty("checkpoint");
|
||||||
|
if(!CRIUSupport.isCheckpointAllowed() || checkpointFile == null) {
|
||||||
|
Bukkit.shutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bukkit.getOnlinePlayers().forEach(player -> player.kickPlayer(null));
|
||||||
|
|
||||||
|
List<?> networkManagers = TinyProtocol.networkManagers.get(TinyProtocol.getServerConnection(Core.getInstance()));
|
||||||
|
if(!Bukkit.getOnlinePlayers().isEmpty() || !networkManagers.isEmpty()) {
|
||||||
|
Core.getInstance().getLogger().log(Level.INFO, "Waiting for players to disconnect for checkpointing");
|
||||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), CheckpointUtils::freeze, 1);
|
Bukkit.getScheduler().runTaskLater(Core.getInstance(), CheckpointUtils::freeze, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.shutdown();
|
Path path = FileSystems.getDefault().getPath(checkpointFile);
|
||||||
|
|
||||||
if(!message.contains("Can't dump ghost file") && !message.contains("Can't create link remap")) // File/Jar has been updated
|
try {
|
||||||
throw new SecurityException(e);
|
freezeInternal(path);
|
||||||
} finally {
|
} catch (Exception e) {
|
||||||
// Delete checkpoint
|
String message = e.getMessage() != null ? e.getMessage() : "";
|
||||||
try (Stream<Path> stream = Files.walk(path)) {
|
if(message.contains("Connected TCP socket")) {
|
||||||
stream.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
|
Core.getInstance().getLogger().log(Level.INFO, "Connected TCP socket, waiting for checkpointing");
|
||||||
} catch (IOException e) {
|
Bukkit.getScheduler().runTaskLater(Core.getInstance(), CheckpointUtils::freeze, 1);
|
||||||
//ignore
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bukkit.shutdown();
|
||||||
|
|
||||||
|
if(!message.contains("Can't dump ghost file") && !message.contains("Can't create link remap")) // File/Jar has been updated
|
||||||
|
throw new SecurityException(e);
|
||||||
|
} finally {
|
||||||
|
// Delete checkpoint
|
||||||
|
try (Stream<Path> stream = Files.walk(path)) {
|
||||||
|
stream.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
|
||||||
|
} catch (IOException e) {
|
||||||
|
//ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static final Reflection.FieldAccessor<List> channelFutures = Reflection.getField(TinyProtocol.serverConnection, List.class, 0, ChannelFuture.class);
|
|
||||||
private static final Reflection.MethodInvoker bind = Reflection.getMethod(TinyProtocol.serverConnection, null, InetAddress.class, int.class);
|
|
||||||
private static void freezeInternal(Path path) throws Exception {
|
|
||||||
Bukkit.getPluginManager().callEvent(new CRIUSleepEvent());
|
|
||||||
Bukkit.getWorlds().forEach(FlatteningWrapper.impl::syncSave);
|
|
||||||
Statement.closeAll();
|
|
||||||
|
|
||||||
// Close socket
|
private static final Reflection.FieldAccessor<List> channelFutures = Reflection.getField(TinyProtocol.serverConnection, List.class, 0, ChannelFuture.class);
|
||||||
Via.getManager().getInjector().uninject();
|
private static final Reflection.MethodInvoker bind = Reflection.getMethod(TinyProtocol.serverConnection, null, InetAddress.class, int.class);
|
||||||
Object serverConnection = TinyProtocol.getServerConnection(Core.getInstance());
|
private static void freezeInternal(Path path) throws Exception {
|
||||||
List<?> channels = channelFutures.get(serverConnection);
|
Bukkit.getPluginManager().callEvent(new CRIUSleepEvent());
|
||||||
for(Object future : channels) {
|
Bukkit.getWorlds().forEach(FlatteningWrapper.impl::syncSave);
|
||||||
((ChannelFuture) future).channel().close().syncUninterruptibly();
|
Statement.closeAll();
|
||||||
}
|
|
||||||
channels.clear();
|
|
||||||
|
|
||||||
System.runFinalization();
|
// Close socket
|
||||||
System.gc();
|
Via.getManager().getInjector().uninject();
|
||||||
|
Object serverConnection = TinyProtocol.getServerConnection(Core.getInstance());
|
||||||
// Do the checkpoint
|
List<?> channels = channelFutures.get(serverConnection);
|
||||||
path.toFile().mkdirs();
|
|
||||||
CRIUSupport criu = new CRIUSupport(path);
|
|
||||||
criu.setAutoDedup(true);
|
|
||||||
criu.setFileLocks(true);
|
|
||||||
criu.setShellJob(true);
|
|
||||||
criu.setLogFile("criu.log");
|
|
||||||
try {
|
|
||||||
criu.checkpointJVM();
|
|
||||||
} catch (JVMCRIUException e) {
|
|
||||||
Path logfile = path.resolve("criu.log");
|
|
||||||
if(logfile.toFile().exists())
|
|
||||||
throw new IllegalStateException("Could not create checkpoint, criu log:\n" + new String(Files.readAllBytes(logfile)), e);
|
|
||||||
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get new port
|
|
||||||
int port;
|
|
||||||
try (DataInputStream stream = new DataInputStream(Files.newInputStream(path.resolve("port").toFile().toPath()))) {
|
|
||||||
port = stream.readInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reopen socket
|
|
||||||
bind.invoke(serverConnection, InetAddress.getLoopbackAddress(), port);
|
|
||||||
if(Core.getVersion() > 12) {
|
|
||||||
for(Object future : channels) {
|
for(Object future : channels) {
|
||||||
((ChannelFuture) future).channel().config().setAutoRead(true);
|
((ChannelFuture) future).channel().close().syncUninterruptibly();
|
||||||
}
|
}
|
||||||
}
|
channels.clear();
|
||||||
Via.getManager().getInjector().inject();
|
|
||||||
|
|
||||||
Bukkit.getPluginManager().callEvent(new CRIUWakeupEvent());
|
System.runFinalization();
|
||||||
Core.getInstance().getLogger().log(Level.INFO, "Checkpoint restored");
|
System.gc();
|
||||||
|
|
||||||
|
// Do the checkpoint
|
||||||
|
path.toFile().mkdirs();
|
||||||
|
CRIUSupport criu = new CRIUSupport(path);
|
||||||
|
criu.setAutoDedup(true);
|
||||||
|
criu.setFileLocks(true);
|
||||||
|
criu.setShellJob(true);
|
||||||
|
criu.setLogFile("criu.log");
|
||||||
|
try {
|
||||||
|
criu.checkpointJVM();
|
||||||
|
} catch (JVMCRIUException e) {
|
||||||
|
Path logfile = path.resolve("criu.log");
|
||||||
|
if(logfile.toFile().exists())
|
||||||
|
throw new IllegalStateException("Could not create checkpoint, criu log:\n" + new String(Files.readAllBytes(logfile)), e);
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get new port
|
||||||
|
int port;
|
||||||
|
try (DataInputStream stream = new DataInputStream(Files.newInputStream(path.resolve("port").toFile().toPath()))) {
|
||||||
|
port = stream.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reopen socket
|
||||||
|
bind.invoke(serverConnection, InetAddress.getLoopbackAddress(), port);
|
||||||
|
if(Core.getVersion() > 12) {
|
||||||
|
for(Object future : channels) {
|
||||||
|
((ChannelFuture) future).channel().config().setAutoRead(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Via.getManager().getInjector().inject();
|
||||||
|
|
||||||
|
Bukkit.getPluginManager().callEvent(new CRIUWakeupEvent());
|
||||||
|
Core.getInstance().getLogger().log(Level.INFO, "Checkpoint restored");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user