From: Matt Joiner Date: Mon, 18 Jan 2021 23:47:46 +0000 (+1100) Subject: Rejig some storage options X-Git-Tag: v1.22.0~19 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=b69bb34eaf14c7d82d91f174589b91f060ec108d;p=btrtrc.git Rejig some storage options --- diff --git a/storage/piece_resource.go b/storage/piece_resource.go index ac518125..466d157c 100644 --- a/storage/piece_resource.go +++ b/storage/piece_resource.go @@ -20,7 +20,7 @@ type piecePerResource struct { type ResourcePiecesOpts struct { LeaveIncompleteChunks bool - AllowSizedPuts bool + NoSizedPuts bool } func NewResourcePieces(p PieceProvider) ClientImpl { @@ -119,7 +119,7 @@ func (s piecePerResourcePiece) MarkComplete() error { }() completedInstance := s.completed() err := func() error { - if sp, ok := completedInstance.(SizedPutter); ok && s.opts.AllowSizedPuts { + if sp, ok := completedInstance.(SizedPutter); ok && !s.opts.NoSizedPuts { return sp.PutSized(r, s.mp.Length()) } else { return completedInstance.Put(r) diff --git a/storage/sqlite/sqlite-storage.go b/storage/sqlite/sqlite-storage.go index 117e89b6..ca422536 100644 --- a/storage/sqlite/sqlite-storage.go +++ b/storage/sqlite/sqlite-storage.go @@ -181,9 +181,9 @@ type NewPoolOpts struct { Memory bool NumConns int // Forces WAL, disables shared caching. - ConcurrentBlobReads bool - DontInitSchema bool - PageSize int + NoConcurrentBlobReads bool + DontInitSchema bool + PageSize int // If non-zero, overrides the existing setting. Capacity int64 } @@ -194,8 +194,8 @@ type NewPoolOpts struct { type ProviderOpts struct { NumConns int // Concurrent blob reads require WAL. - ConcurrentBlobRead bool - BatchWrites bool + NoConcurrentBlobReads bool + BatchWrites bool } // Remove any capacity limits. @@ -216,7 +216,7 @@ func NewPool(opts NewPoolOpts) (_ ConnPool, _ ProviderOpts, err error) { opts.Path = ":memory:" } values := make(url.Values) - if !opts.ConcurrentBlobReads { + if opts.NoConcurrentBlobReads || opts.Memory { values.Add("cache", "shared") } path := fmt.Sprintf("file:%s?%s", opts.Path, values.Encode()) @@ -255,9 +255,9 @@ func NewPool(opts NewPoolOpts) (_ ConnPool, _ ProviderOpts, err error) { } } return conns, ProviderOpts{ - NumConns: opts.NumConns, - ConcurrentBlobRead: opts.ConcurrentBlobReads, - BatchWrites: true, + NumConns: opts.NumConns, + NoConcurrentBlobReads: opts.NoConcurrentBlobReads || opts.Memory, + BatchWrites: true, }, nil } @@ -286,8 +286,9 @@ func (me *poolFromConn) Close() error { // Needs the ConnPool size so it can initialize all the connections with pragmas. Takes ownership of // the ConnPool (since it has to initialize all the connections anyway). func NewProvider(pool ConnPool, opts ProviderOpts) (_ *provider, err error) { - _, err = initPoolConns(context.TODO(), pool, opts.NumConns, true) + _, err = initPoolConns(context.TODO(), pool, opts.NumConns, !opts.NoConcurrentBlobReads) if err != nil { + err = fmt.Errorf("initing pool conns: %w", err) return } prov := &provider{pool: pool, opts: opts} diff --git a/storage/sqlite/sqlite-storage_test.go b/storage/sqlite/sqlite-storage_test.go index f732b51a..6da6e125 100644 --- a/storage/sqlite/sqlite-storage_test.go +++ b/storage/sqlite/sqlite-storage_test.go @@ -10,6 +10,7 @@ import ( "testing" _ "github.com/anacrolix/envpprof" + "github.com/anacrolix/torrent/storage" test_storage "github.com/anacrolix/torrent/storage/test" qt "github.com/frankban/quicktest" "github.com/stretchr/testify/assert" @@ -40,8 +41,7 @@ func TestTextBlobSize(t *testing.T) { func TestSimultaneousIncrementalBlob(t *testing.T) { _, p := newConnsAndProv(t, NewPoolOpts{ - NumConns: 3, - ConcurrentBlobReads: true, + NumConns: 3, }) a, err := p.NewInstance("a") require.NoError(t, err) @@ -77,15 +77,18 @@ func BenchmarkMarkComplete(b *testing.B) { //b.Logf("storage db path: %q", dbPath) ci, err := NewPiecesStorage(NewPiecesStorageOpts{ NewPoolOpts: NewPoolOpts{ - Path: dbPath, - //Capacity: 4*pieceSize - 1, - ConcurrentBlobReads: false, - PageSize: 1 << 14, - Memory: memory, + Path: dbPath, + Capacity: 4*pieceSize - 1, + NoConcurrentBlobReads: false, + PageSize: 1 << 14, + Memory: memory, }, ProvOpts: func(opts *ProviderOpts) { opts.BatchWrites = true }, + ResourcePiecesOpts: storage.ResourcePiecesOpts{ + NoSizedPuts: false || memory, + }, }) c.Assert(err, qt.IsNil) defer ci.Close()