From: Matt Joiner Date: Mon, 21 Jun 2021 02:29:37 +0000 (+1000) Subject: Remove sqlite piece-resource storage X-Git-Tag: v1.29.0~27 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=5fc42e8105407bc23a840394a5107b494b56b6cd;p=btrtrc.git Remove sqlite piece-resource storage --- diff --git a/storage/sqlite/sqlite-storage.go b/storage/sqlite/sqlite-storage.go index 9eb97e85..0d6cb2d7 100644 --- a/storage/sqlite/sqlite-storage.go +++ b/storage/sqlite/sqlite-storage.go @@ -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 diff --git a/storage/sqlite/sqlite-storage_test.go b/storage/sqlite/sqlite-storage_test.go index 1fe1314e..7d80309f 100644 --- a/storage/sqlite/sqlite-storage_test.go +++ b/storage/sqlite/sqlite-storage_test.go @@ -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) - }) - } - }) }) } } diff --git a/test/transfer_test.go b/test/transfer_test.go index b3187c0b..0b83ec8b 100644 --- a/test/transfer_test.go +++ b/test/transfer_test.go @@ -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