@@ -247,7 +247,7 @@ pub struct GroveDb {
247
247
version : i32
248
248
}
249
249
250
- pub struct state_sync_info < ' db /*, S*/ > {
250
+ pub struct StateSyncInfo < ' db /*, S*/ > {
251
251
restorer : Option < Restorer < PrefixedRocksDbImmediateStorageContext < ' db > > > ,
252
252
tx : Option < Transaction < ' db > > ,
253
253
pending_chunks : BTreeSet < Vec < u8 > > ,
@@ -256,20 +256,77 @@ pub struct state_sync_info<'db/*, S*/> {
256
256
version : i32 ,
257
257
}
258
258
259
- impl /*<S>*/ state_sync_info < ' _ /*, S*/ > {
260
- pub fn new ( ) -> state_sync_info < ' static /*, S*/ > {
259
+ impl /*<S>*/ StateSyncInfo < ' _ /*, S*/ > {
260
+ /*
261
+ pub fn new<'a>() -> StateSyncInfo<'a/*, S*/> {
261
262
let pending_chunks = BTreeSet::new();
262
263
let processed_prefixes = BTreeSet::new();
263
- state_sync_info {
264
+ StateSyncInfo {
264
265
restorer: None,
265
266
tx: None,
266
- pending_chunks : pending_chunks ,
267
- processed_prefixes : processed_prefixes ,
267
+ pending_chunks,
268
+ processed_prefixes,
268
269
//current_subtree_opt: None,
269
270
current_prefix: None,
270
271
version: 1
271
272
}
272
273
}
274
+
275
+ */
276
+ /*
277
+ pub fn start_syncing(
278
+ &self,
279
+ source_db: &GroveDb,
280
+ target_db: &GroveDb,
281
+ ) -> Result<(), Error> {
282
+ let app_hash = source_db.root_hash(None).value.unwrap();
283
+ target_db.w_start_snapshot_syncing(&mut self, app_hash).expect("TODO: panic message");
284
+ Ok(())
285
+ }
286
+
287
+ */
288
+ /*
289
+ pub fn w_start_snapshot_syncing<'db>(
290
+ &'db mut self,
291
+ grovedb: &'db GroveDb,
292
+ app_hash: CryptoHash,
293
+ ) -> Result<Vec<Vec<u8>>, Error>{
294
+ let mut res = vec![];
295
+
296
+ match (&mut self.restorer, &self.tx, &self.current_prefix) {
297
+ (None, None, None) => {
298
+ if self.pending_chunks.is_empty() && self.processed_prefixes.is_empty() {
299
+ let root_prefix = [0u8; 32];
300
+ self.tx = Some(grovedb.start_transaction());
301
+ if let Some(ref_tx) = self.tx.as_ref() {
302
+ let merk = grovedb.open_merk_for_replication(SubtreePath::empty(), ref_tx).unwrap();
303
+ let restorer = Restorer::new(merk, app_hash, None);
304
+ self.restorer = Some(restorer);
305
+ self.current_prefix = Some(root_prefix);
306
+ self.pending_chunks.insert(root_prefix.to_vec());
307
+
308
+ res.push(root_prefix.to_vec());
309
+ }
310
+ else {
311
+ return Err(Error::InternalError(
312
+ "Unable to start a tx",
313
+ ));
314
+ }
315
+ } else {
316
+ return Err(Error::InternalError(
317
+ "Invalid internal state sync info",
318
+ ));
319
+ }
320
+ },
321
+ _ => {
322
+ return Err(Error::InternalError(
323
+ "GroveDB has already started a snapshot syncing",
324
+ ));
325
+ }
326
+ }
327
+
328
+ Ok(res)
329
+ }*/
273
330
}
274
331
275
332
pub ( crate ) type SubtreePrefix = [ u8 ; blake3:: OUT_LEN ] ;
@@ -308,6 +365,21 @@ pub type TransactionArg<'db, 'a> = Option<&'a Transaction<'db>>;
308
365
309
366
#[ cfg( feature = "full" ) ]
310
367
impl GroveDb {
368
+ pub fn create_state_sync_info (
369
+ & self ,
370
+ ) -> StateSyncInfo {
371
+ let pending_chunks = BTreeSet :: new ( ) ;
372
+ let processed_prefixes = BTreeSet :: new ( ) ;
373
+ StateSyncInfo {
374
+ restorer : None ,
375
+ tx : None ,
376
+ pending_chunks,
377
+ processed_prefixes,
378
+ //current_subtree_opt: None,
379
+ current_prefix : None ,
380
+ version : 1
381
+ }
382
+ }
311
383
/// Opens a given path
312
384
pub fn open < P : AsRef < Path > > ( path : P ) -> Result < Self , Error > {
313
385
@@ -387,7 +459,7 @@ impl GroveDb {
387
459
fn open_merk_for_replication < ' db , ' b , B > (
388
460
& ' db self ,
389
461
path : SubtreePath < ' b , B > ,
390
- tx : & ' db Transaction ,
462
+ tx : & ' b Transaction < ' db > ,
391
463
) -> Result < Merk < PrefixedRocksDbImmediateStorageContext < ' db > > , Error >
392
464
where
393
465
B : AsRef < [ u8 ] > + ' b ,
@@ -1316,13 +1388,20 @@ impl GroveDb {
1316
1388
1317
1389
// pub fn w_start_snapshot_syncing<'db: 'a, 'a/*, S: StorageContext<'db>*/>(
1318
1390
// &'a self,
1319
- // state_sync_info : &'db mut state_sync_info <'a/*, S*/>,
1391
+ // StateSyncInfo : &'db mut StateSyncInfo <'a/*, S*/>,
1320
1392
// app_hash: CryptoHash,
1321
1393
// )
1322
1394
1323
- pub fn w_start_snapshot_syncing < ' db : ' a , ' a /*, S: StorageContext<'db>*/ > (
1324
- & ' a self ,
1325
- state_sync_info : & ' db mut state_sync_info < ' a /*, S*/ > ,
1395
+ // pub fn w_start_snapshot_syncing<'db: 'a, 'a/*, S: StorageContext<'db>*/>(
1396
+ // &'a self,
1397
+ // StateSyncInfo: &'db mut StateSyncInfo<'a/*, S*/>,
1398
+ // app_hash: CryptoHash,
1399
+ // )
1400
+
1401
+ pub fn w_start_snapshot_syncing < ' db > (
1402
+ & ' db self ,
1403
+ //state_sync_info: &'db mut StateSyncInfo<'db>,
1404
+ mut state_sync_info : StateSyncInfo < ' db > ,
1326
1405
app_hash : CryptoHash ,
1327
1406
) -> Result < Vec < Vec < u8 > > , Error > {
1328
1407
let mut res = vec ! [ ] ;
@@ -1364,7 +1443,7 @@ impl GroveDb {
1364
1443
1365
1444
pub fn w_apply_chunk < ' db : ' a , ' a /*, S: StorageContext<'db>*/ > (
1366
1445
& ' a self ,
1367
- state_sync_info : & ' db mut state_sync_info < ' a /*, S*/ > ,
1446
+ state_sync_info : & ' db mut StateSyncInfo < ' a /*, S*/ > ,
1368
1447
chunk : ( Vec < u8 > , Vec < Op > )
1369
1448
) -> Result < Vec < Vec < u8 > > , Error > {
1370
1449
let mut res = vec ! [ ] ;
0 commit comments