make moveTo a private method
This commit is contained in:
parent
5cf6fdf81d
commit
94509968a0
@ -222,13 +222,15 @@ func (b *Blockstore) unlockMove(state int) {
|
|||||||
b.moveMx.Unlock()
|
b.moveMx.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MoveTo implements the BlockstoreMover trait
|
// moveTo moves the blockstore to path, and creates a symlink from the current path
|
||||||
func (b *Blockstore) MoveTo(path string, filter func(cid.Cid) bool) error {
|
// to the new path; the old blockstore is deleted.
|
||||||
if err := b.access(); err != nil {
|
// If path is empty, then a new path adjacent to the current path is created
|
||||||
return err
|
// automatically.
|
||||||
}
|
// The blockstore must accept new writes during the move and ensure that these
|
||||||
defer b.viewers.Done()
|
// are persisted to the new blockstore; if a failure occurs aboring the move,
|
||||||
|
// then they must be peristed to the old blockstore.
|
||||||
|
// In short, the blockstore must not lose data from new writes during the move.
|
||||||
|
func (b *Blockstore) moveTo(path string) error {
|
||||||
// this inlines moveLock/moveUnlock for the initial state check to prevent a second move
|
// this inlines moveLock/moveUnlock for the initial state check to prevent a second move
|
||||||
// while one is in progress without clobbering state
|
// while one is in progress without clobbering state
|
||||||
b.moveMx.Lock()
|
b.moveMx.Lock()
|
||||||
@ -293,7 +295,7 @@ func (b *Blockstore) MoveTo(path string, filter func(cid.Cid) bool) error {
|
|||||||
b.unlockMove(moveStateMoving)
|
b.unlockMove(moveStateMoving)
|
||||||
|
|
||||||
log.Info("copying blockstore")
|
log.Info("copying blockstore")
|
||||||
err = b.doCopy(b.db, b.db2, filter)
|
err = b.doCopy(b.db, b.db2, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error moving badger blockstore to %s: %w", path, err)
|
return fmt.Errorf("error moving badger blockstore to %s: %w", path, err)
|
||||||
}
|
}
|
||||||
@ -334,6 +336,8 @@ func (b *Blockstore) MoveTo(path string, filter func(cid.Cid) bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// doCopy copies a badger blockstore to another, with an optional filter; if the filter
|
||||||
|
// is not nil, then only cids that satisfy the filter will be copied.
|
||||||
func (b *Blockstore) doCopy(from, to *badger.DB, filter func(cid.Cid) bool) error {
|
func (b *Blockstore) doCopy(from, to *badger.DB, filter func(cid.Cid) bool) error {
|
||||||
count := 0
|
count := 0
|
||||||
batch := to.NewWriteBatch()
|
batch := to.NewWriteBatch()
|
||||||
|
@ -154,7 +154,7 @@ func testMove(t *testing.T, optsF func(string) Options) {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
return db.MoveTo("", nil)
|
return db.moveTo("")
|
||||||
})
|
})
|
||||||
|
|
||||||
err = g.Wait()
|
err = g.Wait()
|
||||||
|
Loading…
Reference in New Issue
Block a user