no tolerance for failed snapshots v2

This commit is contained in:
2024-07-06 23:53:44 +02:00
parent fc7369419a
commit a1cc36796f
3 changed files with 22 additions and 14 deletions

View File

@@ -4,11 +4,8 @@ import com.usatiuk.dhfs.objects.repository.distributed.ObjectChangelog;
import com.usatiuk.dhfs.objects.repository.distributed.ObjectChangelogEntry;
import com.usatiuk.dhfs.objects.repository.distributed.ObjectHeader;
import com.usatiuk.dhfs.storage.SerializationHelper;
import com.usatiuk.dhfs.storage.objects.repository.distributed.PersistentRemoteHostsService;
import com.usatiuk.dhfs.storage.objects.repository.distributed.peersync.PersistentPeerInfo;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import jakarta.enterprise.inject.spi.CDI;
import lombok.Getter;
import lombok.Setter;
@@ -153,17 +150,11 @@ public class ObjectMetadata implements Serializable {
public ObjectChangelog toRpcChangelog() {
var changelogBuilder = ObjectChangelog.newBuilder();
var hosts = CDI.current().select(PersistentRemoteHostsService.class).get();
var all = new ArrayList<>(hosts.getHosts().stream().map(PersistentPeerInfo::getUuid).toList());
all.add(hosts.getSelfUuid());
for (var h : all) {
for (var h : _changelog.entrySet()) {
var logEntry = ObjectChangelogEntry.newBuilder();
if (!_changelog.containsKey(h))
continue;
logEntry.setHost(h.toString());
logEntry.setVersion(_changelog.get(h));
logEntry.setHost(h.getKey().toString());
logEntry.setVersion(h.getValue());
changelogBuilder.addEntries(logEntry.build());
}
return changelogBuilder.build();

View File

@@ -122,6 +122,19 @@ public class PersistentRemoteHostsService {
return (JObject<PersistentPeerInfo>) got;
}
private List<PersistentPeerInfo> getPeersSnapshot() {
return getPeerDirectory().runReadLocked(JObject.ResolutionStrategy.LOCAL_ONLY, (m, d) -> {
return d.getPeers().stream().map(u -> {
try {
return getPeer(u).runReadLocked(JObject.ResolutionStrategy.LOCAL_ONLY, (m2, d2) -> d2);
} catch (Exception e) {
Log.warn("Error making snapshot of peer " + u, e);
return null;
}
}).filter(Objects::nonNull).toList();
});
}
public UUID getSelfUuid() {
if (_selfUuid == null)
throw new IllegalStateException();
@@ -139,6 +152,10 @@ public class PersistentRemoteHostsService {
}
public List<PersistentPeerInfo> getHosts() {
return getPeersSnapshot().stream().filter(i -> !i.getUuid().equals(_selfUuid)).toList();
}
public List<PersistentPeerInfo> getHostsNoNulls() {
for (int i = 0; i < 5; i++) {
try {
return getPeerDirectory()
@@ -175,7 +192,7 @@ public class PersistentRemoteHostsService {
private void updateCerts() {
getPeerDirectory().runReadLocked(JObject.ResolutionStrategy.LOCAL_ONLY, (m, d) -> {
peerTrustManager.reloadTrustManagerHosts(getHosts());
peerTrustManager.reloadTrustManagerHosts(getHostsNoNulls());
return null;
});
}

View File

@@ -22,7 +22,7 @@ public class ManagementApi {
@Path("known-peers")
@GET
public List<KnownPeerInfo> knownPeers() {
return persistentRemoteHostsService.getHosts().stream().map(h -> new KnownPeerInfo(h.getUuid().toString())).toList();
return persistentRemoteHostsService.getHostsNoNulls().stream().map(h -> new KnownPeerInfo(h.getUuid().toString())).toList();
}
@Path("known-peers")