Skip to content

Commit

Permalink
Use safe version for seednodes (#3452)
Browse files Browse the repository at this point in the history
* Apply shutdown and memory check again

To not risk issues with the release and seed nodes we merge back the
old code base for handling memory check and shutdowns.
The newly added changes for cross connecting between seed nodes cause
out of memory issues and require more work and testing before it can be
used.

* Revert code change for periodic updates between seed nodes.

The periodic updates code caused out of memory issues and require more
work and testing before it can be used.
  • Loading branch information
chimp1984 authored and ripcurlx committed Oct 23, 2019
1 parent d591763 commit f0242bf
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
33 changes: 29 additions & 4 deletions core/src/main/java/bisq/core/app/misc/ExecutableForAppWithP2p.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public abstract class ExecutableForAppWithP2p extends BisqExecutable implements UncaughtExceptionHandler {
private static final long MAX_MEMORY_MB_DEFAULT = 500;
private static final long MAX_MEMORY_MB_DEFAULT = 1200;
private static final long CHECK_MEMORY_PERIOD_SEC = 300;
private static final long CHECK_SHUTDOWN_SEC = TimeUnit.HOURS.toSeconds(1);
private static final long SHUTDOWN_INTERVAL = TimeUnit.HOURS.toMillis(24);
private volatile boolean stopped;
private final long startTime = System.currentTimeMillis();
private static long maxMemory = MAX_MEMORY_MB_DEFAULT;

public ExecutableForAppWithP2p(String fullName, String scriptName, String version) {
Expand Down Expand Up @@ -120,6 +124,20 @@ protected void keepRunning() {
}
}

protected void startShutDownInterval(GracefulShutDownHandler gracefulShutDownHandler) {
UserThread.runPeriodically(() -> {
if (System.currentTimeMillis() - startTime > SHUTDOWN_INTERVAL) {
log.warn("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" +
"Shut down as node was running longer as {} hours" +
"\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n",
SHUTDOWN_INTERVAL / 3600000);

shutDown(gracefulShutDownHandler);
}

}, CHECK_SHUTDOWN_SEC);
}

protected void checkMemory(BisqEnvironment environment, GracefulShutDownHandler gracefulShutDownHandler) {
String maxMemoryOption = environment.getProperty(AppOptionKeys.MAX_MEMORY);
if (maxMemoryOption != null && !maxMemoryOption.isEmpty()) {
Expand Down Expand Up @@ -153,16 +171,24 @@ protected void checkMemory(BisqEnvironment environment, GracefulShutDownHandler
long usedMemory = Profiler.getUsedMemoryInMB();
if (usedMemory > maxMemory) {
log.warn("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" +
"We are over our memory limit ({}) and trigger a restart. usedMemory: {} MB. freeMemory: {} MB" +
"We are over our memory limit ({}) and trigger a shutdown. usedMemory: {} MB. freeMemory: {} MB" +
"\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n",
(int) maxMemory, usedMemory, Profiler.getFreeMemoryInMB());
restart(environment, gracefulShutDownHandler);
shutDown(gracefulShutDownHandler);
}
}, 5);
}
}, CHECK_MEMORY_PERIOD_SEC);
}

protected void shutDown(GracefulShutDownHandler gracefulShutDownHandler) {
stopped = true;
gracefulShutDownHandler.gracefulShutDown(() -> {
log.info("Shutdown complete");
System.exit(1);
});
}

protected void restart(BisqEnvironment bisqEnvironment, GracefulShutDownHandler gracefulShutDownHandler) {
stopped = true;
gracefulShutDownHandler.gracefulShutDown(() -> {
Expand All @@ -180,5 +206,4 @@ protected void restart(BisqEnvironment bisqEnvironment, GracefulShutDownHandler
}
});
}

}
6 changes: 2 additions & 4 deletions p2p/src/main/java/bisq/network/p2p/P2PService.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
import bisq.network.p2p.storage.payload.ProtectedStoragePayload;

import bisq.common.UserThread;
import bisq.common.app.Capabilities;
import bisq.common.app.Capability;
import bisq.common.crypto.CryptoException;
import bisq.common.crypto.KeyRing;
import bisq.common.crypto.PubKeyRing;
Expand Down Expand Up @@ -313,8 +311,8 @@ private void onNetworkReady() {
"seedNodeOfPreliminaryDataRequest must be present");

requestDataManager.requestUpdateData();
if (Capabilities.app.containsAll(Capability.SEED_NODE))
UserThread.runPeriodically(() -> requestDataManager.requestUpdateData(), 1, TimeUnit.HOURS);
/*if (Capabilities.app.containsAll(Capability.SEED_NODE))
UserThread.runPeriodically(() -> requestDataManager.requestUpdateData(), 1, TimeUnit.HOURS);*/

// If we start up first time we don't have any peers so we need to request from seed node.
// As well it can be that the persisted peer list is outdated with dead peers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@

import bisq.common.Timer;
import bisq.common.UserThread;
import bisq.common.app.Capabilities;
import bisq.common.app.Capability;
import bisq.common.proto.network.NetworkEnvelope;
import bisq.common.proto.network.NetworkPayload;

Expand All @@ -61,13 +59,15 @@
class RequestDataHandler implements MessageListener {
private static final long TIMEOUT = 90;
private NodeAddress peersNodeAddress;
/*
*/

/**
* when we are run as a seed node, we spawn a RequestDataHandler every hour. However, we do not want to receive
* {@link PersistableNetworkPayload}s (for now, as there are hardly any cases where such data goes out of sync). This
* flag indicates whether we already received our first set of {@link PersistableNetworkPayload}s.
*/
private static boolean firstRequest = true;
*//*
private static boolean firstRequest = true;*/

///////////////////////////////////////////////////////////////////////////////////////////
// Listener
Expand Down Expand Up @@ -227,11 +227,11 @@ public void onMessage(NetworkEnvelope networkEnvelope, Connection connection) {
});
log.info("Processing {} protectedStorageEntries took {} ms.", counter.get(), System.currentTimeMillis() - ts);

// engage the firstRequest logic only if we are a seed node. Normal clients get here twice at most.
/* // engage the firstRequest logic only if we are a seed node. Normal clients get here twice at most.
if (!Capabilities.app.containsAll(Capability.SEED_NODE))
firstRequest = true;
firstRequest = true;*/

if (persistableNetworkPayloadSet != null && firstRequest) {
if (persistableNetworkPayloadSet != null /*&& firstRequest*/) {
ts = System.currentTimeMillis();
persistableNetworkPayloadSet.forEach(e -> {
if (e instanceof LazyProcessedPayload) {
Expand All @@ -253,7 +253,7 @@ public void onMessage(NetworkEnvelope networkEnvelope, Connection connection) {

cleanup();
listener.onComplete();
firstRequest = false;
// firstRequest = false;
} else {
log.warn("Nonce not matching. That can happen rarely if we get a response after a canceled " +
"handshake (timeout causes connection close but peer might have sent a msg before " +
Expand Down
2 changes: 2 additions & 0 deletions seednode/src/main/java/bisq/seednode/SeedNodeMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public static void main(String[] args) throws Exception {
protected void doExecute(OptionSet options) {
super.doExecute(options);

checkMemory(bisqEnvironment, this);
startShutDownInterval(this);
CommonSetup.setup(this);

keepRunning();
Expand Down

0 comments on commit f0242bf

Please sign in to comment.