Skip to content

Commit

Permalink
chore(jobsdb): setup and migrate schema of database tables early
Browse files Browse the repository at this point in the history
  • Loading branch information
atzoum committed Nov 16, 2022
1 parent bf0e4d5 commit d414a37
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions jobsdb/jobsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,16 @@ func (jd *HandleT) init() {
jd.dbHandle = sqlDB
}
jd.workersAndAuxSetup()

// Database schema migration should happen early, even before jobsdb is started,
// so that we can be sure that all the necessary tables are created and considered to be in
// the latest schema version, before rudder-migrator starts introducing new tables.
jd.dsListLock.WithLock(func(l lock.LockToken) {
switch jd.ownerType {
case Write, ReadWrite:
jd.setupDatabaseTables(l, jd.clearAll)
}
})
}

func (jd *HandleT) workersAndAuxSetup() {
Expand Down Expand Up @@ -898,24 +908,19 @@ func (jd *HandleT) Start() error {
jd.backgroundGroup = g

if !jd.skipSetupDBSetup {
jd.setUpForOwnerType(ctx, jd.ownerType, jd.clearAll)

// Avoid clearing the database, if .Start() is called again.
jd.clearAll = false
jd.setUpForOwnerType(ctx, jd.ownerType)
}
return nil
}

func (jd *HandleT) setUpForOwnerType(ctx context.Context, ownerType OwnerType, clearAll bool) {
func (jd *HandleT) setUpForOwnerType(ctx context.Context, ownerType OwnerType) {
jd.dsListLock.WithLock(func(l lock.LockToken) {
switch ownerType {
case Read:
jd.readerSetup(ctx, l)
case Write:
jd.setupDatabaseTables(l, clearAll)
jd.writerSetup(ctx, l)
case ReadWrite:
jd.setupDatabaseTables(l, clearAll)
jd.readerWriterSetup(ctx, l)
}
})
Expand Down

0 comments on commit d414a37

Please sign in to comment.