ipfs-cluster/state/mapstate/migrate.go
Hector Sanjuan 718b2177ce Issue #51: Save a backup on shutdown
This adds snapshot and restore methods to state and uses the snapshot
one to save a copy of the state when shutting down. Right now, this is
not used for anything else.

Some lines performing a migration, but this is only an idea of how it could
work.

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-03-13 17:57:10 +01:00

35 lines
599 B
Go

package mapstate
import (
"encoding/json"
"errors"
"github.com/ipfs/ipfs-cluster/api"
)
type mapStateV1 struct {
Version int
PinMap map[string]struct{}
}
func (st *MapState) migrateFrom(version int, snap []byte) error {
switch version {
case 1:
var mstv1 mapStateV1
err := json.Unmarshal(snap, &mstv1)
if err != nil {
return err
}
for k := range mstv1.PinMap {
st.PinMap[k] = api.PinSerial{
Cid: k,
Allocations: []string{},
ReplicationFactor: -1,
}
}
return nil
default:
return errors.New("version migration not supported")
}
}