storage/piece_resource.go | 4 ++-- storage/sqlite/sqlite-storage.go | 21 +++++++++++---------- storage/sqlite/sqlite-storage_test.go | 17 ++++++++++------- diff --git a/storage/piece_resource.go b/storage/piece_resource.go index ac518125cff8cd1773e5ccd2b33cf693b258a1f6..466d157ca088c24dda6d5fa6c2c46b01689bb2b4 100644 --- a/storage/piece_resource.go +++ b/storage/piece_resource.go @@ -20,7 +20,7 @@ } type ResourcePiecesOpts struct { LeaveIncompleteChunks bool - AllowSizedPuts bool + NoSizedPuts bool } func NewResourcePieces(p PieceProvider) ClientImpl { @@ -119,7 +119,7 @@ w.CloseWithError(err) }() 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 117e89b6724e12adfb7d4e6067878517b88ad553..ca42253661b6eea58f1dce650b8f25f37e8c0174 100644 --- a/storage/sqlite/sqlite-storage.go +++ b/storage/sqlite/sqlite-storage.go @@ -181,9 +181,9 @@ Path string 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 @@ // top-level option type. 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 @@ if opts.Memory { 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 @@ return } } 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 @@ // 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 f732b51aea62e46feb936249cd1153b9731d7699..6da6e1254ed0b8db52bb460d86f24557d6f085af 100644 --- a/storage/sqlite/sqlite-storage_test.go +++ b/storage/sqlite/sqlite-storage_test.go @@ -10,6 +10,7 @@ "sync" "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 TestSimultaneousIncrementalBlob(t *testing.T) { _, p := newConnsAndProv(t, NewPoolOpts{ - NumConns: 3, - ConcurrentBlobReads: true, + NumConns: 3, }) a, err := p.NewInstance("a") require.NoError(t, err) @@ -77,14 +77,17 @@ dbPath := filepath.Join(b.TempDir(), "storage.db") //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)