2. go vet found many printing format errors
This commit is contained in:
Chris Lu 2014-04-17 00:16:44 -07:00
parent 51939efeac
commit 3b5035c468
11 changed files with 22 additions and 24 deletions

View file

@ -142,7 +142,7 @@ func (m cdbMap) Visit(visit func(NeedleValue) error) (err error) {
func ConvertIndexToCdb(cdbName string, index *os.File) error { func ConvertIndexToCdb(cdbName string, index *os.File) error {
idx, err := LoadNeedleMap(index) idx, err := LoadNeedleMap(index)
if err != nil { if err != nil {
return fmt.Errorf("error loading needle map %s: %s", index, err) return fmt.Errorf("error loading needle map %s: %s", index.Name(), err)
} }
defer idx.Close() defer idx.Close()
return DumpNeedleMapToCdb(cdbName, idx) return DumpNeedleMapToCdb(cdbName, idx)
@ -185,12 +185,12 @@ func DumpNeedleMapToCdb(cdbName string, nm *NeedleMap) error {
}) })
if err != nil { if err != nil {
closer() closer()
return fmt.Errorf("error walking index %s: %s", nm, err) return fmt.Errorf("error walking index %v: %s", nm, err)
} }
// store fileBytes // store fileBytes
data, e := json.Marshal(nm.mapMetric) data, e := json.Marshal(nm.mapMetric)
if e != nil { if e != nil {
return fmt.Errorf("error marshaling metric %s: %s", nm.mapMetric, e) return fmt.Errorf("error marshaling metric %v: %s", nm.mapMetric, e)
} }
if err = adder(cdb.Element{Key: []byte{'M'}, Data: data}); err != nil { if err = adder(cdb.Element{Key: []byte{'M'}, Data: data}); err != nil {
return err return err

View file

@ -84,7 +84,7 @@ func BenchmarkCdbMap9List(t *testing.B) {
t.Logf("opening %s", indexFile) t.Logf("opening %s", indexFile)
idx, err := LoadNeedleMap(indexFile) idx, err := LoadNeedleMap(indexFile)
if err != nil { if err != nil {
t.Fatalf("cannot load %s: %s", indexFile, err) t.Fatalf("cannot load %s: %s", indexFile.Name(), err)
} }
defer idx.Close() defer idx.Close()
b := getMemStats() b := getMemStats()
@ -113,7 +113,7 @@ func BenchmarkCdbMap9List(t *testing.B) {
glog.V(0).Infof("%d. %s", i, nv) glog.V(0).Infof("%d. %s", i, nv)
} }
if nv2, ok := m.Get(uint64(nv.Key)); !ok || nv2 == nil { if nv2, ok := m.Get(uint64(nv.Key)); !ok || nv2 == nil {
t.Errorf("%s in index, not in cdb", nv.Key) t.Errorf("%d in index, not in cdb", nv.Key)
} else if nv2.Key != nv.Key { } else if nv2.Key != nv.Key {
t.Errorf("requested key %d from cdb, got %d", nv.Key, nv2.Key) t.Errorf("requested key %d from cdb, got %d", nv.Key, nv2.Key)
} else if nv2.Offset != nv.Offset { } else if nv2.Offset != nv.Offset {
@ -137,7 +137,7 @@ func BenchmarkCdbMap9List(t *testing.B) {
return nil return nil
} }
if nv2, ok := m.Get(uint64(nv.Key)); !ok || nv2 == nil { if nv2, ok := m.Get(uint64(nv.Key)); !ok || nv2 == nil {
t.Errorf("%s in cdb, not in index", nv.Key) t.Errorf("%d in cdb, not in index", nv.Key)
} else if nv2.Key != nv.Key { } else if nv2.Key != nv.Key {
t.Errorf("requested key %d from index, got %d", nv.Key, nv2.Key) t.Errorf("requested key %d from index, got %d", nv.Key, nv2.Key)
} else if nv2.Offset != nv.Offset { } else if nv2.Offset != nv.Offset {

View file

@ -145,7 +145,7 @@ func (nm *NeedleMap) Delete(key uint64) error {
if e := nm.indexFile.Truncate(offset); e != nil { if e := nm.indexFile.Truncate(offset); e != nil {
plus = "\ncouldn't truncate index file: " + e.Error() plus = "\ncouldn't truncate index file: " + e.Error()
} }
return fmt.Errorf("error writing to indexfile %s: %s%s", nm.indexFile, err, plus) return fmt.Errorf("error writing to indexfile %s: %s%s", nm.indexFile.Name(), err, plus)
} }
nm.DeletionCounter++ nm.DeletionCounter++
return nil return nil

View file

@ -150,7 +150,7 @@ func (s *Store) findFreeLocation() (ret *DiskLocation) {
} }
func (s *Store) addVolume(vid VolumeId, collection string, replicaPlacement *ReplicaPlacement) error { func (s *Store) addVolume(vid VolumeId, collection string, replicaPlacement *ReplicaPlacement) error {
if s.findVolume(vid) != nil { if s.findVolume(vid) != nil {
return fmt.Errorf("Volume Id %s already exists!", vid) return fmt.Errorf("Volume Id %d already exists!", vid)
} }
if location := s.findFreeLocation(); location != nil { if location := s.findFreeLocation(); location != nil {
glog.V(0).Infoln("In dir", location.Directory, "adds volume =", vid, ", collection =", collection, ", replicaPlacement =", replicaPlacement) glog.V(0).Infoln("In dir", location.Directory, "adds volume =", vid, ", collection =", collection, ", replicaPlacement =", replicaPlacement)
@ -177,7 +177,7 @@ func (s *Store) CheckCompactVolume(volumeIdString string, garbageThresholdString
glog.V(3).Infoln(vid, "garbage level is", v.garbageLevel()) glog.V(3).Infoln(vid, "garbage level is", v.garbageLevel())
return nil, garbageThreshold < v.garbageLevel() return nil, garbageThreshold < v.garbageLevel()
} }
return fmt.Errorf("volume id %s is not found during check compact!", vid), false return fmt.Errorf("volume id %d is not found during check compact!", vid), false
} }
func (s *Store) CompactVolume(volumeIdString string) error { func (s *Store) CompactVolume(volumeIdString string) error {
vid, err := NewVolumeId(volumeIdString) vid, err := NewVolumeId(volumeIdString)
@ -187,7 +187,7 @@ func (s *Store) CompactVolume(volumeIdString string) error {
if v := s.findVolume(vid); v != nil { if v := s.findVolume(vid); v != nil {
return v.Compact() return v.Compact()
} }
return fmt.Errorf("volume id %s is not found during compact!", vid) return fmt.Errorf("volume id %d is not found during compact!", vid)
} }
func (s *Store) CommitCompactVolume(volumeIdString string) error { func (s *Store) CommitCompactVolume(volumeIdString string) error {
vid, err := NewVolumeId(volumeIdString) vid, err := NewVolumeId(volumeIdString)
@ -197,7 +197,7 @@ func (s *Store) CommitCompactVolume(volumeIdString string) error {
if v := s.findVolume(vid); v != nil { if v := s.findVolume(vid); v != nil {
return v.commitCompact() return v.commitCompact()
} }
return fmt.Errorf("volume id %s is not found during commit compact!", vid) return fmt.Errorf("volume id %d is not found during commit compact!", vid)
} }
func (s *Store) FreezeVolume(volumeIdString string) error { func (s *Store) FreezeVolume(volumeIdString string) error {
vid, err := NewVolumeId(volumeIdString) vid, err := NewVolumeId(volumeIdString)
@ -210,7 +210,7 @@ func (s *Store) FreezeVolume(volumeIdString string) error {
} }
return v.freeze() return v.freeze()
} }
return fmt.Errorf("volume id %s is not found during freeze!", vid) return fmt.Errorf("volume id %d is not found during freeze!", vid)
} }
func (l *DiskLocation) loadExistingVolumes() { func (l *DiskLocation) loadExistingVolumes() {
if dirs, err := ioutil.ReadDir(l.Directory); err == nil { if dirs, err := ioutil.ReadDir(l.Directory); err == nil {
@ -328,7 +328,7 @@ func (s *Store) Close() {
func (s *Store) Write(i VolumeId, n *Needle) (size uint32, err error) { func (s *Store) Write(i VolumeId, n *Needle) (size uint32, err error) {
if v := s.findVolume(i); v != nil { if v := s.findVolume(i); v != nil {
if v.readOnly { if v.readOnly {
err = fmt.Errorf("Volume %s is read only!", i) err = fmt.Errorf("Volume %d is read only!", i)
return return
} else { } else {
if MaxPossibleVolumeSize >= v.ContentSize()+uint64(size) { if MaxPossibleVolumeSize >= v.ContentSize()+uint64(size) {
@ -346,7 +346,7 @@ func (s *Store) Write(i VolumeId, n *Needle) (size uint32, err error) {
return return
} }
glog.V(0).Infoln("volume", i, "not found!") glog.V(0).Infoln("volume", i, "not found!")
err = fmt.Errorf("Volume %s not found!", i) err = fmt.Errorf("Volume %d not found!", i)
return return
} }
func (s *Store) Delete(i VolumeId, n *Needle) (uint32, error) { func (s *Store) Delete(i VolumeId, n *Needle) (uint32, error) {

View file

@ -195,7 +195,7 @@ func (v *Volume) isFileUnchanged(n *Needle) bool {
func (v *Volume) Destroy() (err error) { func (v *Volume) Destroy() (err error) {
if v.readOnly { if v.readOnly {
err = fmt.Errorf("%s is read-only", v.dataFile) err = fmt.Errorf("%s is read-only", v.dataFile.Name())
return return
} }
v.Close() v.Close()
@ -210,7 +210,7 @@ func (v *Volume) Destroy() (err error) {
func (v *Volume) write(n *Needle) (size uint32, err error) { func (v *Volume) write(n *Needle) (size uint32, err error) {
glog.V(4).Infof("writing needle %s", NewFileIdFromNeedle(v.Id, n).String()) glog.V(4).Infof("writing needle %s", NewFileIdFromNeedle(v.Id, n).String())
if v.readOnly { if v.readOnly {
err = fmt.Errorf("%s is read-only", v.dataFile) err = fmt.Errorf("%s is read-only", v.dataFile.Name())
return return
} }
v.accessLock.Lock() v.accessLock.Lock()
@ -236,7 +236,7 @@ func (v *Volume) write(n *Needle) (size uint32, err error) {
if size, err = n.Append(v.dataFile, v.Version()); err != nil { if size, err = n.Append(v.dataFile, v.Version()); err != nil {
if e := v.dataFile.Truncate(offset); e != nil { if e := v.dataFile.Truncate(offset); e != nil {
err = fmt.Errorf("%s\ncannot truncate %s: %s", err, v.dataFile, e.Error()) err = fmt.Errorf("%s\ncannot truncate %s: %s", err, v.dataFile.Name(), e.Error())
} }
return return
} }
@ -252,7 +252,7 @@ func (v *Volume) write(n *Needle) (size uint32, err error) {
func (v *Volume) delete(n *Needle) (uint32, error) { func (v *Volume) delete(n *Needle) (uint32, error) {
glog.V(4).Infof("delete needle %s", NewFileIdFromNeedle(v.Id, n).String()) glog.V(4).Infof("delete needle %s", NewFileIdFromNeedle(v.Id, n).String())
if v.readOnly { if v.readOnly {
return 0, fmt.Errorf("%s is read-only", v.dataFile) return 0, fmt.Errorf("%s is read-only", v.dataFile.Name())
} }
v.accessLock.Lock() v.accessLock.Lock()
defer v.accessLock.Unlock() defer v.accessLock.Unlock()

View file

@ -107,7 +107,6 @@ func (vl *VolumeLayout) PickForWrite(count int, option *VolumeGrowOption) (*stor
} }
return &vid, count, locationList, nil return &vid, count, locationList, nil
} }
return nil, 0, nil, errors.New("Strangely This Should Never Have Happened!")
} }
func (vl *VolumeLayout) GetActiveVolumeCount(option *VolumeGrowOption) int { func (vl *VolumeLayout) GetActiveVolumeCount(option *VolumeGrowOption) int {

View file

@ -3,5 +3,5 @@ package util
import () import ()
const ( const (
VERSION = "0.54 beta" VERSION = "0.54"
) )

View file

@ -94,7 +94,7 @@ func runExport(cmd *Command, args []string) bool {
nm, err := storage.LoadNeedleMap(indexFile) nm, err := storage.LoadNeedleMap(indexFile)
if err != nil { if err != nil {
glog.Fatalf("cannot load needle map from %s: %s", indexFile, err) glog.Fatalf("cannot load needle map from %s: %s", indexFile.Name(), err)
} }
var version storage.Version var version storage.Version

View file

@ -86,7 +86,7 @@ func runServer(cmd *Command, args []string) bool {
if max, e := strconv.Atoi(maxString); e == nil { if max, e := strconv.Atoi(maxString); e == nil {
maxCounts = append(maxCounts, max) maxCounts = append(maxCounts, max)
} else { } else {
glog.Fatalf("The max specified in -max not a valid number %s", max) glog.Fatalf("The max specified in -max not a valid number %s", maxString)
} }
} }
if len(folders) != len(maxCounts) { if len(folders) != len(maxCounts) {

View file

@ -57,5 +57,4 @@ func runShell(command *Command, args []string) bool {
cmd = readLine() cmd = readLine()
execCmd(cmd) execCmd(cmd)
} }
return true
} }

View file

@ -53,7 +53,7 @@ func runVolume(cmd *Command, args []string) bool {
if max, e := strconv.Atoi(maxString); e == nil { if max, e := strconv.Atoi(maxString); e == nil {
maxCounts = append(maxCounts, max) maxCounts = append(maxCounts, max)
} else { } else {
glog.Fatalf("The max specified in -max not a valid number %s", max) glog.Fatalf("The max specified in -max not a valid number %s", maxString)
} }
} }
if len(folders) != len(maxCounts) { if len(folders) != len(maxCounts) {