mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-15 20:06:19 +08:00
add lots of error checking by GThomas
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"code.google.com/p/weed-fs/go/util"
|
||||
"log"
|
||||
"os"
|
||||
"code.google.com/p/weed-fs/go/util"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
/*
|
||||
* Default more not to gzip since gzip can be done on client side.
|
||||
*/
|
||||
*/
|
||||
func IsGzippable(ext, mtype string) bool {
|
||||
if strings.HasPrefix(mtype, "text/") {
|
||||
return true
|
||||
|
@@ -94,14 +94,17 @@ func (nm *NeedleMap) Delete(key uint64) error {
|
||||
util.Uint32toBytes(nm.bytes[8:12], 0)
|
||||
util.Uint32toBytes(nm.bytes[12:16], 0)
|
||||
if _, err = nm.indexFile.Write(nm.bytes); err != nil {
|
||||
nm.indexFile.Truncate(offset)
|
||||
return fmt.Errorf("error writing to indexfile %s: %s", nm.indexFile, err)
|
||||
plus := ""
|
||||
if e := nm.indexFile.Truncate(offset); e != nil {
|
||||
plus = "\ncouldn't truncate index file: " + e.Error()
|
||||
}
|
||||
return fmt.Errorf("error writing to indexfile %s: %s%s", nm.indexFile, err, plus)
|
||||
}
|
||||
nm.deletionCounter++
|
||||
return nil
|
||||
}
|
||||
func (nm *NeedleMap) Close() {
|
||||
nm.indexFile.Close()
|
||||
_ = nm.indexFile.Close()
|
||||
}
|
||||
func (nm *NeedleMap) ContentSize() uint64 {
|
||||
return nm.fileByteCounter
|
||||
|
@@ -1,11 +1,11 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"code.google.com/p/weed-fs/go/util"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"code.google.com/p/weed-fs/go/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@@ -1,12 +1,12 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"code.google.com/p/weed-fs/go/util"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/url"
|
||||
"code.google.com/p/weed-fs/go/util"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@@ -175,7 +175,9 @@ func (s *Store) Write(i VolumeId, n *Needle) (size uint32, err error) {
|
||||
size, err = v.write(n)
|
||||
if err != nil && s.volumeSizeLimit < v.ContentSize()+uint64(size) && s.volumeSizeLimit >= v.ContentSize() {
|
||||
log.Println("volume", i, "size is", v.ContentSize(), "close to", s.volumeSizeLimit)
|
||||
s.Join()
|
||||
if err = s.Join(); err != nil {
|
||||
log.Printf("error with Join: %s", err)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@@ -86,7 +86,7 @@ func (v *Volume) Close() {
|
||||
v.accessLock.Lock()
|
||||
defer v.accessLock.Unlock()
|
||||
v.nm.Close()
|
||||
v.dataFile.Close()
|
||||
_ = v.dataFile.Close()
|
||||
}
|
||||
func (v *Volume) maybeWriteSuperBlock() error {
|
||||
stat, e := v.dataFile.Stat()
|
||||
@@ -101,7 +101,9 @@ func (v *Volume) maybeWriteSuperBlock() error {
|
||||
return e
|
||||
}
|
||||
func (v *Volume) readSuperBlock() (err error) {
|
||||
v.dataFile.Seek(0, 0)
|
||||
if _, err = v.dataFile.Seek(0, 0); err != nil {
|
||||
return fmt.Errorf("cannot seek to the beginning of %s: %s", v.dataFile, err)
|
||||
}
|
||||
header := make([]byte, SuperBlockSize)
|
||||
if _, e := v.dataFile.Read(header); e != nil {
|
||||
return fmt.Errorf("cannot read superblock: %s", e)
|
||||
@@ -128,7 +130,9 @@ func (v *Volume) write(n *Needle) (size uint32, err error) {
|
||||
return
|
||||
}
|
||||
if size, err = n.Append(v.dataFile, v.Version()); err != nil {
|
||||
v.dataFile.Truncate(offset)
|
||||
if e := v.dataFile.Truncate(offset); e != nil {
|
||||
err = fmt.Errorf("%s\ncannot truncate %s: %s", err, v.dataFile, e)
|
||||
}
|
||||
return
|
||||
}
|
||||
nv, ok := v.nm.Get(n.Id)
|
||||
@@ -143,9 +147,14 @@ func (v *Volume) delete(n *Needle) (uint32, error) {
|
||||
nv, ok := v.nm.Get(n.Id)
|
||||
//fmt.Println("key", n.Id, "volume offset", nv.Offset, "data_size", n.Size, "cached size", nv.Size)
|
||||
if ok {
|
||||
v.nm.Delete(n.Id)
|
||||
v.dataFile.Seek(int64(nv.Offset*NeedlePaddingSize), 0)
|
||||
_, err := n.Append(v.dataFile, v.Version())
|
||||
var err error
|
||||
if err = v.nm.Delete(n.Id); err != nil {
|
||||
return nv.Size, err
|
||||
}
|
||||
if _, err = v.dataFile.Seek(int64(nv.Offset*NeedlePaddingSize), 0); err != nil {
|
||||
return nv.Size, err
|
||||
}
|
||||
_, err = n.Append(v.dataFile, v.Version())
|
||||
return nv.Size, err
|
||||
}
|
||||
return 0, nil
|
||||
@@ -156,7 +165,9 @@ func (v *Volume) read(n *Needle) (int, error) {
|
||||
defer v.accessLock.Unlock()
|
||||
nv, ok := v.nm.Get(n.Id)
|
||||
if ok && nv.Offset > 0 {
|
||||
v.dataFile.Seek(int64(nv.Offset)*NeedlePaddingSize, 0)
|
||||
if _, err := v.dataFile.Seek(int64(nv.Offset)*NeedlePaddingSize, 0); err != nil {
|
||||
return -1, err
|
||||
}
|
||||
return n.Read(v.dataFile, nv.Size, v.Version())
|
||||
}
|
||||
return -1, errors.New("Not Found")
|
||||
@@ -176,7 +187,7 @@ func (v *Volume) compact() error {
|
||||
func (v *Volume) commitCompact() error {
|
||||
v.accessLock.Lock()
|
||||
defer v.accessLock.Unlock()
|
||||
v.dataFile.Close()
|
||||
_ = v.dataFile.Close()
|
||||
var e error
|
||||
if e = os.Rename(path.Join(v.dir, v.Id.String()+".cpd"), path.Join(v.dir, v.Id.String()+".dat")); e != nil {
|
||||
return e
|
||||
|
Reference in New Issue
Block a user