From be18cbef8b3ca717d352526bcb7e015def6a983d Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 18 Aug 2015 08:56:07 +0200 Subject: [PATCH] Update dependencies --- Godeps/Godeps.json | 16 +++---- .../github.com/bkaradzic/go-lz4/.travis.yml | 1 + .../src/github.com/bkaradzic/go-lz4/README.md | 2 +- .../src/github.com/golang/snappy/decode.go | 10 +++-- .../github.com/golang/snappy/snappy_test.go | 10 +++++ .../github.com/syndtr/goleveldb/leveldb/db.go | 9 ++-- .../syndtr/goleveldb/leveldb/db_write.go | 2 +- .../syndtr/goleveldb/leveldb/errors/errors.go | 4 +- .../syndtr/goleveldb/leveldb/opt/options.go | 12 +++++ .../syndtr/goleveldb/leveldb/session_util.go | 8 ++-- .../goleveldb/leveldb/storage/file_storage.go | 45 +++++++++++-------- .../leveldb/storage/file_storage_unix.go | 12 ++++- .../goleveldb/leveldb/storage/storage.go | 16 +++++++ .../syndtr/goleveldb/leveldb/table.go | 10 +++-- 14 files changed, 115 insertions(+), 42 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 33fb3b19..65aa24ad 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1,13 +1,13 @@ { "ImportPath": "github.com/syncthing/syncthing", - "GoVersion": "devel", + "GoVersion": "go1.5rc1", "Packages": [ "./cmd/..." ], "Deps": [ { "ImportPath": "github.com/bkaradzic/go-lz4", - "Rev": "4f7c2045dbd17b802370e2e6022200468abf02ba" + "Rev": "d47913b1412890a261b9fefae99d72d2bf5aebd8" }, { "ImportPath": "github.com/calmh/du", @@ -27,7 +27,7 @@ }, { "ImportPath": "github.com/golang/snappy", - "Rev": "0c7f8a7704bfec561913f4df52c832f094ef56f0" + "Rev": "723cc1e459b8eea2dea4583200fd60757d40097a" }, { "ImportPath": "github.com/juju/ratelimit", @@ -43,7 +43,7 @@ }, { "ImportPath": "github.com/syndtr/goleveldb/leveldb", - "Rev": "183614d6b32571e867df4cf086f5480ceefbdfac" + "Rev": "b743d92d3215f11c9b5ce8830fafe1f16786adf4" }, { "ImportPath": "github.com/thejerf/suture", @@ -63,19 +63,19 @@ }, { "ImportPath": "golang.org/x/crypto/bcrypt", - "Rev": "7d5b0be716b9d6d4269afdaae10032bb296d3cdf" + "Rev": "c16968172724c0b5e8bdc6ad33f5a79443a44cd7" }, { "ImportPath": "golang.org/x/crypto/blowfish", - "Rev": "7d5b0be716b9d6d4269afdaae10032bb296d3cdf" + "Rev": "c16968172724c0b5e8bdc6ad33f5a79443a44cd7" }, { "ImportPath": "golang.org/x/text/transform", - "Rev": "3eb7007b740b66a77f3c85f2660a0240b284115a" + "Rev": "723492b65e225eafcba054e76ba18bb9c5ac1ea2" }, { "ImportPath": "golang.org/x/text/unicode/norm", - "Rev": "3eb7007b740b66a77f3c85f2660a0240b284115a" + "Rev": "723492b65e225eafcba054e76ba18bb9c5ac1ea2" } ] } diff --git a/Godeps/_workspace/src/github.com/bkaradzic/go-lz4/.travis.yml b/Godeps/_workspace/src/github.com/bkaradzic/go-lz4/.travis.yml index cdc7fb7d..0c10d5f7 100644 --- a/Godeps/_workspace/src/github.com/bkaradzic/go-lz4/.travis.yml +++ b/Godeps/_workspace/src/github.com/bkaradzic/go-lz4/.travis.yml @@ -4,4 +4,5 @@ go: - 1.1 - 1.2 - 1.3 + - 1.4 - tip diff --git a/Godeps/_workspace/src/github.com/bkaradzic/go-lz4/README.md b/Godeps/_workspace/src/github.com/bkaradzic/go-lz4/README.md index 3e689d5f..ef3fe1e1 100644 --- a/Godeps/_workspace/src/github.com/bkaradzic/go-lz4/README.md +++ b/Godeps/_workspace/src/github.com/bkaradzic/go-lz4/README.md @@ -4,7 +4,7 @@ go-lz4 go-lz4 is port of LZ4 lossless compression algorithm to Go. The original C code is located at: -https://code.google.com/p/lz4/ +https://github.com/Cyan4973/lz4 Status ------ diff --git a/Godeps/_workspace/src/github.com/golang/snappy/decode.go b/Godeps/_workspace/src/github.com/golang/snappy/decode.go index a72edf0d..e7f1259a 100644 --- a/Godeps/_workspace/src/github.com/golang/snappy/decode.go +++ b/Godeps/_workspace/src/github.com/golang/snappy/decode.go @@ -13,6 +13,8 @@ import ( var ( // ErrCorrupt reports that the input is invalid. 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 = errors.New("snappy: unsupported input") ) @@ -27,11 +29,13 @@ func DecodedLen(src []byte) (int, error) { // that the length header occupied. func decodedLen(src []byte) (blockLen, headerLen int, err error) { v, n := binary.Uvarint(src) - if n <= 0 { + if n <= 0 || v > 0xffffffff { 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 } diff --git a/Godeps/_workspace/src/github.com/golang/snappy/snappy_test.go b/Godeps/_workspace/src/github.com/golang/snappy/snappy_test.go index d6a03973..f8188f11 100644 --- a/Godeps/_workspace/src/github.com/golang/snappy/snappy_test.go +++ b/Godeps/_workspace/src/github.com/golang/snappy/snappy_test.go @@ -86,6 +86,16 @@ func TestInvalidVarint(t *testing.T) { if _, err := Decode(nil, data); err != ErrCorrupt { 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 { diff --git a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/db.go b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/db.go index def86bc1..88a3e0db 100644 --- a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/db.go +++ b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/db.go @@ -291,6 +291,7 @@ func recoverTable(s *session, o *opt.Options) error { // We will drop corrupted table. strict = o.GetStrict(opt.StrictRecovery) + noSync = o.GetNoSync() rec = &sessionRecord{} bpool = util.NewBufferPool(o.GetBlockSize() + 5) @@ -328,9 +329,11 @@ func recoverTable(s *session, o *opt.Options) error { if err != nil { return } - err = writer.Sync() - if err != nil { - return + if !noSync { + err = writer.Sync() + if err != nil { + return + } } size = int64(tw.BytesLen()) return diff --git a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/db_write.go b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/db_write.go index 176ee893..0c395653 100644 --- a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/db_write.go +++ b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/db_write.go @@ -129,7 +129,7 @@ func (db *DB) Write(b *Batch, wo *opt.WriteOptions) (err error) { return } - b.init(wo.GetSync()) + b.init(wo.GetSync() && !db.s.o.GetNoSync()) // The write happen synchronously. select { diff --git a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/errors/errors.go b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/errors/errors.go index 84b5d6b7..dacbf131 100644 --- a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/errors/errors.go +++ b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/errors/errors.go @@ -52,12 +52,14 @@ func IsCorrupted(err error) bool { switch err.(type) { case *ErrCorrupted: return true + case *storage.ErrCorrupted: + return true } return false } // ErrMissingFiles is the type that indicating a corruption due to missing -// files. +// files. ErrMissingFiles always wrapped with ErrCorrupted. type ErrMissingFiles struct { Files []*storage.FileInfo } diff --git a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/opt/options.go b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/opt/options.go index f9a309da..7b5d8b9b 100644 --- a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/opt/options.go +++ b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/opt/options.go @@ -308,6 +308,11 @@ type Options struct { // The default is 2. MaxMemCompationLevel int + // NoSync allows completely disable fsync. + // + // The default is false. + NoSync bool + // NumLevel defines number of database level. The level shouldn't changed // between opens, or the database will panic. // @@ -546,6 +551,13 @@ func (o *Options) GetMaxMemCompationLevel() int { return level } +func (o *Options) GetNoSync() bool { + if o == nil { + return false + } + return o.NoSync +} + func (o *Options) GetNumLevel() int { if o == nil || o.NumLevel <= 0 { return DefaultNumLevel diff --git a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/session_util.go b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/session_util.go index 399a788b..7ec9f86f 100644 --- a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/session_util.go +++ b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/session_util.go @@ -240,9 +240,11 @@ func (s *session) flushManifest(rec *sessionRecord) (err error) { if err != nil { return } - err = s.manifestWriter.Sync() - if err != nil { - return + if !s.o.GetNoSync() { + err = s.manifestWriter.Sync() + if err != nil { + return + } } s.recordCommited(rec) return diff --git a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/storage/file_storage.go b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/storage/file_storage.go index 46cc9d07..420b2773 100644 --- a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/storage/file_storage.go +++ b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/storage/file_storage.go @@ -243,7 +243,10 @@ func (fs *fileStorage) GetManifest() (f File, err error) { rem = append(rem, fn) } 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() { fs.log(fmt.Sprintf("skipping %s: obsolete", fn)) @@ -326,8 +329,7 @@ func (fs *fileStorage) Close() error { runtime.SetFinalizer(fs, nil) if fs.open > 0 { - fs.log(fmt.Sprintf("refuse to close, %d files still open", fs.open)) - return fmt.Errorf("leveldb/storage: cannot close, %d files still open", fs.open) + fs.log(fmt.Sprintf("close: warning, %d files still open", fs.open)) } fs.open = -1 e1 := fs.logw.Close() @@ -505,30 +507,37 @@ func (f *file) path() string { return filepath.Join(f.fs.path, f.name()) } -func (f *file) parse(name string) bool { - var num uint64 +func fsParseName(name string) *FileInfo { + fi := &FileInfo{} var tail string - _, err := fmt.Sscanf(name, "%d.%s", &num, &tail) + _, err := fmt.Sscanf(name, "%d.%s", &fi.Num, &tail) if err == nil { switch tail { case "log": - f.t = TypeJournal + fi.Type = TypeJournal case "ldb", "sst": - f.t = TypeTable + fi.Type = TypeTable case "tmp": - f.t = TypeTemp + fi.Type = TypeTemp default: - return false + return nil } - f.num = num - return true + return fi } - n, _ := fmt.Sscanf(name, "MANIFEST-%d%s", &num, &tail) + n, _ := fmt.Sscanf(name, "MANIFEST-%d%s", &fi.Num, &tail) if n == 1 { - f.t = TypeManifest - f.num = num - return true + fi.Type = TypeManifest + return fi } - - return false + return nil +} + +func (f *file) parse(name string) bool { + fi := fsParseName(name) + if fi == nil { + return false + } + f.t = fi.Type + f.num = fi.Num + return true } diff --git a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/storage/file_storage_unix.go b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/storage/file_storage_unix.go index d0a604b7..6eb32742 100644 --- a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/storage/file_storage_unix.go +++ b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/storage/file_storage_unix.go @@ -50,13 +50,23 @@ func rename(oldpath, newpath string) error { 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 { f, err := os.Open(name) if err != nil { return err } defer f.Close() - if err := f.Sync(); err != nil { + if err := f.Sync(); err != nil && !isErrInvalid(err) { return err } return nil diff --git a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/storage/storage.go b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/storage/storage.go index 85dd70b0..a4e037ca 100644 --- a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/storage/storage.go +++ b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/storage/storage.go @@ -46,6 +46,22 @@ var ( 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. type Syncer interface { // Sync commits the current contents of the file to stable storage. diff --git a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/table.go b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/table.go index db386f3b..37be47ae 100644 --- a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/table.go +++ b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/table.go @@ -287,6 +287,7 @@ func (x *tFilesSortByNum) Less(i, j int) bool { // Table operations. type tOps struct { s *session + noSync bool cache *cache.Cache bcache *cache.Cache bpool *util.BufferPool @@ -458,6 +459,7 @@ func newTableOps(s *session) *tOps { } return &tOps{ s: s, + noSync: s.o.GetNoSync(), cache: cache.NewCache(cacher), bcache: bcache, bpool: bpool, @@ -505,9 +507,11 @@ func (w *tWriter) finish() (f *tFile, err error) { if err != nil { return } - err = w.w.Sync() - if err != nil { - return + if !w.t.noSync { + err = w.w.Sync() + if err != nil { + return + } } f = newTableFile(w.file, uint64(w.tw.BytesLen()), iKey(w.first), iKey(w.last)) return