chore(backend): harden sqlite concurrent writes and add stress tests#10
Merged
Conversation
Comment on lines
+46
to
+54
| // @Autowired | ||
| // private JdbcTemplate jdbcTemplate; | ||
|
|
||
| @BeforeEach | ||
| void cleanTables() { | ||
| jdbcTemplate.update("DELETE FROM activity_logs"); | ||
| jdbcTemplate.update("DELETE FROM items"); | ||
| jdbcTemplate.update("DELETE FROM captures"); | ||
| } | ||
| // @BeforeEach | ||
| // void cleanTables() { | ||
| // jdbcTemplate.update("DELETE FROM activity_logs"); | ||
| // jdbcTemplate.update("DELETE FROM items"); | ||
| // jdbcTemplate.update("DELETE FROM captures"); | ||
| // } |
Comment on lines
+94
to
+95
| jdbcTemplate.update(BACKFILL_ROW_ID_SQL, normalizedCapture.id()); | ||
| Long persistedRowId = jdbcTemplate.queryForObject(FIND_ROW_ID_BY_ID_SQL, Long.class, normalizedCapture.id()); |
Comment on lines
+165
to
+170
| private boolean isSqliteLocked(Throwable throwable) { | ||
| Throwable current = throwable; | ||
| while (current != null) { | ||
| String message = current.getMessage(); | ||
| String className = current.getClass().getName(); | ||
| boolean sqliteCause = className.contains("SQLite"); |
| if (!isSqliteLocked(exception) || attempt == SQLITE_LOCK_RETRY_MAX - 1) { | ||
| throw exception; | ||
| } | ||
| sleepBackoff(attempt); |
| normalizedCapture.deletedAt() | ||
| ); | ||
| return normalizedCapture; | ||
| return withSqliteLockRetry(() -> { |
Comment on lines
+94
to
+95
| jdbcTemplate.update(BACKFILL_ROW_ID_SQL, normalizedCapture.id()); | ||
| Long persistedRowId = jdbcTemplate.queryForObject(FIND_ROW_ID_BY_ID_SQL, Long.class, normalizedCapture.id()); |
| # macOS / Linux | ||
| ./gradlew bootRun | ||
| # Windows (PowerShell / CMD) | ||
| .\\gradlew.bat bootRun |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MAX(row_id)+1flow with safer insert/upsert + rowid backfill in SQLite repositoriesON CONFLICT(id) DO UPDATEWhy
SQLite shared-cache writes can transiently fail under concurrent writes (
SQLITE_LOCKED_SHAREDCACHE). This PR improves resilience and ensures row id assignment remains stable under load.Validation
./gradlew test