@@ -33,6 +33,8 @@ import (
33
33
"github.com/filecoin-project/go-state-types/abi"
34
34
35
35
"github.com/filecoin-project/lotus/blockstore"
36
+ badgerbs "github.com/filecoin-project/lotus/blockstore/badger"
37
+ "github.com/filecoin-project/lotus/blockstore/splitstore"
36
38
"github.com/filecoin-project/lotus/chain/store"
37
39
lcli "github.com/filecoin-project/lotus/cli"
38
40
"github.com/filecoin-project/lotus/cmd/lotus-shed/shedgen"
@@ -97,24 +99,61 @@ var exportChainCmd = &cli.Command{
97
99
98
100
defer fi .Close () //nolint:errcheck
99
101
100
- bs , err := lr .Blockstore (ctx , repo .UniversalBlockstore )
102
+ cold , err := lr .Blockstore (ctx , repo .UniversalBlockstore )
101
103
if err != nil {
102
104
return fmt .Errorf ("failed to open blockstore: %w" , err )
103
105
}
104
106
105
107
defer func () {
106
- if c , ok := bs .(io.Closer ); ok {
108
+ if c , ok := cold .(io.Closer ); ok {
107
109
if err := c .Close (); err != nil {
108
110
log .Warnf ("failed to close blockstore: %s" , err )
109
111
}
110
112
}
111
113
}()
112
114
115
+ path , err := lr .SplitstorePath ()
116
+ if err != nil {
117
+ return xerrors .Errorf ("failed to get splitstore path: %w" , err )
118
+ }
119
+
120
+ path = filepath .Join (path , "hot.badger" )
121
+ if err := os .MkdirAll (path , 0755 ); err != nil {
122
+ return xerrors .Errorf ("failed to create hot.badger dir: %w" , err )
123
+ }
124
+
125
+ opts , err := repo .BadgerBlockstoreOptions (repo .HotBlockstore , path , lr .Readonly ())
126
+ if err != nil {
127
+ return xerrors .Errorf ("failed to get badger blockstore options: %w" , err )
128
+ }
129
+
130
+ hot , err := badgerbs .Open (opts )
131
+ if err != nil {
132
+ return xerrors .Errorf ("failed to open badger blockstore: %w" , err )
133
+ }
134
+
113
135
mds , err := lr .Datastore (context .Background (), "/metadata" )
114
136
if err != nil {
115
- return err
137
+ return xerrors .Errorf ("failed to open metadata datastore: %w" , err )
138
+ }
139
+
140
+ cfg := & splitstore.Config {
141
+ MarkSetType : "map" ,
142
+ DiscardColdBlocks : true ,
143
+ }
144
+ ss , err := splitstore .Open (path , mds , hot , cold , cfg )
145
+ if err != nil {
146
+ return xerrors .Errorf ("failed to open splitstore: %w" , err )
116
147
}
117
148
149
+ defer func () {
150
+ if err := ss .Close (); err != nil {
151
+ log .Warnf ("failed to close blockstore: %s" , err )
152
+ }
153
+ }()
154
+
155
+ bs := ss
156
+
118
157
cs := store .NewChainStore (bs , bs , mds , nil , nil )
119
158
defer cs .Close () //nolint:errcheck
120
159
0 commit comments