1、主要结构体之lotus/extern/sector-storage/stores/index.go
Index结构体
type Index struct {
*indexLocks
lk sync.RWMutex
sectors map[Decl][]*declMeta
stores map[ID]*storageEntry
}
1、stores map[ID]*storageEntry
worker启动连接到miner时调用StorageAttach
1、main.go
localStore, err := stores.NewLocal(ctx, lr, nodeApi, []string{"http://" + cctx.String("address") + "/remote"})
if err != nil {
return err
}
2、lotus/extern/sector-storage/stores/local.go
func NewLocal(ctx context.Context, ls LocalStorage, index SectorIndex, urls []string) (*Local, error) {
...
return l, l.open(ctx)
}
func (st *Local) open(ctx context.Context) error {
...
for _, path := range cfg.StoragePaths {
err := st.OpenPath(ctx, path.Path)
if err != nil {
return xerrors.Errorf("opening path %s: %w", path.Path, err)
}
}
...
}
func (st *Local) OpenPath(ctx context.Context, p string) error {
...
err = st.index.StorageAttach(ctx, StorageInfo{ //rpc调用(注册到miner)
ID: meta.ID,
URLs: st.urls,
Weight: meta.Weight,
CanSeal: meta.CanSeal,
CanStore: meta.CanStore,
}, fst)
if err != nil {
return xerrors.Errorf("declaring storage in index: %w", err)
}
...
}
miner
1、func (i *Index) StorageAttach(ctx context.Context, si StorageInfo, st FsStat) error {
...
i.stores[si.ID] = &storageEntry{
info: &si,
fsi: st,
lastHeartbeat: time.Now(),
}
...
}
si.ID是对应worker存储目录~/.lotusworker2/sectorstore.json中的ID
打印日志:
i.stores[328e87d4-9723-43c4-ab0f-37acd3859c22]: si:{ID:328e87d4-9723-43c4-ab0f-37acd3859c22 URLs:[http://127.0.0.1:3345/remote] Weight:10 CanSeal:true CanStore:false LastHeartbeat:0001-01-01 00:00:00 +0000 UTC HeartbeatErr:<nil>},st:{Capacity:63277150208 Available:34257240064 Used:0}
2、 sectors map[Decl][]*declMeta