-
Notifications
You must be signed in to change notification settings - Fork 42
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
feat: add fs-repo-12-to-13 #162
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1f2b156
feat: 12 to 13
Jorropo 705da4e
feat(12-13): removing hardcoded defaults
lidel 1e495b6
fix: ignored-migrations
lidel 99fd999
test: convertQuicAddrs
lidel 3c216a5
fix: always update webtransport addresses to quic v1 in 12 to 13
Jorropo 2ca8986
test: add end to end tests for 12 to 13
Jorropo 71e9de1
test: add more tests based on review
lidel 1138244
test: require idempotency
lidel 23456c1
fix: correctly handle untransactional trailing errors
Jorropo 9455868
fix: add a uniq map to multiaddrPatternReplace to make it idempotent
Jorropo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.PHONY: build clean | ||
|
||
build: | ||
go build -mod=vendor | ||
|
||
clean: | ||
go clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Package atomicfile provides the ability to write a file with an eventual | ||
// rename on Close (using os.Rename). This allows for a file to always be in a | ||
// consistent state and never represent an in-progress write. | ||
// | ||
// NOTE: `os.Rename` may not be atomic on your operating system. | ||
package atomicfile | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// File behaves like os.File, but does an atomic rename operation at Close. | ||
type File struct { | ||
*os.File | ||
path string | ||
} | ||
|
||
// New creates a new temporary file that will replace the file at the given | ||
// path when Closed. | ||
func New(path string, mode os.FileMode) (*File, error) { | ||
f, err := ioutil.TempFile(filepath.Dir(path), filepath.Base(path)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if err := os.Chmod(f.Name(), mode); err != nil { | ||
f.Close() | ||
os.Remove(f.Name()) | ||
return nil, err | ||
} | ||
return &File{File: f, path: path}, nil | ||
} | ||
|
||
// Close the file replacing the configured file. | ||
func (f *File) Close() error { | ||
if err := f.File.Close(); err != nil { | ||
os.Remove(f.File.Name()) | ||
return err | ||
} | ||
if err := os.Rename(f.Name(), f.path); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// Abort closes the file and removes it instead of replacing the configured | ||
// file. This is useful if after starting to write to the file you decide you | ||
// don't want it anymore. | ||
func (f *File) Abort() error { | ||
if err := f.File.Close(); err != nil { | ||
os.Remove(f.Name()) | ||
return err | ||
} | ||
if err := os.Remove(f.Name()); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/ipfs/fs-repo-migrations/fs-repo-12-to-13 | ||
|
||
go 1.18 | ||
|
||
require github.com/ipfs/fs-repo-migrations/tools v0.0.0-20211209222258-754a2dcb82ea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/ipfs/fs-repo-migrations/tools v0.0.0-20211209222258-754a2dcb82ea h1:lgfk2PMrJI3bh8FflcBTXyNi3rPLqa75J7KcoUfRJmc= | ||
github.com/ipfs/fs-repo-migrations/tools v0.0.0-20211209222258-754a2dcb82ea/go.mod h1:fADeaHKxwS+SKhc52rsL0P1MUcnyK31a9AcaG0KcfY8= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package main | ||
|
||
import ( | ||
mg12 "github.com/ipfs/fs-repo-migrations/fs-repo-12-to-13/migration" | ||
migrate "github.com/ipfs/fs-repo-migrations/tools/go-migrate" | ||
) | ||
|
||
func main() { | ||
m := mg12.Migration{} | ||
migrate.Main(m) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package mg12 | ||
|
||
import ( | ||
log "github.com/ipfs/fs-repo-migrations/tools/stump" | ||
) | ||
|
||
// convertQuicAddrs converts quic multiaddrs to v1 and enables webtransport listener | ||
// https://github.com/ipfs/kubo/issues/9410 | ||
// https://github.com/ipfs/kubo/issues/9292 | ||
func convertQuicAddrs(confMap map[string]any) { | ||
// run this first to avoid having both quic and quic-v1 webtransport addresses | ||
runOnAllAddressFields(confMap, multiaddrPatternReplace(false, "/quic/webtransport", "/quic-v1/webtransport")) | ||
|
||
runOnAllAddressFields(confMap, multiaddrPatternReplace(true, "/quic", "/quic-v1", "/p2p-circuit")) | ||
runOnAllAddressFields(confMap, multiaddrPatternReplace(true, "/quic-v1", "/quic-v1/webtransport", "/p2p-circuit", "/webtransport")) | ||
} | ||
|
||
// convertRouting converts Routing.Type to implicit default | ||
// https://github.com/ipfs/kubo/pull/9475 | ||
func convertRouting(confMap map[string]any) { | ||
routing, _ := confMap["Routing"].(map[string]any) | ||
if routing == nil { | ||
log.Log("No Routing field in config, skipping") | ||
return | ||
} | ||
|
||
routers, ok := routing["Routers"].(map[string]any) | ||
if len(routers) > 0 { | ||
log.Log("Custom Routing.Routers in config, skipping") | ||
return | ||
} | ||
methods, ok := routing["Methods"].(map[string]any) | ||
if len(methods) > 0 { | ||
log.Log("Custom Routing.Methods in config, skipping") | ||
return | ||
} | ||
|
||
rType, ok := routing["Type"].(string) | ||
if !ok { | ||
log.Log("No Routing.Type field in config, skipping") | ||
return | ||
} | ||
if rType == "dht" || rType == "" { | ||
lidel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
delete(routing, "Type") | ||
} else { | ||
log.Log("Routing.Type settings is different than the old default, skipping") | ||
} | ||
} | ||
|
||
// convertReprovider converts Reprovider to implicit defaults | ||
// https://github.com/ipfs/kubo/pull/9326 | ||
func convertReprovider(confMap map[string]any) { | ||
reprovider, _ := confMap["Reprovider"].(map[string]any) | ||
if reprovider == nil { | ||
log.Log("No Reprovider field in config, skipping") | ||
return | ||
} | ||
|
||
interval, ok := reprovider["Interval"].(string) | ||
if !ok { | ||
log.Log("No Reprovider.Interval field in config, skipping") | ||
return | ||
} | ||
|
||
strategy, ok := reprovider["Strategy"].(string) | ||
if !ok { | ||
log.Log("No Reprovider.Strategy field in config, skipping") | ||
return | ||
} | ||
|
||
if interval == "12h" && strategy == "all" { | ||
delete(reprovider, "Strategy") | ||
delete(reprovider, "Interval") | ||
} else { | ||
log.Log("Reprovider settings are different than the old default, skipping") | ||
} | ||
} | ||
|
||
// convertConnMgr converts Swarm.ConnMgr to implicit defaults | ||
// https://github.com/ipfs/kubo/pull/9467 | ||
func convertConnMgr(confMap map[string]any) { | ||
swarm, _ := confMap["Swarm"].(map[string]any) | ||
if swarm == nil { | ||
log.Log("No Swarm field in config, skipping") | ||
return | ||
} | ||
connmgr, _ := swarm["ConnMgr"].(map[string]any) | ||
if connmgr == nil { | ||
log.Log("No Swarm.ConnMgr field in config, skipping") | ||
return | ||
} | ||
cmType, ok := connmgr["Type"].(string) | ||
if !ok { | ||
log.Log("No Swarm.ConnMgr.Type field in config, skipping") | ||
return | ||
} | ||
cmLowWater, ok := connmgr["LowWater"].(float64) | ||
if !ok { | ||
log.Log("No Swarm.ConnMgr.LowWater field in config, skipping") | ||
return | ||
} | ||
cmHighWater, ok := connmgr["HighWater"].(float64) | ||
if !ok { | ||
log.Log("No Swarm.ConnMgr.HighWater field in config, skipping") | ||
return | ||
} | ||
cmGrace, ok := connmgr["GracePeriod"].(string) | ||
if !ok { | ||
log.Log("No Swarm.ConnMgr.GracePeriod field in config, skipping") | ||
return | ||
} | ||
|
||
if cmType == "basic" && int(cmLowWater) == 600 && int(cmHighWater) == 900 && cmGrace == "20s" { | ||
delete(connmgr, "Type") | ||
delete(connmgr, "GracePeriod") | ||
delete(connmgr, "LowWater") | ||
delete(connmgr, "HighWater") | ||
} else { | ||
log.Log("Swarm.ConnMgr settings are different than the old defaults, skipping") | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this file be on
tools
package?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, this doesn't need to be done now given that would be function-less code change.
It would help making future migrations cleaner.