spacemeshos / post

Spacemesh POST protocol implementation
MIT License
19 stars 20 forks source link

LabelsReader & LabelsWriter are less performant and more complex than necessary #197

Open fasmat opened 1 year ago

fasmat commented 1 year ago

Reader

LabelsReader should implement the io.ReadSeekCloser interface and only ever open one file on the disk at a time. NewLabelsReader should receive the directory of containing the PoST data, do some basic checks of the existing files against the postmeta_data.json and then abstract the directory for the user of the object to treat it as if it was a single file.

Read and Seek should only ever open one file and if the file cannot be found or is smaller then expected return io.ErrUnexpectedEOF.

Writer

Similar to the Reader LabelsWriter should implement the io.WriteSeekCloser interface and transparently handle the writing of data to multiple files.

This would among others remove the need to handle individual files by the initializer.

Additional note

At the moment Diskstate does not stat files to get their file size but rather uses fs.DirEntry::Info() which reports an incorrect size if the PoST data directory contains soft-links to the files (e.g. on other disks). On linux this problem can be solved by instead stating the files with os.Stat to get their correct size. On other OSes this might work differently and needs to be tested.