]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Rejig some storage options
authorMatt Joiner <anacrolix@gmail.com>
Mon, 18 Jan 2021 23:47:46 +0000 (10:47 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 25 Jan 2021 04:54:37 +0000 (15:54 +1100)
storage/piece_resource.go
storage/sqlite/sqlite-storage.go
storage/sqlite/sqlite-storage_test.go

index ac518125cff8cd1773e5ccd2b33cf693b258a1f6..466d157ca088c24dda6d5fa6c2c46b01689bb2b4 100644 (file)
@@ -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)
index 117e89b6724e12adfb7d4e6067878517b88ad553..ca42253661b6eea58f1dce650b8f25f37e8c0174 100644 (file)
@@ -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}
index f732b51aea62e46feb936249cd1153b9731d7699..6da6e1254ed0b8db52bb460d86f24557d6f085af 100644 (file)
@@ -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()