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

Fixes in master -> release #6933

Merged
merged 27 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5073c7e
feat(deps): update to branches with improved logging
hannahhoward Jul 28, 2021
9b7a771
add RuntimeSubsystems API method; use it in `lotus-miner info`
nonsense Jul 28, 2021
0dd83c6
fixup
nonsense Jul 28, 2021
cea2634
extract outputs for mining node and markets node in separate functions
nonsense Jul 28, 2021
0c036b1
make linter happy
nonsense Jul 28, 2021
c119ab6
fix docs and nits.
raulk Jul 28, 2021
d8c90b9
address nits.
raulk Jul 28, 2021
d039764
code cosmetics: rename variables for better readability and some comm…
vyzo Jul 28, 2021
7a3193a
make relative links when the canonical and new db paths are in the sa…
vyzo Jul 28, 2021
a24b243
extend test to check the validity of relative links
vyzo Jul 28, 2021
0caabf1
improve detection of relative links
vyzo Jul 28, 2021
ec78d3d
fix format specifier
vyzo Jul 28, 2021
4417be8
fix typo
vyzo Jul 28, 2021
fd33b96
make symlink helper freestanding
vyzo Jul 29, 2021
786d3e7
make gen
jennijuju Jul 29, 2021
0daee83
more logging in data transfer and markets
aarshkshah1992 Jul 29, 2021
029ba39
update deps for logging
aarshkshah1992 Jul 29, 2021
8442bac
support MARKETS_API_INFO env var; support markets-repo, markets-api-u…
raulk Jul 29, 2021
9205642
target markets API for markets commands.
raulk Jul 29, 2021
d37ae95
refactor miner info command.
raulk Jul 29, 2021
107777f
polish.
raulk Jul 29, 2021
1b5a2dd
fix tests.
raulk Jul 29, 2021
299b106
fix docs, add flag.
raulk Jul 29, 2021
b3c951c
add RepoType#String; adjust repo parsing logic.
raulk Jul 29, 2021
4b6fa79
bugfix.
raulk Jul 29, 2021
00c3432
use fallback api infos last; init service with markets-path.
raulk Jul 29, 2021
bb040ab
fix compilation error.
raulk Jul 29, 2021
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
4 changes: 4 additions & 0 deletions api/api_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ type StorageMiner interface {
MarketPendingDeals(ctx context.Context) (PendingDealInfo, error) //perm:write
MarketPublishPendingDeals(ctx context.Context) error //perm:admin

// RuntimeSubsystems returns the subsystems that are enabled
// in this instance.
RuntimeSubsystems(ctx context.Context) (MinerSubsystems, error) //perm:read

DealsImportData(ctx context.Context, dealPropCid cid.Cid, file string) error //perm:admin
DealsList(ctx context.Context) ([]MarketDeal, error) //perm:admin
DealsConsiderOnlineStorageDeals(context.Context) (bool, error) //perm:admin
Expand Down
21 changes: 14 additions & 7 deletions api/docgen/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
"github.com/google/uuid"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-filestore"
metrics "github.com/libp2p/go-libp2p-core/metrics"
"github.com/libp2p/go-libp2p-core/metrics"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
protocol "github.com/libp2p/go-libp2p-core/protocol"
"github.com/libp2p/go-libp2p-core/protocol"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/multiformats/go-multiaddr"

Expand All @@ -46,11 +46,12 @@ import (
)

var ExampleValues = map[reflect.Type]interface{}{
reflect.TypeOf(auth.Permission("")): auth.Permission("write"),
reflect.TypeOf(""): "string value",
reflect.TypeOf(uint64(42)): uint64(42),
reflect.TypeOf(byte(7)): byte(7),
reflect.TypeOf([]byte{}): []byte("byte array"),
reflect.TypeOf(api.MinerSubsystem(0)): api.MinerSubsystem(1),
reflect.TypeOf(auth.Permission("")): auth.Permission("write"),
reflect.TypeOf(""): "string value",
reflect.TypeOf(uint64(42)): uint64(42),
reflect.TypeOf(byte(7)): byte(7),
reflect.TypeOf([]byte{}): []byte("byte array"),
}

func addExample(v interface{}) {
Expand Down Expand Up @@ -264,6 +265,12 @@ func init() {

addExample(api.CheckStatusCode(0))
addExample(map[string]interface{}{"abc": 123})
addExample(api.MinerSubsystems{
api.SubsystemMining,
api.SubsystemSealing,
api.SubsystemSectorStorage,
api.SubsystemMarkets,
})
}

func GetAPIType(name, pkg string) (i interface{}, t reflect.Type, permStruct []reflect.Type) {
Expand Down
79 changes: 79 additions & 0 deletions api/miner_subsystems.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package api

import (
"encoding/json"
)

// MinerSubsystem represents a miner subsystem. Int and string values are not
// guaranteed to be stable over time is not
// guaranteed to be stable over time.
type MinerSubsystem int

const (
// SubsystemUnknown is a placeholder for the zero value. It should never
// be used.
SubsystemUnknown MinerSubsystem = iota
// SubsystemMarkets signifies the storage and retrieval
// deal-making subsystem.
SubsystemMarkets
// SubsystemMining signifies the mining subsystem.
SubsystemMining
// SubsystemSealing signifies the sealing subsystem.
SubsystemSealing
// SubsystemSectorStorage signifies the sector storage subsystem.
SubsystemSectorStorage
)

var MinerSubsystemToString = map[MinerSubsystem]string{
SubsystemUnknown: "Unknown",
SubsystemMarkets: "Markets",
SubsystemMining: "Mining",
SubsystemSealing: "Sealing",
SubsystemSectorStorage: "SectorStorage",
}

var MinerSubsystemToID = map[string]MinerSubsystem{
"Unknown": SubsystemUnknown,
"Markets": SubsystemMarkets,
"Mining": SubsystemMining,
"Sealing": SubsystemSealing,
"SectorStorage": SubsystemSectorStorage,
}

func (ms MinerSubsystem) MarshalJSON() ([]byte, error) {
return json.Marshal(MinerSubsystemToString[ms])
}

func (ms *MinerSubsystem) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
if err != nil {
return err
}
s, ok := MinerSubsystemToID[j]
if !ok {
*ms = SubsystemUnknown
} else {
*ms = s
}
return nil
}

type MinerSubsystems []MinerSubsystem

func (ms MinerSubsystems) Has(entry MinerSubsystem) bool {
for _, v := range ms {
if v == entry {
return true
}
}
return false
}

func (ms MinerSubsystem) String() string {
s, ok := MinerSubsystemToString[ms]
if !ok {
return MinerSubsystemToString[SubsystemUnknown]
}
return s
}
13 changes: 13 additions & 0 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 59 additions & 30 deletions blockstore/badger/blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,29 +258,30 @@ func (b *Blockstore) movingGC() error {
b.moveCond.Broadcast()
b.moveMx.Unlock()

var path string
var newPath string

defer func() {
b.lockMove()

db2 := b.dbNext
dbNext := b.dbNext
b.dbNext = nil

var state bsMoveState
if db2 != nil {
if dbNext != nil {
state = moveStateCleanup
} else {
state = moveStateNone
}

b.unlockMove(state)

if db2 != nil {
err := db2.Close()
if dbNext != nil {
// the move failed and we have a left-over db; delete it.
err := dbNext.Close()
if err != nil {
log.Warnf("error closing badger db: %s", err)
}
b.deleteDB(path)
b.deleteDB(newPath)

b.lockMove()
b.unlockMove(moveStateNone)
Expand All @@ -296,68 +297,96 @@ func (b *Blockstore) movingGC() error {
}

if basePath == linkPath {
path = basePath
newPath = basePath
} else {
// we do this dance to create a name adjacent to the current one, while avoiding clown
// shoes with multiple moves (i.e. we can't just take the basename of the linkPath, as it
// could have been created in a previous move and have the timestamp suffix, which would then
// perpetuate itself.
name := filepath.Base(basePath)
dir := filepath.Dir(linkPath)
path = filepath.Join(dir, name)
newPath = filepath.Join(dir, name)
}
path = fmt.Sprintf("%s.%d", path, time.Now().UnixNano())
newPath = fmt.Sprintf("%s.%d", newPath, time.Now().UnixNano())

log.Infof("moving blockstore from %s to %s", b.opts.Dir, path)
log.Infof("moving blockstore from %s to %s", b.opts.Dir, newPath)

opts := b.opts
opts.Dir = path
opts.ValueDir = path
opts.Dir = newPath
opts.ValueDir = newPath

db2, err := badger.Open(opts.Options)
dbNew, err := badger.Open(opts.Options)
if err != nil {
return fmt.Errorf("failed to open badger blockstore in %s: %w", path, err)
return fmt.Errorf("failed to open badger blockstore in %s: %w", newPath, err)
}

b.lockMove()
b.dbNext = db2
b.dbNext = dbNew
b.unlockMove(moveStateMoving)

log.Info("copying blockstore")
err = b.doCopy(b.db, b.dbNext)
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", newPath, err)
}

b.lockMove()
db1 := b.db
dbOld := b.db
b.db = b.dbNext
b.dbNext = nil
b.unlockMove(moveStateCleanup)

err = db1.Close()
err = dbOld.Close()
if err != nil {
log.Warnf("error closing old badger db: %s", err)
}

dbpath := b.opts.Dir
oldpath := fmt.Sprintf("%s.old.%d", dbpath, time.Now().Unix())
// this is the canonical db path; this is where our db lives.
dbPath := b.opts.Dir

if err = os.Rename(dbpath, oldpath); err != nil {
// we first move the existing db out of the way, and only delete it after we have symlinked the
// new db to the canonical path
backupPath := fmt.Sprintf("%s.old.%d", dbPath, time.Now().Unix())
if err = os.Rename(dbPath, backupPath); err != nil {
// this is not catastrophic in the sense that we have not lost any data.
// but it is pretty bad, as the db path points to the old db, while we are now using to the new
// db; we can't continue and leave a ticking bomb for the next restart.
// so a panic is appropriate and user can fix.
panic(fmt.Errorf("error renaming old badger db dir from %s to %s: %w; USER ACTION REQUIRED", dbpath, oldpath, err)) //nolint
panic(fmt.Errorf("error renaming old badger db dir from %s to %s: %w; USER ACTION REQUIRED", dbPath, backupPath, err)) //nolint
}

if err = os.Symlink(path, dbpath); err != nil {
if err = symlink(newPath, dbPath); err != nil {
// same here; the db path is pointing to the void. panic and let the user fix.
panic(fmt.Errorf("error symlinking new badger db dir from %s to %s: %w; USER ACTION REQUIRED", path, dbpath, err)) //nolint
panic(fmt.Errorf("error symlinking new badger db dir from %s to %s: %w; USER ACTION REQUIRED", newPath, dbPath, err)) //nolint
}

b.deleteDB(oldpath)
// the delete follows symlinks
b.deleteDB(backupPath)

log.Info("moving blockstore done")
return nil
}

// symlink creates a symlink from path to linkTo; the link is relative if the two are
// in the same directory
func symlink(path, linkTo string) error {
resolvedPathDir, err := filepath.EvalSymlinks(filepath.Dir(path))
if err != nil {
return fmt.Errorf("error resolving links in %s: %w", path, err)
}

resolvedLinkDir, err := filepath.EvalSymlinks(filepath.Dir(linkTo))
if err != nil {
return fmt.Errorf("error resolving links in %s: %w", linkTo, err)
}

if resolvedPathDir == resolvedLinkDir {
path = filepath.Base(path)
}

return os.Symlink(path, linkTo)
}

// 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) error {
Expand Down Expand Up @@ -390,19 +419,19 @@ func (b *Blockstore) doCopy(from, to *badger.DB) error {

func (b *Blockstore) deleteDB(path string) {
// follow symbolic links, otherwise the data wil be left behind
lpath, err := filepath.EvalSymlinks(path)
linkPath, err := filepath.EvalSymlinks(path)
if err != nil {
log.Warnf("error resolving symlinks in %s", path)
return
}

log.Infof("removing data directory %s", lpath)
if err := os.RemoveAll(lpath); err != nil {
log.Warnf("error deleting db at %s: %s", lpath, err)
log.Infof("removing data directory %s", linkPath)
if err := os.RemoveAll(linkPath); err != nil {
log.Warnf("error deleting db at %s: %s", linkPath, err)
return
}

if path != lpath {
if path != linkPath {
log.Infof("removing link %s", path)
if err := os.Remove(path); err != nil {
log.Warnf("error removing symbolic link %s", err)
Expand Down
15 changes: 15 additions & 0 deletions blockstore/badger/blockstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,21 @@ func testMove(t *testing.T, optsF func(string) Options) {

checkBlocks()
checkPath()

// reopen the db to make sure our relative link works:
err = db.Close()
if err != nil {
t.Fatal(err)
}

db, err = Open(optsF(dbPath))
if err != nil {
t.Fatal(err)
}

// db.Close() is already deferred

checkBlocks()
}

func TestMoveNoPrefix(t *testing.T) {
Expand Down
Binary file modified build/openrpc/full.json.gz
Binary file not shown.
Binary file modified build/openrpc/miner.json.gz
Binary file not shown.
Binary file modified build/openrpc/worker.json.gz
Binary file not shown.
5 changes: 3 additions & 2 deletions cli/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ var AuthApiInfoToken = &cli.Command{

ti, ok := cctx.App.Metadata["repoType"]
if !ok {
log.Errorf("unknown repo type, are you sure you want to use GetAPI?")
log.Errorf("unknown repo type, are you sure you want to use GetCommonAPI?")
ti = repo.FullNode
}
t, ok := ti.(repo.RepoType)
Expand All @@ -128,7 +128,8 @@ var AuthApiInfoToken = &cli.Command{

// TODO: Log in audit log when it is implemented

fmt.Printf("%s=%s:%s\n", cliutil.EnvForRepo(t), string(token), ainfo.Addr)
currentEnv, _, _ := cliutil.EnvsForAPIInfos(t)
fmt.Printf("%s=%s:%s\n", currentEnv, string(token), ainfo.Addr)
return nil
},
}
3 changes: 2 additions & 1 deletion cli/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func GetFullNodeServices(ctx *cli.Context) (ServicesAPI, error) {

var GetAPIInfo = cliutil.GetAPIInfo
var GetRawAPI = cliutil.GetRawAPI
var GetAPI = cliutil.GetAPI
var GetAPI = cliutil.GetCommonAPI

var DaemonContext = cliutil.DaemonContext
var ReqContext = cliutil.ReqContext
Expand All @@ -54,6 +54,7 @@ var GetFullNodeAPIV1 = cliutil.GetFullNodeAPIV1
var GetGatewayAPI = cliutil.GetGatewayAPI

var GetStorageMinerAPI = cliutil.GetStorageMinerAPI
var GetMarketsAPI = cliutil.GetMarketsAPI
var GetWorkerAPI = cliutil.GetWorkerAPI

var CommonCommands = []*cli.Command{
Expand Down
Loading