Conversation
…ia `Bookeeper` trait.
WalkthroughThe Bookkeeper trait gains AutoCloseable and a new deleteTable(tableWithWildcard: String): Seq[String] API. Implementations were updated: JDBC provides a full implementation and close(), some implementations provide stubs or no-op behavior, tests and mocks updated to exercise deletion behavior. Changes
Sequence DiagramsequenceDiagram
actor Client
participant BookkeeperJdbc as Bookkeeper JDBC
participant DB as Database
participant Logger
Client->>BookkeeperJdbc: deleteTable(pattern)
activate BookkeeperJdbc
BookkeeperJdbc->>BookkeeperJdbc: escape pattern & validate (≤100)
BookkeeperJdbc->>DB: SELECT matching table names
DB-->>BookkeeperJdbc: matched names
BookkeeperJdbc->>DB: DELETE FROM bookkeeping WHERE table IN (matched)
DB-->>BookkeeperJdbc: bookkeeping delete counts
BookkeeperJdbc->>DB: DELETE FROM schema WHERE table IN (matched)
DB-->>BookkeeperJdbc: schema delete counts
BookkeeperJdbc->>DB: DELETE FROM offsets WHERE table IN (matched)
DB-->>BookkeeperJdbc: offsets delete counts
BookkeeperJdbc->>DB: DELETE FROM metadata WHERE table IN (matched)
DB-->>BookkeeperJdbc: metadata delete counts
BookkeeperJdbc->>Logger: log deletion summaries
BookkeeperJdbc-->>Client: Seq[deleted_table_names]
deactivate BookkeeperJdbc
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pramen/core/src/main/scala/za/co/absa/pramen/core/bookkeeper/BookkeeperText.scala (1)
201-206:⚠️ Potential issue | 🟠 Major
deleteTableis unimplemented and will throw at runtime.
???raisesNotImplementedError, so any call will crash pipelines usingBookkeeperText. Please implement deletion (e.g., filter and rewritebookkeeping.csvandschemas.json, mirroring wildcard logic used inSyncBookkeeperMock) or explicitly document unsupported behavior and handle it safely.
🤖 Fix all issues with AI agents
In
`@pramen/core/src/main/scala/za/co/absa/pramen/core/bookkeeper/Bookkeeper.scala`:
- Around line 54-60: Update the Scaladoc comment in the Bookkeeper class for the
method that "Deletes tables matching the given wildcard pattern" by correcting
the typo "bookeeping" to "bookkeeping" so the sentence reads "The method deletes
just the metadata about selected tables in every bookkeeping table except
journal, which is used for logging only."; locate and edit the Scaladoc block
above the delete-tables method in Bookkeeper.scala to apply this change.
In
`@pramen/core/src/main/scala/za/co/absa/pramen/core/bookkeeper/BookkeeperJdbc.scala`:
- Around line 196-231: The current deletes (BookkeepingRecords.records,
SchemaRecords.records, OffsetRecords.records, MetadataRecords.records) are
executed separately via SlickUtils.executeAction which can leave the DB in an
inconsistent state if one delete fails; combine these four delete actions into a
single Slick DB action using .andThen(...) chaining and mark it .transactionally
(or otherwise run as one transaction) so all deletes either commit or roll back
together, then execute that single transactional action instead of calling
SlickUtils.executeAction for each individual delete.
- Around line 180-208: The LIKE handling doesn't escape '_' so single-character
wildcards can match unintended tables; update the pattern construction to also
replace "_" with "\\_" (in addition to replacing "%" with "\\%") when building
tableNameEscaped/likePattern, keep the existing conversion of '*' to '%' for
wildcards, and then use Slick's like(pattern, escape) overload with escape =
'\\' when querying (update the .like usages on BookkeepingRecords.records in
listQuery and deletionQuery and any other .like calls in this method) so queries
use .like(likePattern, '\\') and prevent accidental matches.
In
`@pramen/core/src/test/scala/za/co/absa/pramen/core/mocks/bookkeeper/SyncBookkeeperMock.scala`:
- Around line 159-179: The deleteTable mock mixes SQL LIKE syntax with regex
matching: update the likePattern construction in deleteTable so it produces a
regex, not a SQL LIKE; specifically change the non-wildcard branch to append
"->.*" (regex) instead of "->%" so that keysToDelete filtering using
tblName.matches(...) works correctly. Keep using the existing tableNameEscaped,
chunks, and the .matches(...) checks; no other logic changes required.
🧹 Nitpick comments (1)
pramen/core/src/main/scala/za/co/absa/pramen/core/bookkeeper/BookkeeperJdbc.scala (1)
41-42: Makeclose()atomic for concurrent callers.The
if (!isClosed)check isn’t atomic, so concurrent callers can double-close. ConsiderAtomicBoolean.🔒 Atomic close
+import java.util.concurrent.atomic.AtomicBoolean @@ - `@volatile` private var isClosed = false + private val isClosed = new AtomicBoolean(false) @@ override def close(): Unit = { - if (!isClosed) { - db.close() - isClosed = true - } + if (isClosed.compareAndSet(false, true)) { + db.close() + } }Also applies to: 238-243
pramen/core/src/main/scala/za/co/absa/pramen/core/bookkeeper/Bookkeeper.scala
Show resolved
Hide resolved
pramen/core/src/main/scala/za/co/absa/pramen/core/bookkeeper/BookkeeperJdbc.scala
Show resolved
Hide resolved
pramen/core/src/main/scala/za/co/absa/pramen/core/bookkeeper/BookkeeperJdbc.scala
Show resolved
Hide resolved
pramen/core/src/test/scala/za/co/absa/pramen/core/mocks/bookkeeper/SyncBookkeeperMock.scala
Show resolved
Hide resolved
Unit Test Coverage
Files
|
66bf69a to
e5ceca6
Compare
e5ceca6 to
513ba26
Compare
a2a8fbb to
f7c8003
Compare
Closes #706
Summary by CodeRabbit
New Features
Tests
Bug Fixes