]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Remove sqlite piece-resource storage
authorMatt Joiner <anacrolix@gmail.com>
Mon, 21 Jun 2021 02:29:37 +0000 (12:29 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 21 Jun 2021 02:29:37 +0000 (12:29 +1000)
storage/sqlite/sqlite-storage.go
storage/sqlite/sqlite-storage_test.go
test/transfer_test.go

index 9eb97e85abceac600b67a41f251c8737be19e78f..0d6cb2d73bf30d27e3f602d4b91b78b299645196 100644 (file)
@@ -234,75 +234,6 @@ type NewPiecesStorageOpts struct {
        StorageOpts func(*storage.ResourcePiecesOpts)
 }
 
-// A convenience function that creates a connection pool, resource provider, and a pieces storage
-// ClientImpl and returns them all with a Close attached.
-func NewPiecesStorage(opts NewPiecesStorageOpts) (_ storage.ClientImplCloser, err error) {
-       conns, err := NewPool(opts.NewPoolOpts)
-       if err != nil {
-               return
-       }
-       if opts.PageSize == 0 {
-               opts.PageSize = 1 << 14
-       }
-       err = initPoolDatabase(conns, opts.InitDbOpts)
-       if err != nil {
-               conns.Close()
-               return
-       }
-       if opts.SetJournalMode == "" && !opts.Memory {
-               opts.SetJournalMode = "wal"
-       }
-       err = initPoolConns(context.TODO(), conns, opts.InitConnOpts)
-       if err != nil {
-               conns.Close()
-               return
-       }
-       provOpts := ProviderOpts{
-               BatchWrites: conns.NumConns() > 1,
-       }
-       if f := opts.ProvOpts; f != nil {
-               f(&provOpts)
-       }
-       prov, err := NewProvider(conns, provOpts)
-       if err != nil {
-               conns.Close()
-               return
-       }
-       var (
-               journalMode string
-       )
-       withPoolConn(conns, func(c conn) {
-               err = sqlitex.Exec(c, "pragma journal_mode", func(stmt *sqlite.Stmt) error {
-                       journalMode = stmt.ColumnText(0)
-                       return nil
-               })
-       })
-       if err != nil {
-               err = fmt.Errorf("getting journal mode: %w", err)
-               prov.Close()
-               return
-       }
-       if journalMode == "" {
-               err = errors.New("didn't get journal mode")
-               prov.Close()
-               return
-       }
-       storageOpts := storage.ResourcePiecesOpts{
-               NoSizedPuts: journalMode != "wal" || conns.NumConns() == 1,
-       }
-       if f := opts.StorageOpts; f != nil {
-               f(&storageOpts)
-       }
-       store := storage.NewResourcePiecesOpts(prov, storageOpts)
-       return struct {
-               storage.ClientImpl
-               io.Closer
-       }{
-               store,
-               prov,
-       }, nil
-}
-
 type NewPoolOpts struct {
        NewConnOpts
        InitConnOpts
index 1fe1314ea3e1cc442f5045801864d2dfb2463701..7d80309f5187040ace75ce36c3af75ee1ad9a50c 100644 (file)
@@ -147,24 +147,6 @@ func BenchmarkMarkComplete(b *testing.B) {
                                        })
                                }
                        })
-                       b.Run("ResourcePieces", func(b *testing.B) {
-                               for _, batchWrites := range []bool{false, true} {
-                                       b.Run(fmt.Sprintf("BatchWrites=%v", batchWrites), func(b *testing.B) {
-                                               var opts NewPiecesStorageOpts
-                                               opts.Path = filepath.Join(b.TempDir(), "storage.db")
-                                               //b.Logf("storage db path: %q", dbPath)
-                                               opts.Capacity = capacity
-                                               opts.Memory = memory
-                                               opts.ProvOpts = func(opts *ProviderOpts) {
-                                                       opts.BatchWrites = batchWrites
-                                               }
-                                               ci, err := NewPiecesStorage(opts)
-                                               c.Assert(err, qt.IsNil)
-                                               defer ci.Close()
-                                               runBench(b, ci)
-                                       })
-                               }
-                       })
                })
        }
 }
index b3187c0bec30cef658bba492560eda39d17552f1..0b83ec8bcaba57aa524e18d25c26bf5825423700 100644 (file)
@@ -288,36 +288,12 @@ func TestClientTransferSmallCacheDefaultReadahead(t *testing.T) {
        testClientTransferSmallCache(t, false, -1)
 }
 
-func sqliteClientStorageFactory(optsMaker func(dataDir string) sqliteStorage.NewPiecesStorageOpts) storageFactory {
-       return func(dataDir string) storage.ClientImplCloser {
-               opts := optsMaker(dataDir)
-               //log.Printf("opening sqlite db: %#v", opts)
-               ret, err := sqliteStorage.NewPiecesStorage(opts)
-               if err != nil {
-                       panic(err)
-               }
-               return ret
-       }
-}
-
 type leecherStorageTestCase struct {
        name       string
        f          storageFactory
        gomaxprocs int
 }
 
-func sqliteLeecherStorageTestCase(numConns int) leecherStorageTestCase {
-       return leecherStorageTestCase{
-               fmt.Sprintf("SqliteFile,NumConns=%v", numConns),
-               sqliteClientStorageFactory(func(dataDir string) (opts sqliteStorage.NewPiecesStorageOpts) {
-                       opts.Path = filepath.Join(dataDir, "sqlite.db")
-                       opts.NumConns = numConns
-                       return
-               }),
-               numConns,
-       }
-}
-
 func TestClientTransferVarious(t *testing.T) {
        // Leecher storage
        for _, ls := range []leecherStorageTestCase{
@@ -333,14 +309,6 @@ func TestClientTransferVarious(t *testing.T) {
                        }
                        return cl
                }, 0},
-               sqliteLeecherStorageTestCase(1),
-               sqliteLeecherStorageTestCase(2),
-               // This should use a number of connections equal to the number of CPUs
-               sqliteLeecherStorageTestCase(0),
-               {"SqliteMemory", sqliteClientStorageFactory(func(dataDir string) (opts sqliteStorage.NewPiecesStorageOpts) {
-                       opts.Memory = true
-                       return
-               }), 0},
        } {
                t.Run(fmt.Sprintf("LeecherStorage=%s", ls.name), func(t *testing.T) {
                        // Seeder storage