MCPcopy Create free account
hub / github.com/cloudwan/gohan / Resync

Function Resync

server/resync.go:14–79  ·  view source on GitHub ↗

Resync performs resync

(dbConn db.DB, sync sync.Sync)

Source from the content-addressed store, hash-verified

12
13// Resync performs resync
14func Resync(dbConn db.DB, sync sync.Sync) (err error) {
15
16 syncDbConn := &DbSyncWrapper{DB: dbConn}
17 schemaManager := schema.GetManager()
18
19 tx, err := syncDbConn.Begin()
20 if err != nil {
21 return fmt.Errorf("Error when acquiring DB transaction: %s", err)
22 }
23 committed := false
24 defer func() {
25 if !committed {
26 tx.Close()
27 }
28 }()
29
30 tl := tx.(*transactionEventLogger)
31 for _, schemaType := range schemaManager.OrderedSchemas() {
32 if schemaType.IsAbstract() {
33 log.Debug("Skip abstract schema %s", schemaType.ID)
34 continue
35 }
36
37 if schemaType.Metadata["type"] == "metaschema" {
38 log.Debug("Skip metaschema %s", schemaType.ID)
39 continue
40 }
41
42 if schemaType.Metadata["nosync"] == true {
43 log.Debug("Skip nosync schema %s", schemaType.ID)
44 continue
45 }
46
47 log.Info("Re-emitting events for resource type %s", schemaType.ID)
48 all, _, err := tl.List(schemaType, transaction.Filter{}, nil, nil)
49 if err != nil {
50 util.ExitFatal(fmt.Sprintf("Error when acquiring DB transaction: %s", err))
51 }
52 for _, resource := range all {
53 tl.Resync(resource)
54 }
55 log.Info("Done re-emitting events for resource type %s", schemaType.ID)
56 }
57
58 err = tl.Commit()
59 if err != nil {
60 return fmt.Errorf("Error when committing DB transaction: %s", err)
61 }
62 committed = true
63
64 syncWriter := NewSyncWriter(sync, dbConn)
65 totallySynced := 0
66 for {
67 synced, err := syncWriter.Sync()
68 if err != nil {
69 return fmt.Errorf("Error when syncing events: %s", err)
70 }
71 if synced == 0 {

Callers

nothing calls this directly

Calls 12

BeginMethod · 0.95
SyncMethod · 0.95
NewSyncWriterFunction · 0.85
OrderedSchemasMethod · 0.80
IsAbstractMethod · 0.80
ResyncMethod · 0.80
ErrorfMethod · 0.65
CloseMethod · 0.65
DebugMethod · 0.65
InfoMethod · 0.65
ListMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected