Update dependencies

This commit is contained in:
Jakob Borg 2015-08-18 08:56:07 +02:00
parent b6b6375f70
commit be18cbef8b
14 changed files with 115 additions and 42 deletions

16
Godeps/Godeps.json generated
View File

@ -1,13 +1,13 @@
{ {
"ImportPath": "github.com/syncthing/syncthing", "ImportPath": "github.com/syncthing/syncthing",
"GoVersion": "devel", "GoVersion": "go1.5rc1",
"Packages": [ "Packages": [
"./cmd/..." "./cmd/..."
], ],
"Deps": [ "Deps": [
{ {
"ImportPath": "github.com/bkaradzic/go-lz4", "ImportPath": "github.com/bkaradzic/go-lz4",
"Rev": "4f7c2045dbd17b802370e2e6022200468abf02ba" "Rev": "d47913b1412890a261b9fefae99d72d2bf5aebd8"
}, },
{ {
"ImportPath": "github.com/calmh/du", "ImportPath": "github.com/calmh/du",
@ -27,7 +27,7 @@
}, },
{ {
"ImportPath": "github.com/golang/snappy", "ImportPath": "github.com/golang/snappy",
"Rev": "0c7f8a7704bfec561913f4df52c832f094ef56f0" "Rev": "723cc1e459b8eea2dea4583200fd60757d40097a"
}, },
{ {
"ImportPath": "github.com/juju/ratelimit", "ImportPath": "github.com/juju/ratelimit",
@ -43,7 +43,7 @@
}, },
{ {
"ImportPath": "github.com/syndtr/goleveldb/leveldb", "ImportPath": "github.com/syndtr/goleveldb/leveldb",
"Rev": "183614d6b32571e867df4cf086f5480ceefbdfac" "Rev": "b743d92d3215f11c9b5ce8830fafe1f16786adf4"
}, },
{ {
"ImportPath": "github.com/thejerf/suture", "ImportPath": "github.com/thejerf/suture",
@ -63,19 +63,19 @@
}, },
{ {
"ImportPath": "golang.org/x/crypto/bcrypt", "ImportPath": "golang.org/x/crypto/bcrypt",
"Rev": "7d5b0be716b9d6d4269afdaae10032bb296d3cdf" "Rev": "c16968172724c0b5e8bdc6ad33f5a79443a44cd7"
}, },
{ {
"ImportPath": "golang.org/x/crypto/blowfish", "ImportPath": "golang.org/x/crypto/blowfish",
"Rev": "7d5b0be716b9d6d4269afdaae10032bb296d3cdf" "Rev": "c16968172724c0b5e8bdc6ad33f5a79443a44cd7"
}, },
{ {
"ImportPath": "golang.org/x/text/transform", "ImportPath": "golang.org/x/text/transform",
"Rev": "3eb7007b740b66a77f3c85f2660a0240b284115a" "Rev": "723492b65e225eafcba054e76ba18bb9c5ac1ea2"
}, },
{ {
"ImportPath": "golang.org/x/text/unicode/norm", "ImportPath": "golang.org/x/text/unicode/norm",
"Rev": "3eb7007b740b66a77f3c85f2660a0240b284115a" "Rev": "723492b65e225eafcba054e76ba18bb9c5ac1ea2"
} }
] ]
} }

View File

@ -4,4 +4,5 @@ go:
- 1.1 - 1.1
- 1.2 - 1.2
- 1.3 - 1.3
- 1.4
- tip - tip

View File

@ -4,7 +4,7 @@ go-lz4
go-lz4 is port of LZ4 lossless compression algorithm to Go. The original C code go-lz4 is port of LZ4 lossless compression algorithm to Go. The original C code
is located at: is located at:
https://code.google.com/p/lz4/ https://github.com/Cyan4973/lz4
Status Status
------ ------

View File

