a little cleanup with handleConnectionSuccess

let's not spam it right now
This commit is contained in:
2024-06-23 20:40:49 +02:00
parent 45a1bb299c
commit a9a264cea4
2 changed files with 14 additions and 16 deletions

View File

@@ -44,16 +44,21 @@ public class RemoteHostManager {
@Blocking
public void tryConnectAll() {
for (var host : persistentRemoteHostsService.getHosts()) {
var shouldTry = _transientPeersState.runReadLocked(d -> {
var s = d.getStates().get(host.getUuid());
if (s == null) return true;
return !s.getState().equals(TransientPeerState.ConnectionState.REACHABLE);
});
if (shouldTry) {
Log.info("Trying to connect to " + host.getUuid());
if (pingCheck(host.getUuid())) {
handleConnectionSuccess(host.getUuid());
try {
var shouldTry = _transientPeersState.runReadLocked(d -> {
var s = d.getStates().get(host.getUuid());
if (s == null) return true;
return !s.getState().equals(TransientPeerState.ConnectionState.REACHABLE) && s.getAddr() != null;
});
if (shouldTry) {
Log.info("Trying to connect to " + host.getUuid());
if (pingCheck(host.getUuid())) {
handleConnectionSuccess(host.getUuid());
}
}
} catch (Exception e) {
Log.error("Failed to connect to " + host.getUuid(), e);
continue;
}
}
}

View File

@@ -13,8 +13,6 @@ import io.smallrye.mutiny.Uni;
import jakarta.inject.Inject;
import org.apache.commons.lang3.tuple.Pair;
import java.util.UUID;
// Note: RunOnVirtualThread hangs somehow
@GrpcService
public class RemoteObjectServiceServer implements DhfsObjectSyncGrpc {
@@ -35,8 +33,6 @@ public class RemoteObjectServiceServer implements DhfsObjectSyncGrpc {
public Uni<GetObjectReply> getObject(GetObjectRequest request) {
if (request.getSelfUuid().isBlank()) throw new StatusRuntimeException(Status.INVALID_ARGUMENT);
remoteHostManager.handleConnectionSuccess(UUID.fromString(request.getSelfUuid()));
Log.info("<-- getObject: " + request.getName() + " from " + request.getSelfUuid());
var obj = jObjectManager.get(request.getName()).orElseThrow(() -> new StatusRuntimeException(Status.NOT_FOUND));
@@ -58,7 +54,6 @@ public class RemoteObjectServiceServer implements DhfsObjectSyncGrpc {
@Blocking
public Uni<IndexUpdatePush> getIndex(GetIndexRequest request) {
if (request.getSelfUuid().isBlank()) throw new StatusRuntimeException(Status.INVALID_ARGUMENT);
remoteHostManager.handleConnectionSuccess(UUID.fromString(request.getSelfUuid()));
Log.info("<-- getIndex: from " + request.getSelfUuid());
var builder = IndexUpdatePush.newBuilder().setSelfUuid(persistentRemoteHostsService.getSelfUuid().toString());
@@ -78,7 +73,6 @@ public class RemoteObjectServiceServer implements DhfsObjectSyncGrpc {
@Blocking
public Uni<IndexUpdateReply> indexUpdate(IndexUpdatePush request) {
if (request.getSelfUuid().isBlank()) throw new StatusRuntimeException(Status.INVALID_ARGUMENT);
remoteHostManager.handleConnectionSuccess(UUID.fromString(request.getSelfUuid()));
// Log.info("<-- indexUpdate: " + request.getHeader().getName());
return Uni.createFrom().item(syncHandler.handleRemoteUpdate(request));
@@ -88,7 +82,6 @@ public class RemoteObjectServiceServer implements DhfsObjectSyncGrpc {
@Blocking
public Uni<PingReply> ping(PingRequest request) {
if (request.getSelfUuid().isBlank()) throw new StatusRuntimeException(Status.INVALID_ARGUMENT);
remoteHostManager.handleConnectionSuccess(UUID.fromString(request.getSelfUuid()));
return Uni.createFrom().item(PingReply.newBuilder().setSelfUuid(persistentRemoteHostsService.getSelfUuid().toString()).build());
}