Skip to content

Commit 141921d

Browse files
sanding
Signed-off-by: Matt Peterson <matt.peterson@swirldslabs.com>
1 parent 2529488 commit 141921d

File tree

8 files changed

+27
-22
lines changed

8 files changed

+27
-22
lines changed

server/src/main/java/com/hedera/block/server/data/ObjectEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
public class ObjectEvent<T> {
2020
T val;
2121

22-
public void set(T val) {
22+
public void set(final T val) {
2323
this.val = val;
2424
}
2525

server/src/main/java/com/hedera/block/server/mediator/LiveStreamMediatorImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void publishEvent(final BlockItem blockItem) throws IOException {
121121
LOGGER.log(System.Logger.Level.INFO, "Send a response to end the stream");
122122

123123
// Publish the block for all subscribers to receive
124-
final var endStreamResponse = buildEndStreamResponse();
124+
final SubscribeStreamResponse endStreamResponse = buildEndStreamResponse();
125125
ringBuffer.publishEvent((event, sequence) -> event.set(endStreamResponse));
126126

127127
// Unsubscribe all downstream consumers

server/src/main/java/com/hedera/block/server/persistence/storage/BlockAsDirReader.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private Optional<BlockItem> readBlockItem(final String blockItemPath) throws IOE
127127
return Optional.empty();
128128
}
129129

130-
// FileNotFound is thrown also when a file cannot be read.
130+
// FileNotFound is also thrown when a file cannot be read.
131131
// So re-throw here to make a different decision upstream.
132132
throw io;
133133
}
@@ -171,7 +171,8 @@ private boolean isVerified(final Path path) {
171171
return true;
172172
}
173173

174-
protected void setPerm(Path path, Set<PosixFilePermission> perms) throws IOException {
174+
protected void setPerm(final Path path, final Set<PosixFilePermission> perms)
175+
throws IOException {
175176
Files.setPosixFilePermissions(path, perms);
176177
}
177178
}

server/src/main/java/com/hedera/block/server/persistence/storage/BlockAsDirRemover.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public BlockAsDirRemover(
3838
}
3939

4040
@Override
41-
public void remove(long id) throws IOException {
41+
public void remove(final long id) throws IOException {
4242

4343
// Calculate the block path and proactively set the permissions
4444
// for removal
4545
final Path blockPath = blockNodeRootPath.resolve(String.valueOf(id));
46-
if (!Files.exists(blockPath)) {
46+
if (Files.notExists(blockPath)) {
4747
LOGGER.log(System.Logger.Level.ERROR, "Block does not exist: " + id);
4848
return;
4949
}
@@ -56,14 +56,14 @@ public void remove(long id) throws IOException {
5656
}
5757
}
5858

59-
private static boolean delete(File file) {
59+
private static boolean delete(final File file) {
6060

6161
// Recursively delete the contents
6262
// of the directory
6363
if (file.isDirectory()) {
64-
File[] files = file.listFiles();
64+
final File[] files = file.listFiles();
6565
if (files != null) {
66-
for (File f : files) {
66+
for (final File f : files) {
6767
delete(f);
6868
}
6969
}

server/src/main/java/com/hedera/block/server/persistence/storage/BlockAsDirWriter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public void write(final BlockItem blockItem) throws IOException {
9292
System.Logger.Level.ERROR,
9393
"Error writing the BlockItem protobuf to a file",
9494
e);
95+
96+
// Remove the block if repairing the permissions fails
9597
if (retries > 0) {
9698
// Attempt to remove the block
9799
blockRemover.remove(Long.parseLong(currentBlockDir.toString()));
@@ -111,7 +113,7 @@ public void write(final BlockItem blockItem) throws IOException {
111113

112114
protected void write(final Path blockItemFilePath, final BlockItem blockItem)
113115
throws IOException {
114-
try (FileOutputStream fos = new FileOutputStream(blockItemFilePath.toString())) {
116+
try (final FileOutputStream fos = new FileOutputStream(blockItemFilePath.toString())) {
115117
blockItem.writeTo(fos);
116118
LOGGER.log(
117119
System.Logger.Level.INFO,
@@ -172,7 +174,8 @@ private Path calculateBlockPath() {
172174
return blockNodeRootPath.resolve(currentBlockDir);
173175
}
174176

175-
private void createPath(Path blockNodePath, System.Logger.Level logLevel) throws IOException {
177+
private void createPath(final Path blockNodePath, final System.Logger.Level logLevel)
178+
throws IOException {
176179
// Initialize the Block directory if it does not exist
177180
if (Files.notExists(blockNodePath)) {
178181
Files.createDirectory(blockNodePath, filePerms);

server/src/main/java/com/hedera/block/server/persistence/storage/BlockRemover.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
import java.io.IOException;
2020

2121
public interface BlockRemover {
22-
void remove(long id) throws IOException;
22+
void remove(final long id) throws IOException;
2323
}

server/src/main/java/com/hedera/block/server/producer/Util.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,18 @@ private Util() {}
2929

3030
public static byte[] getFakeHash(BlockItem blockItem)
3131
throws IOException, NoSuchAlgorithmException {
32-
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
33-
try (ObjectOutputStream objectOutputStream =
34-
new ObjectOutputStream(byteArrayOutputStream)) {
32+
33+
try (final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
34+
final ObjectOutputStream objectOutputStream =
35+
new ObjectOutputStream(byteArrayOutputStream)) {
3536
objectOutputStream.writeObject(blockItem);
36-
}
3737

38-
// Get the serialized bytes
39-
byte[] serializedObject = byteArrayOutputStream.toByteArray();
38+
// Get the serialized bytes
39+
byte[] serializedObject = byteArrayOutputStream.toByteArray();
4040

41-
// Calculate the SHA-256 hash
42-
MessageDigest digest = MessageDigest.getInstance("SHA-384");
43-
return digest.digest(serializedObject);
41+
// Calculate the SHA-256 hash
42+
MessageDigest digest = MessageDigest.getInstance("SHA-384");
43+
return digest.digest(serializedObject);
44+
}
4445
}
4546
}

server/src/test/resources/producer.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ trap cleanup SIGINT
5757
echo "{\"block_item\": {\"start_event\": {\"creator_id\": $i},\"value\": \"Payload[...]\"}}"
5858
fi
5959

60-
sleep 0.5
60+
sleep 0.01
6161
done
6262

6363
if [ $iter -eq $2 ]; then

0 commit comments

Comments
 (0)