Skip to content

Commit 3b48b16

Browse files
authored
core/rawdb: drop MigrateTable (#30331)
These are the leftovers from #24028.
1 parent 65aaf52 commit 3b48b16

File tree

8 files changed

+0
-234
lines changed

8 files changed

+0
-234
lines changed

core/rawdb/database.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,6 @@ func (db *nofreezedb) ReadAncients(fn func(reader ethdb.AncientReaderOp) error)
149149
return fn(db)
150150
}
151151

152-
// MigrateTable processes the entries in a given table in sequence
153-
// converting them to a new format if they're of an old format.
154-
func (db *nofreezedb) MigrateTable(kind string, convert convertLegacyFn) error {
155-
return errNotSupported
156-
}
157-
158152
// AncientDatadir returns an error as we don't have a backing chain freezer.
159153
func (db *nofreezedb) AncientDatadir() (string, error) {
160154
return "", errNotSupported

core/rawdb/freezer.go

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ import (
2424
"path/filepath"
2525
"sync"
2626
"sync/atomic"
27-
"time"
2827

29-
"github.com/ethereum/go-ethereum/common"
3028
"github.com/ethereum/go-ethereum/ethdb"
3129
"github.com/ethereum/go-ethereum/log"
3230
"github.com/ethereum/go-ethereum/metrics"
@@ -389,115 +387,3 @@ func (f *Freezer) repair() error {
389387
f.tail.Store(tail)
390388
return nil
391389
}
392-
393-
// convertLegacyFn takes a raw freezer entry in an older format and
394-
// returns it in the new format.
395-
type convertLegacyFn = func([]byte) ([]byte, error)
396-
397-
// MigrateTable processes the entries in a given table in sequence
398-
// converting them to a new format if they're of an old format.
399-
func (f *Freezer) MigrateTable(kind string, convert convertLegacyFn) error {
400-
if f.readonly {
401-
return errReadOnly
402-
}
403-
f.writeLock.Lock()
404-
defer f.writeLock.Unlock()
405-
406-
table, ok := f.tables[kind]
407-
if !ok {
408-
return errUnknownTable
409-
}
410-
// forEach iterates every entry in the table serially and in order, calling `fn`
411-
// with the item as argument. If `fn` returns an error the iteration stops
412-
// and that error will be returned.
413-
forEach := func(t *freezerTable, offset uint64, fn func(uint64, []byte) error) error {
414-
var (
415-
items = t.items.Load()
416-
batchSize = uint64(1024)
417-
maxBytes = uint64(1024 * 1024)
418-
)
419-
for i := offset; i < items; {
420-
if i+batchSize > items {
421-
batchSize = items - i
422-
}
423-
data, err := t.RetrieveItems(i, batchSize, maxBytes)
424-
if err != nil {
425-
return err
426-
}
427-
for j, item := range data {
428-
if err := fn(i+uint64(j), item); err != nil {
429-
return err
430-
}
431-
}
432-
i += uint64(len(data))
433-
}
434-
return nil
435-
}
436-
// TODO(s1na): This is a sanity-check since as of now no process does tail-deletion. But the migration
437-
// process assumes no deletion at tail and needs to be modified to account for that.
438-
if table.itemOffset.Load() > 0 || table.itemHidden.Load() > 0 {
439-
return errors.New("migration not supported for tail-deleted freezers")
440-
}
441-
ancientsPath := filepath.Dir(table.index.Name())
442-
// Set up new dir for the migrated table, the content of which
443-
// we'll at the end move over to the ancients dir.
444-
migrationPath := filepath.Join(ancientsPath, "migration")
445-
newTable, err := newFreezerTable(migrationPath, kind, table.noCompression, false)
446-
if err != nil {
447-
return err
448-
}
449-
var (
450-
batch = newTable.newBatch()
451-
out []byte
452-
start = time.Now()
453-
logged = time.Now()
454-
offset = newTable.items.Load()
455-
)
456-
if offset > 0 {
457-
log.Info("found previous migration attempt", "migrated", offset)
458-
}
459-
// Iterate through entries and transform them
460-
if err := forEach(table, offset, func(i uint64, blob []byte) error {
461-
if i%10000 == 0 && time.Since(logged) > 16*time.Second {
462-
log.Info("Processing legacy elements", "count", i, "elapsed", common.PrettyDuration(time.Since(start)))
463-
logged = time.Now()
464-
}
465-
out, err = convert(blob)
466-
if err != nil {
467-
return err
468-
}
469-
if err := batch.AppendRaw(i, out); err != nil {
470-
return err
471-
}
472-
return nil
473-
}); err != nil {
474-
return err
475-
}
476-
if err := batch.commit(); err != nil {
477-
return err
478-
}
479-
log.Info("Replacing old table files with migrated ones", "elapsed", common.PrettyDuration(time.Since(start)))
480-
// Release and delete old table files. Note this won't
481-
// delete the index file.
482-
table.releaseFilesAfter(0, true)
483-
484-
if err := newTable.Close(); err != nil {
485-
return err
486-
}
487-
files, err := os.ReadDir(migrationPath)
488-
if err != nil {
489-
return err
490-
}
491-
// Move migrated files to ancients dir.
492-
for _, f := range files {
493-
// This will replace the old index file as a side-effect.
494-
if err := os.Rename(filepath.Join(migrationPath, f.Name()), filepath.Join(ancientsPath, f.Name())); err != nil {
495-
return err
496-
}
497-
}
498-
// Delete by now empty dir.
499-
if err := os.Remove(migrationPath); err != nil {
500-
return err
501-
}
502-
return nil
503-
}

core/rawdb/freezer_memory.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,6 @@ func (f *MemoryFreezer) Sync() error {
394394
return nil
395395
}
396396

397-
// MigrateTable processes and migrates entries of a given table to a new format.
398-
// The second argument is a function that takes a raw entry and returns it
399-
// in the newest format.
400-
func (f *MemoryFreezer) MigrateTable(string, func([]byte) ([]byte, error)) error {
401-
return errors.New("not implemented")
402-
}
403-
404397
// Close releases all the sources held by the memory freezer. It will panic if
405398
// any following invocation is made to a closed freezer.
406399
func (f *MemoryFreezer) Close() error {

core/rawdb/freezer_resettable.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,6 @@ func (f *resettableFreezer) Sync() error {
202202
return f.freezer.Sync()
203203
}
204204

205-
// MigrateTable processes the entries in a given table in sequence
206-
// converting them to a new format if they're of an old format.
207-
func (f *resettableFreezer) MigrateTable(kind string, convert convertLegacyFn) error {
208-
f.lock.RLock()
209-
defer f.lock.RUnlock()
210-
211-
return f.freezer.MigrateTable(kind, convert)
212-
}
213-
214205
// cleanup removes the directory located in the specified path
215206
// has the name with deletion marker suffix.
216207
func cleanup(path string) error {

core/rawdb/freezer_test.go

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import (
2222
"fmt"
2323
"math/big"
2424
"math/rand"
25-
"os"
26-
"path/filepath"
2725
"sync"
2826
"testing"
2927

@@ -379,87 +377,6 @@ func checkAncientCount(t *testing.T, f *Freezer, kind string, n uint64) {
379377
}
380378
}
381379

382-
func TestRenameWindows(t *testing.T) {
383-
var (
384-
fname = "file.bin"
385-
fname2 = "file2.bin"
386-
data = []byte{1, 2, 3, 4}
387-
data2 = []byte{2, 3, 4, 5}
388-
data3 = []byte{3, 5, 6, 7}
389-
dataLen = 4
390-
)
391-
392-
// Create 2 temp dirs
393-
dir1 := t.TempDir()
394-
dir2 := t.TempDir()
395-
396-
// Create file in dir1 and fill with data
397-
f, err := os.Create(filepath.Join(dir1, fname))
398-
if err != nil {
399-
t.Fatal(err)
400-
}
401-
f2, err := os.Create(filepath.Join(dir1, fname2))
402-
if err != nil {
403-
t.Fatal(err)
404-
}
405-
f3, err := os.Create(filepath.Join(dir2, fname2))
406-
if err != nil {
407-
t.Fatal(err)
408-
}
409-
if _, err := f.Write(data); err != nil {
410-
t.Fatal(err)
411-
}
412-
if _, err := f2.Write(data2); err != nil {
413-
t.Fatal(err)
414-
}
415-
if _, err := f3.Write(data3); err != nil {
416-
t.Fatal(err)
417-
}
418-
if err := f.Close(); err != nil {
419-
t.Fatal(err)
420-
}
421-
if err := f2.Close(); err != nil {
422-
t.Fatal(err)
423-
}
424-
if err := f3.Close(); err != nil {
425-
t.Fatal(err)
426-
}
427-
if err := os.Rename(f.Name(), filepath.Join(dir2, fname)); err != nil {
428-
t.Fatal(err)
429-
}
430-
if err := os.Rename(f2.Name(), filepath.Join(dir2, fname2)); err != nil {
431-
t.Fatal(err)
432-
}
433-
434-
// Check file contents
435-
f, err = os.Open(filepath.Join(dir2, fname))
436-
if err != nil {
437-
t.Fatal(err)
438-
}
439-
defer f.Close()
440-
defer os.Remove(f.Name())
441-
buf := make([]byte, dataLen)
442-
if _, err := f.Read(buf); err != nil {
443-
t.Fatal(err)
444-
}
445-
if !bytes.Equal(buf, data) {
446-
t.Errorf("unexpected file contents. Got %v\n", buf)
447-
}
448-
449-
f, err = os.Open(filepath.Join(dir2, fname2))
450-
if err != nil {
451-
t.Fatal(err)
452-
}
453-
defer f.Close()
454-
defer os.Remove(f.Name())
455-
if _, err := f.Read(buf); err != nil {
456-
t.Fatal(err)
457-
}
458-
if !bytes.Equal(buf, data2) {
459-
t.Errorf("unexpected file contents. Got %v\n", buf)
460-
}
461-
}
462-
463380
func TestFreezerCloseSync(t *testing.T) {
464381
t.Parallel()
465382
f, _ := newFreezerForTesting(t, map[string]bool{"a": true, "b": true})

core/rawdb/table.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,6 @@ func (t *table) Sync() error {
113113
return t.db.Sync()
114114
}
115115

116-
// MigrateTable processes the entries in a given table in sequence
117-
// converting them to a new format if they're of an old format.
118-
func (t *table) MigrateTable(kind string, convert convertLegacyFn) error {
119-
return t.db.MigrateTable(kind, convert)
120-
}
121-
122116
// AncientDatadir returns the ancient datadir of the underlying database.
123117
func (t *table) AncientDatadir() (string, error) {
124118
return t.db.AncientDatadir()

ethdb/database.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,6 @@ type AncientWriter interface {
124124

125125
// Sync flushes all in-memory ancient store data to disk.
126126
Sync() error
127-
128-
// MigrateTable processes and migrates entries of a given table to a new format.
129-
// The second argument is a function that takes a raw entry and returns it
130-
// in the newest format.
131-
MigrateTable(string, func([]byte) ([]byte, error)) error
132127
}
133128

134129
// AncientWriteOp is given to the function argument of ModifyAncients.

ethdb/remotedb/remotedb.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ func (db *Database) Sync() error {
110110
return nil
111111
}
112112

113-
func (db *Database) MigrateTable(s string, f func([]byte) ([]byte, error)) error {
114-
panic("not supported")
115-
}
116-
117113
func (db *Database) NewBatch() ethdb.Batch {
118114
panic("not supported")
119115
}

0 commit comments

Comments
 (0)