Skip to content

Commit c6fc296

Browse files
authored
Merge pull request #8 from 0xsequence/fileIndex
FileIndex + New File Structure + File Prefetch + Parallel Write
2 parents 3e32528 + 9a3d766 commit c6fc296

File tree

16 files changed

+1201
-252
lines changed

16 files changed

+1201
-252
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.tmp
22

3-
ethwalcat
3+
ethwalcat
4+
ethwalinfo

cmd/ethwalcat/ethwalcat.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -148,29 +148,29 @@ func main() {
148148
FileRollOnCloseFlag,
149149
GoogleCloudBucket,
150150
},
151-
Action: func(context *cli.Context) error {
152-
switch context.String(ModeFlag.Name) {
151+
Action: func(c *cli.Context) error {
152+
switch c.String(ModeFlag.Name) {
153153
case "read":
154-
dec, err := decoder(context)
154+
dec, err := decoder(c)
155155
if err != nil {
156156
return err
157157
}
158158

159-
decomp, err := decompressor(context)
159+
decomp, err := decompressor(c)
160160
if err != nil {
161161
return err
162162
}
163163

164164
var fs storage.FS
165-
if bucket := context.String(GoogleCloudBucket.Name); bucket != "" {
165+
if bucket := c.String(GoogleCloudBucket.Name); bucket != "" {
166166
fs = gcloud.NewGCloudFS(bucket, nil)
167167
}
168168

169169
r, err := ethwal.NewReader[any](ethwal.Options{
170170
Dataset: ethwal.Dataset{
171-
Name: context.String(DatasetNameFlag.Name),
172-
Version: context.String(DatasetVersion.Name),
173-
Path: context.String(DatasetPathFlag.Name),
171+
Name: c.String(DatasetNameFlag.Name),
172+
Version: c.String(DatasetVersion.Name),
173+
Path: c.String(DatasetPathFlag.Name),
174174
},
175175
FileSystem: fs,
176176
NewDecoder: dec,
@@ -180,22 +180,22 @@ func main() {
180180
return err
181181
}
182182

183-
if context.Uint64(FromBlockNumFlag.Name) > 0 {
184-
err = r.Seek(context.Uint64(FromBlockNumFlag.Name))
183+
if c.Uint64(FromBlockNumFlag.Name) > 0 {
184+
err = r.Seek(c.Context, c.Uint64(FromBlockNumFlag.Name))
185185
if err != nil {
186186
return err
187187
}
188188
}
189189

190-
var toBlockNumber = context.Uint64(ToBlockNumFlag.Name)
190+
var toBlockNumber = c.Uint64(ToBlockNumFlag.Name)
191191

192-
for b, err := r.Read(); err == nil; b, err = r.Read() {
192+
for b, err := r.Read(c.Context); err == nil; b, err = r.Read(c.Context) {
193193
if toBlockNumber != 0 && b.Number >= toBlockNumber {
194194
break
195195
}
196196

197197
// cbor deserializes into map[interface{}]interface{} which can not be serialized into json
198-
if context.String(DecoderFlag.Name) == "cbor" {
198+
if c.String(DecoderFlag.Name) == "cbor" {
199199
b.Data = normalizeDataFromCBOR(b.Data)
200200
}
201201

@@ -220,32 +220,32 @@ func main() {
220220
return err
221221
}
222222
case "write":
223-
enc, err := encoder(context)
223+
enc, err := encoder(c)
224224
if err != nil {
225225
return err
226226
}
227227

228-
compres, err := compressor(context)
228+
compres, err := compressor(c)
229229
if err != nil {
230230
return err
231231
}
232232

233233
var fs storage.FS
234-
if bucket := context.String(GoogleCloudBucket.Name); bucket != "" {
234+
if bucket := c.String(GoogleCloudBucket.Name); bucket != "" {
235235
fs = gcloud.NewGCloudFS(bucket, nil)
236236
}
237237

238238
w, err := ethwal.NewWriter[any](ethwal.Options{
239239
Dataset: ethwal.Dataset{
240-
Name: context.String(DatasetNameFlag.Name),
241-
Version: context.String(DatasetVersion.Name),
242-
Path: context.String(DatasetPathFlag.Name),
240+
Name: c.String(DatasetNameFlag.Name),
241+
Version: c.String(DatasetVersion.Name),
242+
Path: c.String(DatasetPathFlag.Name),
243243
},
244244
FileSystem: fs,
245245
NewEncoder: enc,
246246
NewCompressor: compres,
247247
FileRollPolicy: ethwal.NewFileSizeRollPolicy(uint64(8 << 20)), // 8 MB
248-
FileRollOnClose: context.Bool(FileRollOnCloseFlag.Name),
248+
FileRollOnClose: c.Bool(FileRollOnCloseFlag.Name),
249249
})
250250
if err != nil {
251251
return err
@@ -260,11 +260,11 @@ func main() {
260260
}
261261

262262
// cbor needs to have hashes represented as byte slices
263-
if context.String(EncoderFlag.Name) == "cbor" {
263+
if c.String(EncoderFlag.Name) == "cbor" {
264264
b.Data = normalizeDataToCBOR(b.Data)
265265
}
266266

267-
err = w.Write(b)
267+
err = w.Write(c.Context, b)
268268
if err != nil {
269269
return err
270270
}
@@ -274,12 +274,12 @@ func main() {
274274
return err
275275
}
276276

277-
err = w.Close()
277+
err = w.Close(c.Context)
278278
if err != nil {
279279
return err
280280
}
281281
default:
282-
return fmt.Errorf("unknown mode: %s", context.String(ModeFlag.Name))
282+
return fmt.Errorf("unknown mode: %s", c.String(ModeFlag.Name))
283283
}
284284

285285
return nil

cmd/ethwalinfo/ethwalinfo.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func main() {
6060
// mount fs to dataset path
6161
fs = storage.NewPrefixWrapper(fs, dataset.FullPath())
6262

63-
walFiles, err := ethwal.ListWALFiles(fs)
63+
walFiles, err := ethwal.ListFiles(c.Context, fs)
6464
if err != nil {
6565
return err
6666
}
@@ -75,7 +75,11 @@ func main() {
7575
}
7676
fmt.Println("Path:", dataset.Path)
7777
fmt.Println("Number of files:", len(walFiles))
78-
fmt.Println("Block range:", walFiles[0].FirstBlockNum, "-", walFiles[len(walFiles)-1].LastBlockNum)
78+
if len(walFiles) > 0 {
79+
fmt.Println("Block range:", walFiles[0].FirstBlockNum, "-", walFiles[len(walFiles)-1].LastBlockNum)
80+
} else {
81+
fmt.Println("Block range: -")
82+
}
7983

8084
return nil
8185
},

0 commit comments

Comments
 (0)