diff --git a/CHANGELOG.md b/CHANGELOG.md index 581424b..119fe32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,22 +4,38 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Added + +### Changed + +### Deprecated + +### Removed + +### Fixed + + +## [0.0.2] + ### Added - Add `(*pq.Reader).Begin/Done` to reuse a read transaction for multiple reads. PR #4 - Add `Flags` to txfile.Options. PR #5 - Add support to increase a file's maxSize on open. PR #5 +- Add support to reduce the maximum file size PR #8 - Add support to pre-allocate the meta area. PR #7 +- Improved error handling and error reporting. PR #15, #16, #17, #18 - Begin returns an error if transaction is not compatible to file open mode. PR #17 - Introduce Error type to txfile and pq package. PR #17, #18 ### Changed - Refine platform dependent file syncing. PR #10 - -### Deprecated - -### Removed +- Begin methods can return an error. PR #17 ### Fixed +- Windows Fix: Add missing file unlock on close, so file can be reopened and locked. PR #11 +- Windows Fix: Can not open file because '' can not be locked right now. PR #11 +- Windows Fix: Max mmaped area must not exceed actual file size on windows. PR #11 -[Unreleased]: https://github.com/elastic/go-structform/compare/v0.0.1...HEAD +[Unreleased]: https://github.com/elastic/go-txfile/compare/v0.0.2...HEAD +[0.0.2]: https://github.com/elastic/go-txfile/compare/v0.0.1...v0.0.2 diff --git a/file.go b/file.go index 3569d68..e714df8 100644 --- a/file.go +++ b/file.go @@ -23,9 +23,9 @@ import ( "math/bits" "os" "sync" + "sync/atomic" "unsafe" - "github.com/elastic/beats/libbeat/common/atomic" "github.com/elastic/go-txfile/internal/cleanup" "github.com/elastic/go-txfile/internal/invariant" "github.com/elastic/go-txfile/internal/vfs" @@ -53,7 +53,7 @@ type File struct { meta [2]*metaPage metaActive int - txids atomic.Uint + txids uint64 } // internal contants @@ -299,7 +299,9 @@ func (f *File) beginTx(settings TxOptions) (*Tx, reason) { lock := f.locks.TxLock(settings.Readonly) lock.Lock() tracef("init new transaction (readonly: %v)\n", settings.Readonly) - tx := newTx(f, f.txids.Inc(), lock, settings) + + txid := atomic.AddUint64(&f.txids, 1) + tx := newTx(f, txid, lock, settings) tracef("begin transaction: %p (readonly: %v)\n", tx, settings.Readonly) return tx, nil } diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..96f325f --- /dev/null +++ b/go.mod @@ -0,0 +1,13 @@ +module github.com/elastic/go-txfile + +require ( + github.com/davecgh/go-spew v1.1.0 // indirect + github.com/kr/pretty v0.1.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/stretchr/testify v1.2.2 + github.com/theckman/go-flock v0.4.0 + github.com/urso/go-bin v0.0.0-20180220135811-781c575c9f0e + github.com/urso/qcgen v0.0.0-20180131103024-0b059e7db4f4 + golang.org/x/sys v0.0.0-20180802203216-0ffbfd41fbef + gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7579635 --- /dev/null +++ b/go.sum @@ -0,0 +1,21 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/theckman/go-flock v0.4.0 h1:bcqNkS4RTQBGWybG7IBimUMxnLz53Qes1+D4QaOhzJc= +github.com/theckman/go-flock v0.4.0/go.mod h1:kjuth3y9VJ2aNlkNEO99G/8lp9fMIKaGyBmh84IBheM= +github.com/urso/go-bin v0.0.0-20180220135811-781c575c9f0e h1:NiofbjIUI5gR+ybDsGSVH1fWyjSeDYiYVJHT1+kcsak= +github.com/urso/go-bin v0.0.0-20180220135811-781c575c9f0e/go.mod h1:6GfHrdWBQYjFRIznu7XuQH4lYB2w8nO4bnImVKkzPOM= +github.com/urso/qcgen v0.0.0-20180131103024-0b059e7db4f4 h1:hhA8EBThzz9PztawVTycKvfETVuBqxAQ5keFlAVtbAw= +github.com/urso/qcgen v0.0.0-20180131103024-0b059e7db4f4/go.mod h1:RspW+E2Yb7Fs7HclB2tiDaiu6Rp41BiIG4Wo1YaoXGc= +golang.org/x/sys v0.0.0-20180802203216-0ffbfd41fbef h1:ESfhYoBNk2UQGmavscFPKfwmc4ZTB2+UdQYsVw6Bq9M= +golang.org/x/sys v0.0.0-20180802203216-0ffbfd41fbef/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/tx.go b/tx.go index 3987572..7a27383 100644 --- a/tx.go +++ b/tx.go @@ -77,7 +77,7 @@ type txFlags struct { checkpoint bool // mark wal checkpoint has been applied } -func newTx(file *File, id uint, lock sync.Locker, settings TxOptions) *Tx { +func newTx(file *File, id uint64, lock sync.Locker, settings TxOptions) *Tx { meta := file.getMetaPage() invariant.Check(meta != nil, "file meta is not set")