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

Fix error caused by double-locking repo #117

Merged
merged 3 commits into from
Jan 15, 2021
Merged
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
62 changes: 27 additions & 35 deletions ipfs-10-to-11/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/ipfs/fs-repo-migrations/ipfs-10-to-11/_vendor/github.com/ipfs/go-merkledag"

migrate "github.com/ipfs/fs-repo-migrations/go-migrate"
lock "github.com/ipfs/fs-repo-migrations/ipfs-1-to-2/repolock"
mfsr "github.com/ipfs/fs-repo-migrations/mfsr"
log "github.com/ipfs/fs-repo-migrations/stump"
)
Expand All @@ -37,14 +36,8 @@ func (m Migration) Apply(opts migrate.Options) error {
log.Verbose = opts.Verbose
log.Log("applying %s repo migration", m.Versions())

log.VLog("locking repo at %q", opts.Path)
lk, err := lock.Lock2(opts.Path)
err := setupPlugins(opts.Path)
if err != nil {
return err
}
defer lk.Close()

if err = setupPlugins(opts.Path); err != nil {
log.Error("failed to setup plugins", err.Error())
return err
}
Expand All @@ -56,7 +49,18 @@ func (m Migration) Apply(opts migrate.Options) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

if err = transferPins(ctx, opts.Path); err != nil {
if !fsrepo.IsInitialized(opts.Path) {
return fmt.Errorf("ipfs repo %q not initialized", opts.Path)
}
gammazero marked this conversation as resolved.
Show resolved Hide resolved

log.VLog(" - opening datastore at %q", opts.Path)
r, err := fsrepo.Open(opts.Path)
if err != nil {
return fmt.Errorf("cannot open datastore: %v", err)
}
defer r.Close()

if err = transferPins(ctx, r); err != nil {
log.Error("failed to transfer pins:", err.Error())
return err
}
Expand All @@ -75,21 +79,27 @@ func (m Migration) Revert(opts migrate.Options) error {
log.Verbose = opts.Verbose
log.Log("reverting migration")

lk, err := lock.Lock2(opts.Path)
err := setupPlugins(opts.Path)
if err != nil {
log.Error("failed to setup plugins", err.Error())
return err
}
defer lk.Close()

if err = setupPlugins(opts.Path); err != nil {
log.Error("failed to setup plugins", err.Error())
return err
if !fsrepo.IsInitialized(opts.Path) {
return fmt.Errorf("ipfs repo %q not initialized", opts.Path)
}

log.VLog(" - opening datastore at %q", opts.Path)
r, err := fsrepo.Open(opts.Path)
if err != nil {
return fmt.Errorf("cannot open datastore: %v", err)
}
defer r.Close()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

if err = revertPins(ctx, opts.Path); err != nil {
if err = revertPins(ctx, r); err != nil {
return err
}

Expand Down Expand Up @@ -165,20 +175,9 @@ func makeStore(r repo.Repo) (datastore.Datastore, format.DAGService, format.DAGS
return dstore, syncDs, syncInternalDag, nil
}

func transferPins(ctx context.Context, repopath string) error {
func transferPins(ctx context.Context, r repo.Repo) error {
log.Log("> Upgrading pinning to use datastore")

if !fsrepo.IsInitialized(repopath) {
return fmt.Errorf("ipfs repo %q not initialized", repopath)
}

log.VLog(" - opening datastore at %q", repopath)
r, err := fsrepo.Open(repopath)
if err != nil {
return fmt.Errorf("cannot open datastore: %v", err)
}
defer r.Close()

dstore, dserv, internalDag, err := makeStore(r)
if err != nil {
return err
Expand All @@ -195,16 +194,9 @@ func transferPins(ctx context.Context, repopath string) error {
return nil
}

func revertPins(ctx context.Context, repopath string) error {
func revertPins(ctx context.Context, r repo.Repo) error {
log.Log("> Reverting pinning to use ipld storage")

log.VLog(" - opening datastore at %q", repopath)
r, err := fsrepo.Open(repopath)
if err != nil {
return fmt.Errorf("cannot open datastore: %v", err)
}
defer r.Close()

dstore, dserv, internalDag, err := makeStore(r)
if err != nil {
return err
Expand Down