1
0
mirror of https://github.com/taigrr/bitcask synced 2025-01-18 04:03:17 -08:00

Refactor Datafile.Size()

This commit is contained in:
James Mills 2019-03-22 17:33:24 +10:00
parent 2400dd86d5
commit c593bc966f
No known key found for this signature in database
GPG Key ID: AC4C014F1440EBD6
2 changed files with 3 additions and 7 deletions

View File

@ -175,11 +175,7 @@ func (b *Bitcask) Fold(f func(key string) error) error {
} }
func (b *Bitcask) put(key string, value []byte) (int64, error) { func (b *Bitcask) put(key string, value []byte) (int64, error) {
size, err := b.curr.Size() size := b.curr.Size()
if err != nil {
return -1, err
}
if size >= int64(b.config.maxDatafileSize) { if size >= int64(b.config.maxDatafileSize) {
err := b.curr.Close() err := b.curr.Close()
if err != nil { if err != nil {

View File

@ -98,10 +98,10 @@ func (df *Datafile) Sync() error {
return df.w.Sync() return df.w.Sync()
} }
func (df *Datafile) Size() (int64, error) { func (df *Datafile) Size() int64 {
df.RLock() df.RLock()
defer df.RUnlock() defer df.RUnlock()
return df.offset, nil return df.offset
} }
func (df *Datafile) Read() (e pb.Entry, err error) { func (df *Datafile) Read() (e pb.Entry, err error) {