@@ -48,6 +48,7 @@ const (
48
48
setNs = "s" // set
49
49
processedBlocksNs = "b" // blocks
50
50
dirtyBitKey = "d" // dirty
51
+ versionKey = "crdt_version"
51
52
)
52
53
53
54
// Common errors.
@@ -86,9 +87,9 @@ type Options struct {
86
87
// element is successfully removed from the datastore (either by a
87
88
// local or remote update). Unordered and concurrent updates may
88
89
// result in the DeleteHook being triggered even though the element is
89
- // still present in the datastore because it was re-added. If that is
90
- // relevant, use Has() to check if the removed element is still part
91
- // of the datastore.
90
+ // still present in the datastore because it was re-added or not fully
91
+ // tombstoned. If that is relevant, use Has() to check if the removed
92
+ // element is still part of the datastore.
92
93
DeleteHook func (k ds.Key )
93
94
// NumWorkers specifies the number of workers ready to walk DAGs
94
95
NumWorkers int
@@ -257,7 +258,7 @@ func New(
257
258
}
258
259
259
260
ctx , cancel := context .WithCancel (context .Background ())
260
- set , err := newCRDTSet (ctx , store , fullSetNs , opts .Logger , setPutHook , setDeleteHook )
261
+ set , err := newCRDTSet (ctx , store , fullSetNs , dagSyncer , opts .Logger , setPutHook , setDeleteHook )
261
262
if err != nil {
262
263
cancel ()
263
264
return nil , errors .Wrap (err , "error setting up crdt set" )
@@ -285,8 +286,15 @@ func New(
285
286
queuedChildren : newCidSafeSet (),
286
287
}
287
288
289
+ err = dstore .applyMigrations (ctx )
290
+ if err != nil {
291
+ cancel ()
292
+ return nil , err
293
+ }
294
+
288
295
headList , maxHeight , err := dstore .heads .List ()
289
296
if err != nil {
297
+ cancel ()
290
298
return nil , err
291
299
}
292
300
dstore .logger .Infof (
@@ -576,7 +584,7 @@ func (store *Datastore) handleBlock(c cid.Cid) error {
576
584
// Ignore already processed blocks.
577
585
// This includes the case when the block is a current
578
586
// head.
579
- isProcessed , err := store .isProcessed (c )
587
+ isProcessed , err := store .isProcessed (store . ctx , c )
580
588
if err != nil {
581
589
return errors .Wrapf (err , "error checking for known block %s" , c )
582
590
}
@@ -733,11 +741,11 @@ func (store *Datastore) processedBlockKey(c cid.Cid) ds.Key {
733
741
return store .namespace .ChildString (processedBlocksNs ).ChildString (dshelp .MultihashToDsKey (c .Hash ()).String ())
734
742
}
735
743
736
- func (store * Datastore ) isProcessed (c cid.Cid ) (bool , error ) {
744
+ func (store * Datastore ) isProcessed (ctx context. Context , c cid.Cid ) (bool , error ) {
737
745
return store .store .Has (store .ctx , store .processedBlockKey (c ))
738
746
}
739
747
740
- func (store * Datastore ) markProcessed (c cid.Cid ) error {
748
+ func (store * Datastore ) markProcessed (ctx context. Context , c cid.Cid ) error {
741
749
return store .store .Put (store .ctx , store .processedBlockKey (c ), nil )
742
750
}
743
751
@@ -785,7 +793,7 @@ func (store *Datastore) processNode(ng *crdtNodeGetter, root cid.Cid, rootPrio u
785
793
786
794
// Record that we have processed the node so that any other worker
787
795
// can skip it.
788
- err = store .markProcessed (current )
796
+ err = store .markProcessed (store . ctx , current )
789
797
if err != nil {
790
798
return nil , errors .Wrapf (err , "error recording %s as processed" , current )
791
799
}
@@ -827,7 +835,7 @@ func (store *Datastore) processNode(ng *crdtNodeGetter, root cid.Cid, rootPrio u
827
835
return nil , errors .Wrapf (err , "error checking if %s is head" , child )
828
836
}
829
837
830
- isProcessed , err := store .isProcessed (child )
838
+ isProcessed , err := store .isProcessed (store . ctx , child )
831
839
if err != nil {
832
840
return nil , errors .Wrapf (err , "error checking for known block %s" , child )
833
841
}
@@ -959,7 +967,7 @@ func (store *Datastore) repairDAG() error {
959
967
}
960
968
cancel ()
961
969
962
- isProcessed , err := store .isProcessed (cur )
970
+ isProcessed , err := store .isProcessed (store . ctx , cur )
963
971
if err != nil {
964
972
return errors .Wrapf (err , "error checking for reprocessed block %s" , cur )
965
973
}
@@ -1364,7 +1372,9 @@ func (store *Datastore) printDAGRec(from cid.Cid, depth uint64, ng *crdtNodeGett
1364
1372
return nil
1365
1373
}
1366
1374
1367
- nd , delta , err := ng .GetDelta (context .Background (), from )
1375
+ ctx , cancel := context .WithTimeout (store .ctx , store .opts .DAGSyncerTimeout )
1376
+ defer cancel ()
1377
+ nd , delta , err := ng .GetDelta (ctx , from )
1368
1378
if err != nil {
1369
1379
return err
1370
1380
}
@@ -1385,7 +1395,19 @@ func (store *Datastore) printDAGRec(from cid.Cid, depth uint64, ng *crdtNodeGett
1385
1395
cidStr = cidStr [len (cidStr )- 4 :]
1386
1396
line += fmt .Sprintf ("%s," , cidStr )
1387
1397
}
1388
- line += "}:"
1398
+ line += "}"
1399
+
1400
+ processed , err := store .isProcessed (store .ctx , nd .Cid ())
1401
+ if err != nil {
1402
+ return err
1403
+ }
1404
+
1405
+ if ! processed {
1406
+ line += " Unprocessed!"
1407
+ }
1408
+
1409
+ line += ":"
1410
+
1389
1411
fmt .Println (line )
1390
1412
for _ , l := range nd .Links () {
1391
1413
store .printDAGRec (l .Cid , depth + 1 , ng , set )
@@ -1433,7 +1455,9 @@ func (store *Datastore) dotDAGRec(w io.Writer, from cid.Cid, depth uint64, ng *c
1433
1455
return nil
1434
1456
}
1435
1457
1436
- nd , delta , err := ng .GetDelta (context .Background (), from )
1458
+ ctx , cancel := context .WithTimeout (store .ctx , store .opts .DAGSyncerTimeout )
1459
+ defer cancel ()
1460
+ nd , delta , err := ng .GetDelta (ctx , from )
1437
1461
if err != nil {
1438
1462
return err
1439
1463
}
0 commit comments