feat: Add max persistence age override option [TRIAGE-608]#698
feat: Add max persistence age override option [TRIAGE-608]#698junias-rokt wants to merge 5 commits intomParticle:mainfrom
Conversation
PR SummaryMedium Risk Overview Updates the upload pipeline to run a throttled (24h) age-based sweep before uploads, deleting persisted messages/uploads/sessions older than the configured max age (or a new 90-day default), via a new transactional Adds unit/instrumentation tests covering option validation, the new delete-by-cutoff semantics (strict Reviewed by Cursor Bugbot for commit efe31bb. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit c588b67. Configure here.
| if (builder.persistenceMaxAgeSeconds <= 0) { | ||
| Logger.warning("Persistence Max Age must be a positive number, disregarding value."); | ||
| } else { | ||
| this.mPersistenceMaxAgeSeconds = builder.persistenceMaxAgeSeconds; | ||
| } |
There was a problem hiding this comment.
Shouldn't we check for the upper bound? Something like
if (builder.persistenceMaxAgeSeconds <= 0) {
Logger.warning("Persistence Max Age must be a positive number, disregarding value.");
} else if (builder.persistenceMaxAgeSeconds > MAX_PERSISTENCE_MAX_AGE_SECONDS) {
Logger.warning("Persistence Max Age is too high");
this.mPersistenceMaxAgeSeconds = MAX_PERSISTENCE_MAX_AGE_SECONDS;
} else {
this.mPersistenceMaxAgeSeconds = builder.persistenceMaxAgeSeconds;
}or not set it at all of not in the range?
There was a problem hiding this comment.
Hey good callout! This is intentional as the main aim for these changes was to have feature parity with the other SDKs. Changing this would diverge from the other ones. This also matches all the other validators in the file and large values basically just disable the sweep.
|




Background
The iOS mParticle SDK exposes
MParticleOptions.persistenceMaxAgeSeconds, which caps the age of locally persisted events, batches, and sessions to prevent unbounded on-device storage growth. The Android SDK had no equivalent — once data was written to the SQLite store it would sit there until the app either uploaded it or was uninstalled. For apps that batch heavily, go long stretches offline, or see users who rarely background the app, this can produce noticeable storage bloat and a slow drift toward larger database files. TRIAGE-608 was opened to close this feature-parity gap and document it on the Android configuration guide.The companion iOS implementation lives in
MPBackendController.cleanUp:andMPPersistenceController deleteRecordsOlderThan:, which is the behavioral spec this change mirrors.What Has Changed
Public API
MParticleOptions.Builder#persistenceMaxAgeSeconds(int seconds)and the matching getterMParticleOptions#getPersistenceMaxAgeSeconds(). Units are seconds, values must be positive; zero or negative values log a warning and fall back to the default.Wiring
ConfigManagerso the upload pipeline can read it at runtime.Age-based sweep
MParticleDBManager#deleteRecordsOlderThan(long cutoffMillis)orchestrator wraps three new static helpers in a single transaction:MessageService#deleteMessagesOlderThan— deletes fromMessageTableColumns.TABLE_NAMEwherecreated_at < ?UploadService#deleteUploadsOlderThan— deletes fromUploadTableColumns.TABLE_NAMEwherecreated_at < ?SessionService#deleteSessionsOlderThan— deletes fromSessionTableColumns.TABLE_NAMEwhereend_time < ?UploadHandler#upload()now callsmaybePrunePersistedRecords(now)at the start of each cycle. The sweep is throttled to run at most once every 24 hours and defaults to a 90-day retention window whenpersistenceMaxAgeSecondsis unset — matching the iOS defaults precisely.Tests
MParticleOptionsTest#testPersistenceMaxAgeSecondscovers null/positive/zero/negative inputs on the builder.MessageServiceTest#testDeleteMessagesOlderThanverifies the SQL cutoff semantics (strictly<cutoff are deleted; rows at or newer than the cutoff are retained).Screenshots/Video
N/A — this is a configuration/storage-hygiene change with no UI surface.
Checklist
Local validation against JDK 17: `trunk check`, `./gradlew build`, `./gradlew test`, `./gradlew ktlintCheck`, and `./gradlew lint` all pass. `connectedAndroidTest` was not run locally (no emulator available) — will rely on CI.
Additional Notes
Reference Issue (For employees only. Ignore if you are an outside contributor)