Skip to content

Commit

Permalink
better error handling/logging for KerlDHT.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellblazer committed Jan 15, 2024
1 parent fdc83fc commit b827f0c
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
*/
package com.salesforce.apollo.stereotomy.identifier;

import java.util.Objects;

import com.salesforce.apollo.stereotomy.event.proto.Ident;
import com.salesforce.apollo.cryptography.Digest;
import com.salesforce.apollo.cryptography.DigestAlgorithm;
import com.salesforce.apollo.stereotomy.event.proto.Ident;

import java.util.Objects;

/**
* @author hal.hildebrand
Expand All @@ -20,6 +20,7 @@ public class SelfAddressingIdentifier implements Identifier, Comparable<SelfAddr
private final Digest digest;

public SelfAddressingIdentifier(Digest digest) {
assert digest != null : "Digest cannot be null";
this.digest = digest;
}

Expand All @@ -33,10 +34,9 @@ public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof SelfAddressingIdentifier)) {
if (!(obj instanceof SelfAddressingIdentifier other)) {
return false;
}
SelfAddressingIdentifier other = (SelfAddressingIdentifier) obj;
return Objects.equals(digest, other.digest);
}

Expand Down
77 changes: 75 additions & 2 deletions thoth/src/main/java/com/salesforce/apollo/thoth/KerlDHT.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ public KeyState_ append(AttachmentEvent event) {
Thread.currentThread().interrupt();
return null;
} catch (ExecutionException e) {
if (e.getCause() instanceof CompletionException ce) {
log.info("error appending Attachment: {} on: {}", ce.getMessage(), member.getId());
return KeyState_.getDefaultInstance();
}
throw new IllegalStateException(e.getCause());
}
}
Expand Down Expand Up @@ -255,6 +259,10 @@ public List<KeyState_> append(KERL_ kerl) {
Thread.currentThread().interrupt();
return null;
} catch (ExecutionException e) {
if (e.getCause() instanceof CompletionException ce) {
log.info("error appending KERL: {} on: {}", ce.getMessage(), member.getId());
return Collections.emptyList();
}
throw new IllegalStateException(e.getCause());
}
}
Expand Down Expand Up @@ -287,6 +295,10 @@ public KeyState_ append(KeyEvent_ event) {
Thread.currentThread().interrupt();
return null;
} catch (ExecutionException e) {
if (e.getCause() instanceof CompletionException ce) {
log.info("error appending Key Event: {} on: {}", ce.getMessage(), member.getId());
return KeyState_.getDefaultInstance();
}
throw new IllegalStateException(e.getCause());
}
}
Expand Down Expand Up @@ -338,7 +350,19 @@ public Empty appendAttachments(List<AttachmentEvent> events) {
"append attachments"),
t -> completeIt(result,
gathered));
return Empty.getDefaultInstance();

try {
return result.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return null;
} catch (ExecutionException e) {
if (e.getCause() instanceof CompletionException ce) {
log.info("error appending attachments: {} on: {}", ce.getMessage(), member.getId());
return Empty.getDefaultInstance();
}
throw new IllegalStateException(e.getCause());
}
}

@Override
Expand Down Expand Up @@ -371,6 +395,10 @@ public Empty appendValidations(Validations validations) {
Thread.currentThread().interrupt();
return null;
} catch (ExecutionException e) {
if (e.getCause() instanceof CompletionException ce) {
log.info("error appending validations: {} on: {}", ce.getMessage(), member.getId());
return Empty.getDefaultInstance();
}
throw new IllegalStateException(e.getCause());
}
}
Expand Down Expand Up @@ -429,6 +457,11 @@ public Attachment getAttachment(EventCoords coordinates) {
Thread.currentThread().interrupt();
return null;
} catch (ExecutionException e) {
if (e.getCause() instanceof CompletionException ce) {
log.info("error get Attachment: {} : {} on: {}", EventCoordinates.from(coordinates), ce.getMessage(),
member.getId());
return null;
}
throw new IllegalStateException(e.getCause());
}
}
Expand Down Expand Up @@ -468,6 +501,11 @@ public KERL_ getKERL(Ident identifier) {
Thread.currentThread().interrupt();
return null;
} catch (ExecutionException e) {
if (e.getCause() instanceof CompletionException ce) {
log.info("error get Kerl: {} : {} on: {}", Identifier.from(identifier), ce.getMessage(),
member.getId());
return KERL_.getDefaultInstance();
}
throw new IllegalStateException(e.getCause());
}
}
Expand Down Expand Up @@ -508,6 +546,11 @@ public KeyEvent_ getKeyEvent(EventCoords coordinates) {
Thread.currentThread().interrupt();
return null;
} catch (ExecutionException e) {
if (e.getCause() instanceof CompletionException ce) {
log.info("error get KeyEvent: {} : {} on: {}", EventCoordinates.from(coordinates), ce.getMessage(),
member.getId());
return KeyEvent_.getDefaultInstance();
}
throw new IllegalStateException(e.getCause());
}
}
Expand Down Expand Up @@ -548,6 +591,11 @@ public KeyState_ getKeyState(EventCoords coordinates) {
Thread.currentThread().interrupt();
return null;
} catch (ExecutionException e) {
if (e.getCause() instanceof CompletionException ce) {
log.info("error get KeyState: {} : {} on: {}", EventCoordinates.from(coordinates), ce.getMessage(),
member.getId());
return KeyState_.getDefaultInstance();
}
throw new IllegalStateException(e.getCause());
}
}
Expand Down Expand Up @@ -592,6 +640,11 @@ public KeyState_ getKeyState(Ident identifier, long sequenceNumber) {
Thread.currentThread().interrupt();
return null;
} catch (ExecutionException e) {
if (e.getCause() instanceof CompletionException ce) {
log.info("error get KeyState: {}:#{} : {} on: {}", Identifier.from(identifier),
ULong.valueOf(sequenceNumber), ce.getMessage(), member.getId());
return KeyState_.getDefaultInstance();
}
throw new IllegalStateException(e.getCause());
}
}
Expand Down Expand Up @@ -631,13 +684,18 @@ public KeyState_ getKeyState(Ident identifier) {
Thread.currentThread().interrupt();
return null;
} catch (ExecutionException e) {
if (e.getCause() instanceof CompletionException ce) {
log.info("error get KeyState: {} : {} on: {}", Identifier.from(identifier), ce.getMessage(),
member.getId());
return KeyState_.getDefaultInstance();
}
throw new IllegalStateException(e.getCause());
}
}

@Override
public KeyStateWithAttachments_ getKeyStateWithAttachments(EventCoords coordinates) {
log.info("Get key state with attachements: {} on: {}", EventCoordinates.from(coordinates), member.getId());
log.info("Get key state with attachments: {} on: {}", EventCoordinates.from(coordinates), member.getId());
if (coordinates == null) {
return completeIt(KeyStateWithAttachments_.getDefaultInstance());
}
Expand Down Expand Up @@ -670,6 +728,11 @@ public KeyStateWithAttachments_ getKeyStateWithAttachments(EventCoords coordinat
Thread.currentThread().interrupt();
return null;
} catch (ExecutionException e) {
if (e.getCause() instanceof CompletionException ce) {
log.info("error get KeyState With Attachments: {} on: {}", EventCoordinates.from(coordinates),
member.getId(), ce);
return null;
}
throw new IllegalStateException(e.getCause());
}
}
Expand Down Expand Up @@ -710,6 +773,11 @@ public KeyStateWithEndorsementsAndValidations_ getKeyStateWithEndorsementsAndVal
Thread.currentThread().interrupt();
return null;
} catch (ExecutionException e) {
if (e.getCause() instanceof CompletionException ce) {
log.info("error get KeyState With endorsement and validations: {} : {} on: {}",
EventCoordinates.from(coordinates), ce.getMessage(), member.getId());
return null;
}
throw new IllegalStateException(e.getCause());
}
}
Expand Down Expand Up @@ -749,6 +817,11 @@ public Validations getValidations(EventCoords coordinates) {
Thread.currentThread().interrupt();
return null;
} catch (ExecutionException e) {
if (e.getCause() instanceof CompletionException ce) {
log.info("error get validations: {} : {} on: {}", EventCoordinates.from(coordinates), ce.getMessage(),
member.getId());
return null;
}
throw new IllegalStateException(e.getCause());
}
}
Expand Down

0 comments on commit b827f0c

Please sign in to comment.