26
26
import java .nio .file .Files ;
27
27
import java .nio .file .Path ;
28
28
29
- public class FileSystemBlockWriter implements BlockWriter <BlockItem > {
29
+ public class BlockAsDirWriter implements BlockWriter <BlockItem > {
30
30
31
31
private final System .Logger LOGGER = System .getLogger (getClass ().getName ());
32
32
33
33
private final Path blockNodeRootPath ;
34
34
private long blockNodeFileNameIndex = 0 ;
35
35
private Path currentBlockDir ;
36
36
37
- public FileSystemBlockWriter (final String key , final Config config ) throws IOException {
37
+ public BlockAsDirWriter (final String key , final Config config ) throws IOException {
38
38
39
39
LOGGER .log (System .Logger .Level .INFO , "Initializing FileSystemBlockStorage" );
40
40
@@ -49,16 +49,7 @@ public FileSystemBlockWriter(final String key, final Config config) throws IOExc
49
49
}
50
50
51
51
// Initialize the block node root directory if it does not exist
52
- if (Files .notExists (blockNodeRootPath )) {
53
- Files .createDirectory (blockNodeRootPath );
54
- LOGGER .log (
55
- System .Logger .Level .INFO ,
56
- "Created block node root directory: " + blockNodeRootPath );
57
- } else {
58
- LOGGER .log (
59
- System .Logger .Level .INFO ,
60
- "Using existing block node root directory: " + blockNodeRootPath );
61
- }
52
+ createPath (blockNodeRootPath , System .Logger .Level .INFO );
62
53
63
54
this .blockNodeRootPath = blockNodeRootPath ;
64
55
}
@@ -77,7 +68,8 @@ public void write(final BlockItem blockItem) throws IOException {
77
68
"Successfully wrote the block item file: {0}" ,
78
69
blockItemFilePath );
79
70
} catch (IOException e ) {
80
- LOGGER .log (System .Logger .Level .ERROR , "Error writing the protobuf to a file" , e );
71
+ LOGGER .log (
72
+ System .Logger .Level .ERROR , "Error writing the BlockItem protobuf to a file" , e );
81
73
}
82
74
}
83
75
@@ -87,7 +79,7 @@ private void resetState(final BlockItem blockItem) throws IOException {
87
79
currentBlockDir = Path .of (String .valueOf (blockItem .getHeader ().getBlockNumber ()));
88
80
89
81
// Construct the path to the block directory
90
- createPath (blockNodeRootPath .resolve (currentBlockDir ));
82
+ createPath (blockNodeRootPath .resolve (currentBlockDir ), System . Logger . Level . DEBUG );
91
83
92
84
// Reset
93
85
blockNodeFileNameIndex = 0 ;
@@ -100,17 +92,13 @@ private String calculateBlockItemPath() {
100
92
return blockPath .resolve (blockNodeFileNameIndex + BLOCK_FILE_EXTENSION ).toString ();
101
93
}
102
94
103
- private void createPath (Path blockNodePath ) throws IOException {
95
+ private void createPath (Path blockNodePath , System . Logger . Level logLevel ) throws IOException {
104
96
// Initialize the Block directory if it does not exist
105
97
if (Files .notExists (blockNodePath )) {
106
98
Files .createDirectory (blockNodePath );
107
- LOGGER .log (
108
- System .Logger .Level .INFO ,
109
- "Created block node root directory: " + blockNodePath );
99
+ LOGGER .log (logLevel , "Created block node root directory: " + blockNodePath );
110
100
} else {
111
- LOGGER .log (
112
- System .Logger .Level .INFO ,
113
- "Using existing block node root directory: " + blockNodePath );
101
+ LOGGER .log (logLevel , "Using existing block node root directory: " + blockNodePath );
114
102
}
115
103
}
116
104
}
0 commit comments