Commit 400c24d 1 parent 2574b37 commit 400c24d Copy full SHA for 400c24d
File tree 5 files changed +20
-16
lines changed
graph/src/components/store
5 files changed +20
-16
lines changed Original file line number Diff line number Diff line change @@ -183,13 +183,13 @@ where
183
183
// Restart the store to clear any errors that it
184
184
// might have encountered and use that from now on
185
185
let store = self . inputs . store . cheap_clone ( ) ;
186
- let store = store. restart ( ) . await ?;
187
- self . inputs = Arc :: new ( self . inputs . with_store ( store ) ) ;
188
- // Also clear the entity cache since we might have
189
- // entries in there that never made it to the
190
- // database
191
- self . state . entity_lfu_cache = LfuCache :: new ( ) ;
192
- self . state . synced = self . inputs . store . is_deployment_synced ( ) . await ? ;
186
+ if let Some ( store) = store. restart ( ) . await ? {
187
+ let last_good_block =
188
+ store . block_ptr ( ) . map ( |ptr| ptr . number ) . unwrap_or ( 0 ) ;
189
+ self . revert_state ( last_good_block ) ? ;
190
+ self . inputs = Arc :: new ( self . inputs . with_store ( store ) ) ;
191
+ self . state . synced = self . inputs . store . is_deployment_synced ( ) . await ? ;
192
+ }
193
193
break ;
194
194
}
195
195
} ;
Original file line number Diff line number Diff line change @@ -331,10 +331,11 @@ pub trait WritableStore: ReadStore + DeploymentCursorTracker {
331
331
/// contain unprocessed write requests that will be discarded by this
332
332
/// call.
333
333
///
334
- /// After this call, `self` should not be used anymore, as it will
335
- /// continue to produce errors for any write requests, and instead, the
336
- /// returned `WritableStore` should be used.
337
- async fn restart ( self : Arc < Self > ) -> Result < Arc < dyn WritableStore > , StoreError > ;
334
+ /// This call returns `None` if a restart was not needed because `self`
335
+ /// had no errors. If it returns `Some`, `self` should not be used
336
+ /// anymore, as it will continue to produce errors for any write
337
+ /// requests, and instead, the returned `WritableStore` should be used.
338
+ async fn restart ( self : Arc < Self > ) -> Result < Option < Arc < dyn WritableStore > > , StoreError > ;
338
339
}
339
340
340
341
#[ async_trait]
Original file line number Diff line number Diff line change @@ -1316,16 +1316,19 @@ impl WritableStoreTrait for WritableStore {
1316
1316
self . writer . flush ( ) . await
1317
1317
}
1318
1318
1319
- async fn restart ( self : Arc < Self > ) -> Result < Arc < dyn WritableStoreTrait > , StoreError > {
1319
+ async fn restart ( self : Arc < Self > ) -> Result < Option < Arc < dyn WritableStoreTrait > > , StoreError > {
1320
1320
if self . poisoned ( ) {
1321
1321
let logger = self . store . logger . clone ( ) ;
1322
1322
if let Err ( e) = self . stop ( ) . await {
1323
1323
warn ! ( logger, "Writable had error when stopping, it is safe to ignore this error" ; "error" => e. to_string( ) ) ;
1324
1324
}
1325
1325
let store = Arc :: new ( self . store . store . 0 . clone ( ) ) ;
1326
- store. writable ( logger, self . store . site . id . into ( ) ) . await
1326
+ store
1327
+ . writable ( logger, self . store . site . id . into ( ) )
1328
+ . await
1329
+ . map ( |store| Some ( store) )
1327
1330
} else {
1328
- Ok ( self )
1331
+ Ok ( None )
1329
1332
}
1330
1333
}
1331
1334
}
Original file line number Diff line number Diff line change @@ -170,7 +170,7 @@ impl WritableStore for MockStore {
170
170
unimplemented ! ( )
171
171
}
172
172
173
- async fn restart ( self : Arc < Self > ) -> Result < Arc < dyn WritableStore > , StoreError > {
173
+ async fn restart ( self : Arc < Self > ) -> Result < Option < Arc < dyn WritableStore > > , StoreError > {
174
174
unimplemented ! ( )
175
175
}
176
176
}
Original file line number Diff line number Diff line change @@ -192,7 +192,7 @@ fn restart() {
192
192
193
193
// We now have a poisoned store. Restarting it gives us a new store
194
194
// that works again
195
- let writable = writable. restart ( ) . await . unwrap ( ) ;
195
+ let writable = writable. restart ( ) . await . unwrap ( ) . unwrap ( ) ;
196
196
writable. flush ( ) . await . unwrap ( ) ;
197
197
198
198
// Retry our write with correct data
You can’t perform that action at this time.
0 commit comments