mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
Cleanup error printing.
This commit is contained in:
parent
5afdc469a3
commit
af416189f1
|
@ -62,7 +62,7 @@ func NewDirectoryManagerInMap(dirLogFile string) (dm *DirectoryManagerInMap, err
|
||||||
//dm.Root do not use NewDirectoryEntryInMap, since dm.max will be changed
|
//dm.Root do not use NewDirectoryEntryInMap, since dm.max will be changed
|
||||||
dm.Root = &DirectoryEntryInMap{SubDirectories: make(map[string]*DirectoryEntryInMap)}
|
dm.Root = &DirectoryEntryInMap{SubDirectories: make(map[string]*DirectoryEntryInMap)}
|
||||||
if dm.logFile, err = os.OpenFile(dirLogFile, os.O_RDWR|os.O_CREATE, 0644); err != nil {
|
if dm.logFile, err = os.OpenFile(dirLogFile, os.O_RDWR|os.O_CREATE, 0644); err != nil {
|
||||||
return nil, fmt.Errorf("cannot write directory log file %s.idx: %s", dirLogFile, err.Error())
|
return nil, fmt.Errorf("cannot write directory log file %s.idx: %v", dirLogFile, err)
|
||||||
}
|
}
|
||||||
return dm, dm.load()
|
return dm, dm.load()
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,12 +214,12 @@ func DumpNeedleMapToCdb(cdbName string, nm *NeedleMap) error {
|
||||||
func openTempCdb(fileName string) (cdb.AdderFunc, cdb.CloserFunc, error) {
|
func openTempCdb(fileName string) (cdb.AdderFunc, cdb.CloserFunc, error) {
|
||||||
fh, err := os.Create(fileName)
|
fh, err := os.Create(fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("cannot create cdb file %s: %s", fileName, err.Error())
|
return nil, nil, fmt.Errorf("cannot create cdb file %s: %v", fileName, err)
|
||||||
}
|
}
|
||||||
adder, closer, err := cdb.MakeFactory(fh)
|
adder, closer, err := cdb.MakeFactory(fh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fh.Close()
|
fh.Close()
|
||||||
return nil, nil, fmt.Errorf("error creating factory: %s", err.Error())
|
return nil, nil, fmt.Errorf("error creating factory: %v", err)
|
||||||
}
|
}
|
||||||
return adder, func() error {
|
return adder, func() error {
|
||||||
if e := closer(); e != nil {
|
if e := closer(); e != nil {
|
||||||
|
|
|
@ -126,7 +126,7 @@ func (nm *NeedleMap) Put(key uint64, offset uint32, size uint32) (int, error) {
|
||||||
nm.DeletionByteCounter = nm.DeletionByteCounter + uint64(oldSize)
|
nm.DeletionByteCounter = nm.DeletionByteCounter + uint64(oldSize)
|
||||||
}
|
}
|
||||||
if _, err := nm.indexFile.Seek(0, 2); err != nil {
|
if _, err := nm.indexFile.Seek(0, 2); err != nil {
|
||||||
return 0, fmt.Errorf("cannot go to the end of indexfile %s: %s", nm.indexFile.Name(), err.Error())
|
return 0, fmt.Errorf("cannot go to the end of indexfile %s: %v", nm.indexFile.Name(), err)
|
||||||
}
|
}
|
||||||
return nm.indexFile.Write(bytes)
|
return nm.indexFile.Write(bytes)
|
||||||
}
|
}
|
||||||
|
@ -141,10 +141,10 @@ func (nm *NeedleMap) Delete(key uint64) error {
|
||||||
util.Uint32toBytes(bytes[8:12], 0)
|
util.Uint32toBytes(bytes[8:12], 0)
|
||||||
util.Uint32toBytes(bytes[12:16], 0)
|
util.Uint32toBytes(bytes[12:16], 0)
|
||||||
if _, err := nm.indexFile.Seek(0, 2); err != nil {
|
if _, err := nm.indexFile.Seek(0, 2); err != nil {
|
||||||
return fmt.Errorf("cannot go to the end of indexfile %s: %s", nm.indexFile.Name(), err.Error())
|
return fmt.Errorf("cannot go to the end of indexfile %s: %v", nm.indexFile.Name(), err)
|
||||||
}
|
}
|
||||||
if _, err := nm.indexFile.Write(bytes); err != nil {
|
if _, err := nm.indexFile.Write(bytes); err != nil {
|
||||||
return fmt.Errorf("error writing to indexfile %s: %s", nm.indexFile.Name(), err.Error())
|
return fmt.Errorf("error writing to indexfile %s: %v", nm.indexFile.Name(), err)
|
||||||
}
|
}
|
||||||
nm.DeletionCounter++
|
nm.DeletionCounter++
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -30,12 +30,12 @@ func (n *Needle) Append(w io.Writer, version Version) (size uint32, err error) {
|
||||||
defer func(s io.Seeker, off int64) {
|
defer func(s io.Seeker, off int64) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, e = s.Seek(off, 0); e != nil {
|
if _, e = s.Seek(off, 0); e != nil {
|
||||||
glog.V(0).Infof("Failed to seek %s back to %d with error: %s", w, off, e.Error())
|
glog.V(0).Infof("Failed to seek %s back to %d with error: %v", w, off, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(s, end)
|
}(s, end)
|
||||||
} else {
|
} else {
|
||||||
err = fmt.Errorf("Cnnot Read Current Volume Position: %s", e.Error())
|
err = fmt.Errorf("Cnnot Read Current Volume Position: %v", e)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,10 +287,10 @@ func ScanVolumeFile(dirname string, collection string, id VolumeId,
|
||||||
visitNeedle func(n *Needle, offset int64) error) (err error) {
|
visitNeedle func(n *Needle, offset int64) error) (err error) {
|
||||||
var v *Volume
|
var v *Volume
|
||||||
if v, err = loadVolumeWithoutIndex(dirname, collection, id); err != nil {
|
if v, err = loadVolumeWithoutIndex(dirname, collection, id); err != nil {
|
||||||
return errors.New("Failed to load volume:" + err.Error())
|
return fmt.Errorf("Failed to load volume %d: %v", id, err)
|
||||||
}
|
}
|
||||||
if err = visitSuperBlock(v.SuperBlock); err != nil {
|
if err = visitSuperBlock(v.SuperBlock); err != nil {
|
||||||
return errors.New("Failed to read super block:" + err.Error())
|
return fmt.Errorf("Failed to read volume %d super block: %v", id, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
version := v.Version()
|
version := v.Version()
|
||||||
|
|
|
@ -39,5 +39,6 @@ func NewVolumeInfo(m *operation.VolumeInformationMessage) (vi VolumeInfo, err er
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vi VolumeInfo) String() string {
|
func (vi VolumeInfo) String() string {
|
||||||
return fmt.Sprintf("Id:%s, Size:%d, ReplicaPlacement:%s, Collection:%s, Version:%v, FileCount:%d, DeleteCount:%d, DeletedByteCount:%d, ReadOnly:%v", vi.Id, vi.Size, vi.ReplicaPlacement, vi.Collection, vi.Version, vi.FileCount, vi.DeleteCount, vi.DeletedByteCount, vi.ReadOnly)
|
return fmt.Sprintf("Id:%d, Size:%d, ReplicaPlacement:%s, Collection:%s, Version:%v, FileCount:%d, DeleteCount:%d, DeletedByteCount:%d, ReadOnly:%v",
|
||||||
|
vi.Id, vi.Size, vi.ReplicaPlacement, vi.Collection, vi.Version, vi.FileCount, vi.DeleteCount, vi.DeletedByteCount, vi.ReadOnly)
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ func (s *SuperBlock) Bytes() []byte {
|
||||||
func (v *Volume) maybeWriteSuperBlock() error {
|
func (v *Volume) maybeWriteSuperBlock() error {
|
||||||
stat, e := v.dataFile.Stat()
|
stat, e := v.dataFile.Stat()
|
||||||
if e != nil {
|
if e != nil {
|
||||||
glog.V(0).Infof("failed to stat datafile %s: %s", v.dataFile, e.Error())
|
glog.V(0).Infof("failed to stat datafile %s: %v", v.dataFile, e)
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
if stat.Size() == 0 {
|
if stat.Size() == 0 {
|
||||||
|
@ -57,11 +57,11 @@ func (v *Volume) maybeWriteSuperBlock() error {
|
||||||
}
|
}
|
||||||
func (v *Volume) readSuperBlock() (err error) {
|
func (v *Volume) readSuperBlock() (err error) {
|
||||||
if _, err = v.dataFile.Seek(0, 0); err != nil {
|
if _, err = v.dataFile.Seek(0, 0); err != nil {
|
||||||
return fmt.Errorf("cannot seek to the beginning of %s: %s", v.dataFile.Name(), err.Error())
|
return fmt.Errorf("cannot seek to the beginning of %s: %v", v.dataFile.Name(), err)
|
||||||
}
|
}
|
||||||
header := make([]byte, SuperBlockSize)
|
header := make([]byte, SuperBlockSize)
|
||||||
if _, e := v.dataFile.Read(header); e != nil {
|
if _, e := v.dataFile.Read(header); e != nil {
|
||||||
return fmt.Errorf("cannot read superblock: %s", e.Error())
|
return fmt.Errorf("cannot read volume %d super block: %v", v.Id, e)
|
||||||
}
|
}
|
||||||
v.SuperBlock, err = ParseSuperBlock(header)
|
v.SuperBlock, err = ParseSuperBlock(header)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -33,7 +33,7 @@ func TestLoadConfiguration(t *testing.T) {
|
||||||
|
|
||||||
fmt.Printf("%s\n", c)
|
fmt.Printf("%s\n", c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unmarshal error:%s", err.Error())
|
t.Fatalf("unmarshal error:%v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(c.Topo.DataCenters) <= 0 || c.Topo.DataCenters[0].Name != "dc1" {
|
if len(c.Topo.DataCenters) <= 0 || c.Topo.DataCenters[0].Name != "dc1" {
|
||||||
|
|
|
@ -204,7 +204,7 @@ func (vg *VolumeGrowth) grow(topo *Topology, vid storage.VolumeId, option *Volum
|
||||||
glog.V(0).Infoln("Created Volume", vid, "on", server)
|
glog.V(0).Infoln("Created Volume", vid, "on", server)
|
||||||
} else {
|
} else {
|
||||||
glog.V(0).Infoln("Failed to assign", vid, "to", servers, "error", err)
|
glog.V(0).Infoln("Failed to assign", vid, "to", servers, "error", err)
|
||||||
return fmt.Errorf("Failed to assign %s: %s", vid.String(), err.Error())
|
return fmt.Errorf("Failed to assign %d: %v", vid, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -77,7 +77,7 @@ func runFiler(cmd *Command, args []string) bool {
|
||||||
*f.redis_server, *f.redis_database,
|
*f.redis_server, *f.redis_database,
|
||||||
)
|
)
|
||||||
if nfs_err != nil {
|
if nfs_err != nil {
|
||||||
glog.Fatalf(nfs_err.Error())
|
glog.Fatalf("Filer startup error: %v", nfs_err)
|
||||||
}
|
}
|
||||||
glog.V(0).Infoln("Start Seaweed Filer", util.VERSION, "at port", strconv.Itoa(*f.port))
|
glog.V(0).Infoln("Start Seaweed Filer", util.VERSION, "at port", strconv.Itoa(*f.port))
|
||||||
filerListener, e := util.NewListener(
|
filerListener, e := util.NewListener(
|
||||||
|
@ -85,10 +85,10 @@ func runFiler(cmd *Command, args []string) bool {
|
||||||
time.Duration(10)*time.Second,
|
time.Duration(10)*time.Second,
|
||||||
)
|
)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
glog.Fatalf(e.Error())
|
glog.Fatalf("Filer listener error: %v", e)
|
||||||
}
|
}
|
||||||
if e := http.Serve(filerListener, r); e != nil {
|
if e := http.Serve(filerListener, r); e != nil {
|
||||||
glog.Fatalf("Filer Fail to serve:%s", e.Error())
|
glog.Fatalf("Filer Fail to serve: %v", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -71,7 +71,7 @@ func runMaster(cmd *Command, args []string) bool {
|
||||||
|
|
||||||
listener, e := util.NewListener(listeningAddress, time.Duration(*mTimeout)*time.Second)
|
listener, e := util.NewListener(listeningAddress, time.Duration(*mTimeout)*time.Second)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
glog.Fatalf(e.Error())
|
glog.Fatalf("Master startup error: %v", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -93,7 +93,7 @@ func runMaster(cmd *Command, args []string) bool {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if e := http.Serve(listener, r); e != nil {
|
if e := http.Serve(listener, r); e != nil {
|
||||||
glog.Fatalf("Fail to serve:%s", e.Error())
|
glog.Fatalf("Fail to serve: %v", e)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,7 +167,7 @@ func runServer(cmd *Command, args []string) bool {
|
||||||
"", 0,
|
"", 0,
|
||||||
)
|
)
|
||||||
if nfs_err != nil {
|
if nfs_err != nil {
|
||||||
glog.Fatalf(nfs_err.Error())
|
glog.Fatalf("Filer startup error: %v", nfs_err)
|
||||||
}
|
}
|
||||||
glog.V(0).Infoln("Start Seaweed Filer", util.VERSION, "at port", strconv.Itoa(*filerOptions.port))
|
glog.V(0).Infoln("Start Seaweed Filer", util.VERSION, "at port", strconv.Itoa(*filerOptions.port))
|
||||||
filerListener, e := util.NewListener(
|
filerListener, e := util.NewListener(
|
||||||
|
@ -175,10 +175,11 @@ func runServer(cmd *Command, args []string) bool {
|
||||||
time.Duration(10)*time.Second,
|
time.Duration(10)*time.Second,
|
||||||
)
|
)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
|
glog.Fatalf("Filer listener error: %v", e)
|
||||||
glog.Fatalf(e.Error())
|
glog.Fatalf(e.Error())
|
||||||
}
|
}
|
||||||
if e := http.Serve(filerListener, r); e != nil {
|
if e := http.Serve(filerListener, r); e != nil {
|
||||||
glog.Fatalf("Filer Fail to serve:%s", e.Error())
|
glog.Fatalf("Filer Fail to serve: %v", e)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
@ -199,7 +200,7 @@ func runServer(cmd *Command, args []string) bool {
|
||||||
glog.V(0).Infoln("Start Seaweed Master", util.VERSION, "at", *serverIp+":"+strconv.Itoa(*masterPort))
|
glog.V(0).Infoln("Start Seaweed Master", util.VERSION, "at", *serverIp+":"+strconv.Itoa(*masterPort))
|
||||||
masterListener, e := util.NewListener(*serverBindIp+":"+strconv.Itoa(*masterPort), time.Duration(*serverTimeout)*time.Second)
|
masterListener, e := util.NewListener(*serverBindIp+":"+strconv.Itoa(*masterPort), time.Duration(*serverTimeout)*time.Second)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
glog.Fatalf(e.Error())
|
glog.Fatalf("Master startup error: %v", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -235,7 +236,7 @@ func runServer(cmd *Command, args []string) bool {
|
||||||
time.Duration(*serverTimeout)*time.Second,
|
time.Duration(*serverTimeout)*time.Second,
|
||||||
)
|
)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
glog.Fatalf(e.Error())
|
glog.Fatalf("Volume server listener error: %v", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
OnInterrupt(func() {
|
OnInterrupt(func() {
|
||||||
|
@ -244,7 +245,7 @@ func runServer(cmd *Command, args []string) bool {
|
||||||
})
|
})
|
||||||
|
|
||||||
if e := http.Serve(volumeListener, r); e != nil {
|
if e := http.Serve(volumeListener, r); e != nil {
|
||||||
glog.Fatalf("Fail to serve:%s", e.Error())
|
glog.Fatalf("Volume server fail to serve:%v", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -119,7 +119,7 @@ func runVolume(cmd *Command, args []string) bool {
|
||||||
|
|
||||||
listener, e := util.NewListener(listeningAddress, time.Duration(*v.idleConnectionTimeout)*time.Second)
|
listener, e := util.NewListener(listeningAddress, time.Duration(*v.idleConnectionTimeout)*time.Second)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
glog.Fatalf(e.Error())
|
glog.Fatalf("Volume server listener error:%v", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
OnInterrupt(func() {
|
OnInterrupt(func() {
|
||||||
|
@ -127,7 +127,7 @@ func runVolume(cmd *Command, args []string) bool {
|
||||||
})
|
})
|
||||||
|
|
||||||
if e := http.Serve(listener, r); e != nil {
|
if e := http.Serve(listener, r); e != nil {
|
||||||
glog.Fatalf("Fail to serve:%s", e.Error())
|
glog.Fatalf("Volume server fail to serve: %v", e)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ func writeJson(w http.ResponseWriter, r *http.Request, httpStatus int, obj inter
|
||||||
// wrapper for writeJson - just logs errors
|
// wrapper for writeJson - just logs errors
|
||||||
func writeJsonQuiet(w http.ResponseWriter, r *http.Request, httpStatus int, obj interface{}) {
|
func writeJsonQuiet(w http.ResponseWriter, r *http.Request, httpStatus int, obj interface{}) {
|
||||||
if err := writeJson(w, r, httpStatus, obj); err != nil {
|
if err := writeJson(w, r, httpStatus, obj); err != nil {
|
||||||
glog.V(0).Infof("error writing JSON %s: %s", obj, err.Error())
|
glog.V(0).Infof("error writing JSON %s: %v", obj, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func writeJsonError(w http.ResponseWriter, r *http.Request, httpStatus int, err error) {
|
func writeJsonError(w http.ResponseWriter, r *http.Request, httpStatus int, err error) {
|
||||||
|
|
Loading…
Reference in a new issue