Ensure that new deployments in a snapshot will be processed on the new DB
diff --git a/data.go b/data.go
index 0f8c412..6cd175a 100644
--- a/data.go
+++ b/data.go
@@ -80,13 +80,12 @@
return db
}
+// caller is responsible for calling dbMux.Lock() and dbMux.Unlock()
func SetDB(db apid.DB) {
- dbMux.Lock()
if unsafeDB == nil { // init API when DB is initialized
go InitAPI()
}
unsafeDB = db
- dbMux.Unlock()
}
// call whenever the list of deployments changes
diff --git a/listener.go b/listener.go
index 889e74c..7d9b056 100644
--- a/listener.go
+++ b/listener.go
@@ -62,17 +62,17 @@
log.Panicf("Error starting transaction: %v", err)
}
+ // ensure that no new database updates are made on old database
+ dbMux.Lock()
+
defer tx.Rollback()
for _, table := range snapshot.Tables {
var err error
switch table.Name {
case DEPLOYMENT_TABLE:
log.Debugf("Snapshot of %s with %d rows", table.Name, len(table.Rows))
- if len(table.Rows) == 0 {
- return
- }
for _, row := range table.Rows {
- addDeployment(tx, row)
+ err = addDeployment(tx, row)
}
}
if err != nil {
@@ -86,6 +86,7 @@
}
SetDB(db)
+ dbMux.Unlock()
// if no tables, this a startup event for an existing DB, start bundle downloads that didn't finish
if len(snapshot.Tables) == 0 {