From e092458546723d96237c3a8a934a56b1769e3c18 Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Fri, 26 May 2023 18:21:36 +0800 Subject: [PATCH] code optimization and add ignore file --- .gitignore | 1 + leveldb/storage/file_storage.go | 2 +- manualtest/dbstress/main.go | 9 +++++---- 3 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..9f11b755 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/leveldb/storage/file_storage.go b/leveldb/storage/file_storage.go index 3c5e70a0..d639c9f9 100644 --- a/leveldb/storage/file_storage.go +++ b/leveldb/storage/file_storage.go @@ -126,7 +126,7 @@ func OpenFile(path string, readOnly bool) (Storage, error) { if err != nil { return nil, err } - logSize, err = logw.Seek(0, os.SEEK_END) + logSize, err = logw.Seek(0, io.SeekStart) if err != nil { logw.Close() return nil, err diff --git a/manualtest/dbstress/main.go b/manualtest/dbstress/main.go index 3e2c8d77..180d8135 100644 --- a/manualtest/dbstress/main.go +++ b/manualtest/dbstress/main.go @@ -5,6 +5,7 @@ import ( "encoding/binary" "flag" "fmt" + "io" "log" mrand "math/rand" "net/http" @@ -162,7 +163,7 @@ func (ts *testingStorage) scanTable(fd storage.FileDesc, checksum bool) (corrupt } defer r.Close() - size, err := r.Seek(0, os.SEEK_END) + size, err := r.Seek(0, io.SeekStart) if err != nil { return false, err } @@ -280,9 +281,9 @@ func (s *latencyStats) record(n int) { } func (s *latencyStats) ratePerSec() int { - durSec := s.dur / time.Second - if durSec > 0 { - return s.num / int(durSec) + dur := s.dur / time.Second + if dur > 0 { + return s.num / int(dur) } return s.num }