Skip to content

Commit

Permalink
V1 migration works if old offset table does not exist (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zen Yui authored Apr 6, 2021
1 parent 3b600f0 commit 0b35105
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,16 @@ case class V1(
/**
* move the data from the old read side offset store table to the new temporay offset store table by
* reading all records into memory.
*
* @return the number of the record inserted into the table
*/
private def migrate(): Int = {
// let us fetch the records
val data: Seq[OffsetRow] = fetchOffsetRows()

log.info(s"num records migrating to $tempTable: ${data.size}")

// let us insert the data into the temporary table
insertInto(tempTable, journalJdbcConfig, data)
private[v1] def migrate(): Unit = {
val oldTable: String = transformTableName()
if (DbUtil.tableExists(projectionJdbcConfig, oldTable)) {
// let us fetch the records
val data: Seq[OffsetRow] = fetchOffsetRows()
log.info(s"num records migrating to $tempTable: ${data.size}")
// let us insert the data into the temporary table
insertInto(tempTable, journalJdbcConfig, data)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,20 @@ class V1Spec extends BaseSpec with ForAllTestContainer {

count(journalJdbcConfig) shouldBe 3
}
"succeed if old table does not exist" in {
val v1: V1 = V1(journalJdbcConfig, projectionJdbcConfig, "not_a_table")
// then run beforeUpgrade
v1.beforeUpgrade().isSuccess shouldBe true
// assert no records
count(journalJdbcConfig) shouldBe 0
}
}
".migrate" should {
"succeed even if old table does not exist" in {
val v1: V1 = V1(journalJdbcConfig, projectionJdbcConfig, "not_a_table")
// create the old read side offset store
noException shouldBe thrownBy(v1.migrate())
}
}
".upgrade" should {
"drop the old table and index" in {
Expand Down

0 comments on commit 0b35105

Please sign in to comment.