@ -13,6 +13,8 @@ import (
var ( var (
// ErrCorrupt reports that the input is invalid. // ErrCorrupt reports that the input is invalid.
ErrCorrupt = errors.New("snappy: corrupt input") ErrCorrupt = errors.New("snappy: corrupt input")
// ErrTooLarge reports that the uncompressed length is too large.
ErrTooLarge = errors.New("snappy: decoded block is too large")
// ErrUnsupported reports that the input isn't supported. // ErrUnsupported reports that the input isn't supported.
ErrUnsupported = errors.New("snappy: unsupported input") ErrUnsupported = errors.New("snappy: unsupported input")
) )
@ -27,11 +29,13 @@ func DecodedLen(src []byte) (int, error) {
// that the length header occupied. // that the length header occupied.
func decodedLen(src []byte) (blockLen, headerLen int, err error) { func decodedLen(src []byte) (blockLen, headerLen int, err error) {
v, n := binary.Uvarint(src) v, n := binary.Uvarint(src)
if n <= 0 { if n <= 0 || v > 0xffffffff {
return 0, 0, ErrCorrupt return 0, 0, ErrCorrupt
} }
if uint64(int(v)) != v {
return 0, 0, errors.New("snappy: decoded block is too large") const wordSize = 32 << (^uint(0) >> 32 & 1)
if wordSize == 32 && v > 0x7fffffff {
return 0, 0, ErrTooLarge
} }
return int(v), n, nil return int(v), n, nil
} }

View File

@ -86,6 +86,16 @@ func TestInvalidVarint(t *testing.T) {
if _, err := Decode(nil, data); err != ErrCorrupt { if _, err := Decode(nil, data); err != ErrCorrupt {
t.Errorf("Decode: got %v, want ErrCorrupt", err) t.Errorf("Decode: got %v, want ErrCorrupt", err)
} }
// The encoded varint overflows 32 bits
data = []byte("\xff\xff\xff\xff\xff\x00")
if _, err := DecodedLen(data); err != ErrCorrupt {
t.Errorf("DecodedLen: got %v, want ErrCorrupt", err)
}
if _, err := Decode(nil, data); err != ErrCorrupt {
t.Errorf("Decode: got %v, want ErrCorrupt", err)
}
} }
func cmp(a, b []byte) error { func cmp(a, b []byte) error {

View File

@ -291,6 +291,7 @@ func recoverTable(s *session, o *opt.Options) error {
// We will drop corrupted table. // We will drop corrupted table.
strict = o.GetStrict(opt.StrictRecovery) strict = o.GetStrict(opt.StrictRecovery)
noSync = o.GetNoSync()
rec = &sessionRecord{} rec = &sessionRecord{}
bpool = util.NewBufferPool(o.GetBlockSize() + 5) bpool = util.NewBufferPool(o.GetBlockSize() + 5)
@ -328,10 +329,12 @@ func recoverTable(s *session, o *opt.Options) error {
if err != nil { if err != nil {
return return
} }
if !noSync {
err = writer.Sync() err = writer.Sync()
if err != nil { if err != nil {
return return
} }
}
size = int64(tw.BytesLen()) size = int64(tw.BytesLen())
return return
} }

View File

@ -129,7 +129,7 @@ func (db *DB) Write(b *Batch, wo *opt.WriteOptions) (err error) {
return return
} }
b.init(wo.GetSync()) b.init(wo.GetSync() && !db.s.o.GetNoSync())
// The write happen synchronously. // The write happen synchronously.
select { select {

View File

@ -52,12 +52,14 @@ func IsCorrupted(err error) bool {
switch err.(type) { switch err.(type) {
case *ErrCorrupted: case *ErrCorrupted:
return true return true
case *storage.ErrCorrupted:
return true
} }
return false return false
} }
// ErrMissingFiles is the type that indicating a corruption due to missing // ErrMissingFiles is the type that indicating a corruption due to missing
// files. // files. ErrMissingFiles always wrapped with ErrCorrupted.
type ErrMissingFiles struct { type ErrMissingFiles struct {
Files []*storage.FileInfo Files []*storage.FileInfo
} }

View File

@ -308,6 +308,11 @@ type Options struct {
// The default is 2. // The default is 2.
MaxMemCompationLevel int MaxMemCompationLevel int
// NoSync allows completely disable fsync.
//
// The default is false.
NoSync bool
// NumLevel defines number of database level. The level shouldn't changed // NumLevel defines number of database level. The level shouldn't changed
// between opens, or the database will panic. // between opens, or the database will panic.
// //
@ -546,6 +551,13 @@ func (o *Options) GetMaxMemCompationLevel() int {
return level return level
} }
func (o *Options) GetNoSync() bool {
if o == nil {
return false
}
return o.NoSync
}
func (o *Options) GetNumLevel() int { func (o *Options) GetNumLevel() int {
if o == nil || o.NumLevel <= 0 { if o == nil || o.NumLevel <= 0 {
return DefaultNumLevel return DefaultNumLevel

View File

@ -240,10 +240,12 @@ func (s *session) flushManifest(rec *sessionRecord) (err error) {
if err != nil { if err != nil {
return return
} }
if !s.o.GetNoSync() {
err = s.manifestWriter.Sync() err = s.manifestWriter.Sync()
if err != nil { if err != nil {
return return
} }
}
s.recordCommited(rec) s.recordCommited(rec)
return return
} }

View File

@ -243,7 +243,10 @@ func (fs *fileStorage) GetManifest() (f File, err error) {
rem = append(rem, fn) rem = append(rem, fn)
} }
if !pend1 || cerr == nil { if !pend1 || cerr == nil {
cerr = fmt.Errorf("leveldb/storage: corrupted or incomplete %s file", fn) cerr = &ErrCorrupted{
File: fsParseName(filepath.Base(fn)),
Err: errors.New("leveldb/storage: corrupted or incomplete manifest file"),
}
} }
} else if f != nil && f1.Num() < f.Num() { } else if f != nil && f1.Num() < f.Num() {
fs.log(fmt.Sprintf("skipping %s: obsolete", fn)) fs.log(fmt.Sprintf("skipping %s: obsolete", fn))
@ -326,8 +329,7 @@ func (fs *fileStorage) Close() error {
runtime.SetFinalizer(fs, nil) runtime.SetFinalizer(fs, nil)
if fs.open > 0 { if fs.open > 0 {
fs.log(fmt.Sprintf("refuse to close, %d files still open", fs.open)) fs.log(fmt.Sprintf("close: warning, %d files still open", fs.open))
return fmt.Errorf("leveldb/storage: cannot close, %d files still open", fs.open)
} }
fs.open = -1 fs.open = -1
e1 := fs.logw.Close() e1 := fs.logw.Close()
@ -505,30 +507,37 @@ func (f *file) path() string {
return filepath.Join(f.fs.path, f.name()) return filepath.Join(f.fs.path, f.name())
} }
func (f *file) parse(name string) bool { func fsParseName(name string) *FileInfo {
var num uint64 fi := &FileInfo{}
var tail string var tail string
_, err := fmt.Sscanf(name, "%d.%s", &num, &tail) _, err := fmt.Sscanf(name, "%d.%s", &fi.Num, &tail)
if err == nil { if err == nil {
switch tail { switch tail {
case "log": case "log":
f.t = TypeJournal fi.Type = TypeJournal
case "ldb", "sst": case "ldb", "sst":
f.t = TypeTable fi.Type = TypeTable
case "tmp": case "tmp":
f.t = TypeTemp fi.Type = TypeTemp
default: default:
return false return nil
} }
f.num = num return fi
return true
} }
n, _ := fmt.Sscanf(name, "MANIFEST-%d%s", &num, &tail) n, _ := fmt.Sscanf(name, "MANIFEST-%d%s", &fi.Num, &tail)
if n == 1 { if n == 1 {
f.t = TypeManifest fi.Type = TypeManifest
f.num = num return fi
return true }
return nil
} }
func (f *file) parse(name string) bool {
fi := fsParseName(name)
if fi == nil {
return false return false
} }
f.t = fi.Type
f.num = fi.Num
return true
}

View File

@ -50,13 +50,23 @@ func rename(oldpath, newpath string) error {
return os.Rename(oldpath, newpath) return os.Rename(oldpath, newpath)
} }
func isErrInvalid(err error) bool {
if err == os.ErrInvalid {
return true
}
if syserr, ok := err.(*os.SyscallError); ok && syserr.Err == syscall.EINVAL {
return true
}
return false
}
func syncDir(name string) error { func syncDir(name string) error {
f, err := os.Open(name) f, err := os.Open(name)
if err != nil { if err != nil {
return err return err
} }
defer f.Close() defer f.Close()
if err := f.Sync(); err != nil { if err := f.Sync(); err != nil && !isErrInvalid(err) {
return err return err
} }
return nil return nil

View File

@ -46,6 +46,22 @@ var (
ErrClosed = errors.New("leveldb/storage: closed") ErrClosed = errors.New("leveldb/storage: closed")
) )
// ErrCorrupted is the type that wraps errors that indicate corruption of
// a file. Package storage has its own type instead of using
// errors.ErrCorrupted to prevent circular import.
type ErrCorrupted struct {
File *FileInfo
Err error
}
func (e *ErrCorrupted) Error() string {
if e.File != nil {
return fmt.Sprintf("%v [file=%v]", e.Err, e.File)
} else {
return e.Err.Error()
}
}
// Syncer is the interface that wraps basic Sync method. // Syncer is the interface that wraps basic Sync method.
type Syncer interface { type Syncer interface {
// Sync commits the current contents of the file to stable storage. // Sync commits the current contents of the file to stable storage.

View File

@ -287,6 +287,7 @@ func (x *tFilesSortByNum) Less(i, j int) bool {
// Table operations. // Table operations.
type tOps struct { type tOps struct {
s *session s *session
noSync bool
cache *cache.Cache cache *cache.Cache
bcache *cache.Cache bcache *cache.Cache
bpool *util.BufferPool bpool *util.BufferPool
@ -458,6 +459,7 @@ func newTableOps(s *session) *tOps {
} }
return &tOps{ return &tOps{
s: s, s: s,
noSync: s.o.GetNoSync(),
cache: cache.NewCache(cacher), cache: cache.NewCache(cacher),
bcache: bcache, bcache: bcache,
bpool: bpool, bpool: bpool,
@ -505,10 +507,12 @@ func (w *tWriter) finish() (f *tFile, err error) {
if err != nil { if err != nil {
return return
} }
if !w.t.noSync {
err = w.w.Sync() err = w.w.Sync()
if err != nil { if err != nil {
return return
} }
}
f = newTableFile(w.file, uint64(w.tw.BytesLen()), iKey(w.first), iKey(w.last)) f = newTableFile(w.file, uint64(w.tw.BytesLen()), iKey(w.first), iKey(w.last))
return return
} }