File tree Expand file tree Collapse file tree 8 files changed +27
-22
lines changed
main/java/com/hedera/block/server Expand file tree Collapse file tree 8 files changed +27
-22
lines changed Original file line number Diff line number Diff line change 19
19
public class ObjectEvent <T > {
20
20
T val ;
21
21
22
- public void set (T val ) {
22
+ public void set (final T val ) {
23
23
this .val = val ;
24
24
}
25
25
Original file line number Diff line number Diff line change @@ -121,7 +121,7 @@ public void publishEvent(final BlockItem blockItem) throws IOException {
121
121
LOGGER .log (System .Logger .Level .INFO , "Send a response to end the stream" );
122
122
123
123
// Publish the block for all subscribers to receive
124
- final var endStreamResponse = buildEndStreamResponse ();
124
+ final SubscribeStreamResponse endStreamResponse = buildEndStreamResponse ();
125
125
ringBuffer .publishEvent ((event , sequence ) -> event .set (endStreamResponse ));
126
126
127
127
// Unsubscribe all downstream consumers
Original file line number Diff line number Diff line change @@ -127,7 +127,7 @@ private Optional<BlockItem> readBlockItem(final String blockItemPath) throws IOE
127
127
return Optional .empty ();
128
128
}
129
129
130
- // FileNotFound is thrown also when a file cannot be read.
130
+ // FileNotFound is also thrown when a file cannot be read.
131
131
// So re-throw here to make a different decision upstream.
132
132
throw io ;
133
133
}
@@ -171,7 +171,8 @@ private boolean isVerified(final Path path) {
171
171
return true ;
172
172
}
173
173
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 {
175
176
Files .setPosixFilePermissions (path , perms );
176
177
}
177
178
}
Original file line number Diff line number Diff line change @@ -38,12 +38,12 @@ public BlockAsDirRemover(
38
38
}
39
39
40
40
@ Override
41
- public void remove (long id ) throws IOException {
41
+ public void remove (final long id ) throws IOException {
42
42
43
43
// Calculate the block path and proactively set the permissions
44
44
// for removal
45
45
final Path blockPath = blockNodeRootPath .resolve (String .valueOf (id ));
46
- if (! Files .exists (blockPath )) {
46
+ if (Files .notExists (blockPath )) {
47
47
LOGGER .log (System .Logger .Level .ERROR , "Block does not exist: " + id );
48
48
return ;
49
49
}
@@ -56,14 +56,14 @@ public void remove(long id) throws IOException {
56
56
}
57
57
}
58
58
59
- private static boolean delete (File file ) {
59
+ private static boolean delete (final File file ) {
60
60
61
61
// Recursively delete the contents
62
62
// of the directory
63
63
if (file .isDirectory ()) {
64
- File [] files = file .listFiles ();
64
+ final File [] files = file .listFiles ();
65
65
if (files != null ) {
66
- for (File f : files ) {
66
+ for (final File f : files ) {
67
67
delete (f );
68
68
}
69
69
}
Original file line number Diff line number Diff line change @@ -92,6 +92,8 @@ public void write(final BlockItem blockItem) throws IOException {
92
92
System .Logger .Level .ERROR ,
93
93
"Error writing the BlockItem protobuf to a file" ,
94
94
e );
95
+
96
+ // Remove the block if repairing the permissions fails
95
97
if (retries > 0 ) {
96
98
// Attempt to remove the block
97
99
blockRemover .remove (Long .parseLong (currentBlockDir .toString ()));
@@ -111,7 +113,7 @@ public void write(final BlockItem blockItem) throws IOException {
111
113
112
114
protected void write (final Path blockItemFilePath , final BlockItem blockItem )
113
115
throws IOException {
114
- try (FileOutputStream fos = new FileOutputStream (blockItemFilePath .toString ())) {
116
+ try (final FileOutputStream fos = new FileOutputStream (blockItemFilePath .toString ())) {
115
117
blockItem .writeTo (fos );
116
118
LOGGER .log (
117
119
System .Logger .Level .INFO ,
@@ -172,7 +174,8 @@ private Path calculateBlockPath() {
172
174
return blockNodeRootPath .resolve (currentBlockDir );
173
175
}
174
176
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 {
176
179
// Initialize the Block directory if it does not exist
177
180
if (Files .notExists (blockNodePath )) {
178
181
Files .createDirectory (blockNodePath , filePerms );
Original file line number Diff line number Diff line change 19
19
import java .io .IOException ;
20
20
21
21
public interface BlockRemover {
22
- void remove (long id ) throws IOException ;
22
+ void remove (final long id ) throws IOException ;
23
23
}
Original file line number Diff line number Diff line change @@ -29,17 +29,18 @@ private Util() {}
29
29
30
30
public static byte [] getFakeHash (BlockItem blockItem )
31
31
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 )) {
35
36
objectOutputStream .writeObject (blockItem );
36
- }
37
37
38
- // Get the serialized bytes
39
- byte [] serializedObject = byteArrayOutputStream .toByteArray ();
38
+ // Get the serialized bytes
39
+ byte [] serializedObject = byteArrayOutputStream .toByteArray ();
40
40
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
+ }
44
45
}
45
46
}
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ trap cleanup SIGINT
57
57
echo " {\" block_item\" : {\" start_event\" : {\" creator_id\" : $i },\" value\" : \" Payload[...]\" }}"
58
58
fi
59
59
60
- sleep 0.5
60
+ sleep 0.01
61
61
done
62
62
63
63
if [ $iter -eq $2 ]; then
You can’t perform that action at this time.
0 commit comments