Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

downloader: remove deprecated manual fsync #10064

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 1 addition & 24 deletions erigon-lib/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,23 +808,6 @@ type seedHash struct {
reported bool
}

// fsyncDB - to not loose results of downloading on power-off
// See `erigon-lib/downloader/mdbx_piece_completion.go` for explanation
func (d *Downloader) fsyncDB() error {
return d.db.Update(d.ctx, func(tx kv.RwTx) error {
v, err := tx.GetOne(kv.BittorrentInfo, []byte("_fsync"))
if err != nil {
return err
}
if len(v) == 0 || v[0] == 0 {
v = []byte{1}
} else {
v = []byte{0}
}
return tx.Put(kv.BittorrentInfo, []byte("_fsync"), v)
})
}

func (d *Downloader) mainLoop(silent bool) error {
if d.webseedsDiscover {
// CornerCase: no peers -> no anoncments to trackers -> no magnetlink resolution (but magnetlink has filename)
Expand Down Expand Up @@ -1317,7 +1300,6 @@ func (d *Downloader) mainLoop(silent bool) error {
defer statEvery.Stop()

var m runtime.MemStats
justCompleted := true
for {
select {
case <-d.ctx.Done():
Expand All @@ -1334,11 +1316,6 @@ func (d *Downloader) mainLoop(silent bool) error {

dbg.ReadMemStats(&m)
if stats.Completed {
if justCompleted {
justCompleted = false
_ = d.fsyncDB()
}

d.logger.Info("[snapshots] Seeding",
"up", common.ByteCount(stats.UploadRate)+"/s",
"peers", stats.PeersUnique,
Expand Down Expand Up @@ -2303,7 +2280,7 @@ func (d *Downloader) VerifyData(ctx context.Context, whiteList []string, failFas
if err := g.Wait(); err != nil {
return err
}
return d.fsyncDB()
return nil
}

// AddNewSeedableFile decides what we do depending on wether we have the .seg file or the .torrent file
Expand Down
25 changes: 25 additions & 0 deletions erigon-lib/downloader/mdbx_piece_completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,28 @@ func TestMdbxPieceCompletion(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, storage.Completion{Complete: true, Ok: true}, b)
}

func TestMdbxPieceCompletionBatch(t *testing.T) {
db := memdb.NewTestDownloaderDB(t)
pc, err := NewMdbxPieceCompletionBatch(db)
require.NoError(t, err)
defer pc.Close()

pk := metainfo.PieceKey{}

b, err := pc.Get(pk)
require.NoError(t, err)
assert.False(t, b.Ok)

require.NoError(t, pc.Set(pk, false))

b, err = pc.Get(pk)
require.NoError(t, err)
assert.Equal(t, storage.Completion{Complete: false, Ok: true}, b)

require.NoError(t, pc.Set(pk, true))

b, err = pc.Get(pk)
require.NoError(t, err)
assert.Equal(t, storage.Completion{Complete: true, Ok: true}, b)
}
Loading