Skip to content

Commit

Permalink
fix read meta error
Browse files Browse the repository at this point in the history
  • Loading branch information
roseduan committed Aug 15, 2023
1 parent 380eb6c commit c19c6cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
5 changes: 2 additions & 3 deletions fs/os_file.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fs

import (
"io"
"os"
)

Expand All @@ -17,11 +16,11 @@ func openOSFile(name string) (File, error) {
}

// get the file size
size, err := fd.Seek(0, io.SeekEnd)
stat, err := fd.Stat()
if err != nil {
return nil, err
}
return &OSFile{fd: fd, size: size}, nil
return &OSFile{fd: fd, size: stat.Size()}, nil
}

func (of *OSFile) Read(p []byte) (n int, err error) {
Expand Down
20 changes: 10 additions & 10 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,18 @@ func checkOptions(options Options) error {
}

func (t *Table) readMeta() error {
file, err := fs.Open(filepath.Join(t.options.DirPath, metaFileName), fs.OSFileSystem)
if err != nil {
return err
}
t.metaFile = file
t.meta = &tableMeta{}

// init meta file if not exist
if t.metaFile == nil {
file, err := fs.Open(filepath.Join(t.options.DirPath, metaFileName), fs.OSFileSystem)
if err != nil {
return err
}
t.meta = &tableMeta{
NumBuckets: 1,
SlotValueLength: t.options.SlotValueLength,
}
if file.Size() == 0 {
t.meta.NumBuckets = 1
t.meta.SlotValueLength = t.options.SlotValueLength
t.meta.BucketSize = slotsPerBucket*(4+t.meta.SlotValueLength) + bucketNextOffsetLen
t.metaFile = file
} else {
decoder := json.NewDecoder(t.metaFile)
if err := decoder.Decode(t.meta); err != nil {
Expand Down

0 comments on commit c19c6cb

Please sign in to comment.