Repository navigation
refactor(events): name the event directory from a name the caller hashes - #430
Open
abelonogov-ld wants to merge 327 commits into
Open
abelonogov-ld wants to merge 327 commits into
abelonogov-ld wants to merge 327 commits into
Conversation
One helper for both, so a reset path that cleared the counters alone cannot spend the cardinality limit on contexts whose counters have already gone out. Co-authored-by: Cursor <cursoragent@cursor.com>
…-durability-tier2-bounded-flush
…y/event-durability-tier3-persistence Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/OutboundEventBuffer.java
An evaluation of a tracked flag writes a summary counter and a feature event, and a debug event alongside them when debugging is on. Those writes took separate locks, so a close() landing between them delivered the counter and then refused the event, reporting an evaluation that no event describes. Widen the lock that guarded the pending events to cover the summary counters too, so the writes one evaluation makes are one critical section. drain() splits into takeSummaries() and encode() so the flush can take the run and the counters together and still encode outside the lock. Co-authored-by: Cursor <cursoragent@cursor.com>
…-durability-tier2-bounded-flush Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/DirectEventProcessor.java
…y/event-durability-tier3-persistence Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/DirectEventProcessor.java # launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/OutboundEventBuffer.java
createEventAndReset hands back a period's statistics and clears them in the same call, so whoever builds the event owns it. It was built on the scheduler thread and posted from the diagnostics thread, which may have been busy with an earlier post; a transition to offline or background in that window was noticed after the build and discarded the event. The period's stream inits, events-in-batch count and dropped count went with it, and dataSinceDate had already moved, so the next event described a window beginning after the reset. Move the build onto the posting thread, behind the suspension check, so a transition leaves the counters where they are for the next period to carry. The init event keeps its check, having nothing to consume. Co-authored-by: Cursor <cursoragent@cursor.com>
…-durability-tier2-bounded-flush
…y/event-durability-tier3-persistence Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/DirectEventProcessorTest.java
The normalization said `>= 0`, so a capacity of nought stayed nought. On main that threw from `new ArrayBlockingQueue<>(0)` at construction; with the pending list there is nothing to throw, so it became a silent refusal of every event. Worse than it sounds, because the same number is the buffer's context limit and only the processor was normalizing it: at nought neither full events nor summaries survived, and at -5 the processor allowed one event while the buffer refused to summarize at all. So the fix is one normalization in ComponentsImpl feeding both, with the processor keeping its own guard for direct construction. Co-authored-by: Cursor <cursoragent@cursor.com>
…ing the server describeConfiguration was sending the raw capacity, so a client configured with nought told the service nought while running at one. It now shares the one normalization with the buffer and the processor. The race test was flaking about one run in six. Not the processor: the test server records a request body with a single unlooped read, so a body past one socket read's worth comes back truncated, at a point that moves between runs. Thirty events instead of a hundred and fifty stays clear of it, and the test still fails on every un-fixed run. Co-authored-by: Cursor <cursoragent@cursor.com>
…-durability-tier2-bounded-flush
…y/event-durability-tier3-persistence Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/ComponentsImpl.java
Three components bound themselves by this number and each was normalizing it, or not. Clamping in the setter makes the field valid by construction, which is what the sibling setter for the diagnostic interval already does, and leaves every consumer -- the buffer, the processor, the diagnostic description -- to just use it. Co-authored-by: Cursor <cursoragent@cursor.com>
…-durability-tier2-bounded-flush
…y/event-durability-tier3-persistence Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/ComponentsImpl.java
The two init tests asserted nothing. One asked a foreground processor to go to the foreground, which setInBackground returns from before reaching any decision; the other waited for the init event before going offline, so the only thing stopping a second one was that the first had already gone. Each was held up by the guard the other claimed to cover, and both passed with every guard deleted. Coming to the foreground now goes through the background first, and waits for the diagnostics thread to come free -- while the first init is still posting, the claim is taken and the transition is turned away before it decides anything. The offline one builds a processor that never comes online, then brings it online to show the silence was the offline state and not a dead fixture. Two new ones. A must-shut-down response has to stop recording and delivery for good, which nothing exercised. And a flush running against four recorders has to keep each evaluation in one payload: close() delivers once, so it can catch an evaluation being stranded but never one being split across two deliveries. Eight trials, because a single one catches a split lock about two times in three. Co-authored-by: Cursor <cursoragent@cursor.com>
…-durability-tier2-bounded-flush Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/DirectEventProcessorTest.java
…y/event-durability-tier3-persistence aFlushNeverSplitsAnEvaluationAcrossTwoPayloads is left behind at tier 2. It reads each payload as it went out, which says something only where a payload is the run taken straight from the pending list; here a delivery reads the store, so a counter and its event can land in one payload or two for reasons that have nothing to do with the lock. Confirmed by narrowing the lock and watching it pass five times out of five. A comment in its place says where it went. Co-authored-by: Cursor <cursoragent@cursor.com>
The MalformedJsonException in aContextAlreadyBeingCountedKeepsCountingOnceTheLimitIsReached is not a serialization race: recording is sequential on the test thread and the payload is a deterministic ~28 KB. The test-helpers HTTP server reads request bodies with a single unlooped read, so larger bodies can be truncated depending on the machine. Fill the summarizer to a limit of 10 contexts instead of 100 so each flush stays well under that size. Co-authored-by: Cursor <cursoragent@cursor.com>
…-durability-tier2-bounded-flush
…y/event-durability-tier3-persistence
Offline means the application told the SDK to stay off the network, and closing does not revoke that, so the final delivery in close() is skipped and held events are dropped. DefaultEventProcessor behaved the same way (its FLUSH is a no-op while offline); the comments and the EventProcessor javadoc promised more than either implementation did. Add a test pinning the behavior. Co-authored-by: Cursor <cursoragent@cursor.com>
…-durability-tier2-bounded-flush * andrey/event-durability-tier1-buffer: Document that close() discards events held while offline
…y/event-durability-tier3-persistence * andrey/event-durability-tier2-bounded-flush: Document that close() discards events held while offline
…n reconnect The SDK builds the event processor offline and turns it on once initialization is done. Coming online used to deliver immediately, meant for the end of an outage, but it also fired on that first transition at startup and sent the initial identify alone before anything else was recorded. DefaultEventProcessor never did that, and the contract tests expect the first payload to wait for a flush. The immediate delivery existed only because cancelling the periodic flush for an outage restarted its interval on every reconnect. The flush task now stays scheduled regardless of the offline state (a run while offline does nothing), so the interval is never restarted and what an outage buffered goes out at the first run after it ends. No transition needs special handling. Co-authored-by: Cursor <cursoragent@cursor.com>
…-durability-tier2-bounded-flush Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/DirectEventProcessorTest.java
…y/event-durability-tier3-persistence Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/DirectEventProcessor.java # launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/EventProcessorTestBase.java
…rent constructor The context limit moved to the fourth parameter; the androidTest copy of the benchmark was never compiled by the unit-test runs and kept the old order. Co-authored-by: Cursor <cursoragent@cursor.com>
A commit takes the pending run under recordLock and encodes it outside, so until it is staged the run is in neither pending nor the store. The capacity check counted only those two, so an event recorded in that window was accepted past capacity; LDClientEventTest.testEventBufferFillsUp saw two identifies with a capacity of one once startup stopped delivering the first one alone. EventStore is no longer final so the test can pause a commit mid-staging. Co-authored-by: Cursor <cursoragent@cursor.com>
A batch was dropped at its third failed read in a row, counted per pass. Passes can come milliseconds apart -- flushes in a row, or flushAndWait posting through the backoff -- so a failure lasting a moment deleted an intact batch. Now a failed read counts only at least a flush interval after the last counted one, and a read that ran short of memory, which says nothing about the file, never counts. Co-authored-by: Cursor <cursoragent@cursor.com>
Every part of a split summary carries the whole context, so with a context near a frame's size the halving went on down to one flag per part: one loss per flag where there was one, each holding the context. A half that kept more than three quarters of what it was split from is now left whole. Co-authored-by: Cursor <cursoragent@cursor.com>
The three-quarter guard on halving stopped at any half that was mostly context, even where one more split would have fit, so those evaluations were refused. Now each flag's size is measured with a small stand-in context, and the flags are packed in key order into as few parts as fit a frame beside the context. A context that alone takes a frame still leaves the summary whole, one loss; halving remains only for a part that comes out larger than measured. Co-authored-by: Cursor <cursoragent@cursor.com>
…ler's thread Co-authored-by: Cursor <cursoragent@cursor.com>
…rites everything before it returns Co-authored-by: Cursor <cursoragent@cursor.com>
…ence The caller's thread encodes and writes the one event, without waiting for a commit in progress; the held evaluations and the summaries are left to a commit queued on the commit executor in the same call. The summarizer's counters are still taken at each track or identify, so its contexts are cleared as before. Co-authored-by: Cursor <cursoragent@cursor.com>
… reserved place A track or identify at immediate persistence committed the store, which wrote whatever a commit in flight had staged so far, up to megabytes of a run or a split summary, on the application thread. It now writes just its own frame and leaves the rest to the commit that staged it. It is also reserved where it is admitted, so a recording on another thread cannot take its place while it is encoded and have it refused as a loss. A commit now releases only its own unused reservations rather than all of them. Co-authored-by: Cursor <cursoragent@cursor.com>
A summary too large for one log frame is refused whole by the store, logged, and counted as lost, so the flush that committed it answers false. Reaching that takes one context evaluating dozens of the largest JSON flags between two commits, which did not justify the packing and halving that split it. Co-authored-by: Cursor <cursoragent@cursor.com>
…e again Writing only the tracked event left the evaluations before it to a commit queued on the commit executor, so a kill straight after the track, which is what immediate persistence is for, could take those exposures with it. With the summary split gone, the commit costs the caller a normal encode of the held run and the summaries, so the track commits it again before returning. This reverts 19afcec and 1200025. Co-authored-by: Cursor <cursoragent@cursor.com>
…rsistence again" This reverts commit a65c588, which moves to a PR of its own. Co-authored-by: Cursor <cursoragent@cursor.com>
…n hashing the mobile key in EventDirectory Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Automated risk review (dry run): Low
This PR would be automatically approved.
Why: This is a small, test-covered refactor that moves event-directory hashing from EventDirectory to LDUtil.hashedStorageName and updates EventStore factories so the on-disk path stays the same. Production callers still hash the mobile key, and new tests pin that hash plus that defaultDirectory does not hash again.
If you disagree with this review, share this PR in #feedback-agent-approvals or submit a changes-requested review explaining why.
Sent by Cursor Approval Agent: Dry-Run PR Approver
Each environment now has the whole `capacityBytes`, like `capacity`, rather than an equal share of it. This follows the review on iOS ([ios-client-sdk#538](launchdarkly/ios-client-sdk#538 (comment))), which makes the same change. Stacked on #408 (tier 3). - **An equal share is too small where there are many environments.** Some customers configure 7, which at the default left each under 3 MiB. - **Adding an environment no longer shrinks the others.** A share was fixed when the store was built, so a directory within its old share could be over its new one, and new events were refused until delivery or expiry drained it. - **The disk the SDK may use now grows with the environments**: up to 20 MiB each at the default. Ordinary traffic reaches `capacity` (2000 events) long before that; only unusually large events, or summaries piling up through a long outage, get near it. - **`ComponentsImpl.shareOfCapacityBytes` is gone**; the store gets `capacityBytes` as it is, and already reads zero or less as the default. The `EventProcessorBuilder.capacityBytes` docs say it is for each environment. Test: `theByteCapacityIsSharedEquallyByTheConfiguredEnvironments` becomes `eachEnvironmentHasTheWholeByteCapacityHoweverManyAreConfigured`: with seven environments and a 2,400-byte capacity, an 850-byte event is delivered, where the old split's 342 bytes would have refused it. `./gradlew :launchdarkly-android-client-sdk:testDebugUnitTest`: 1257 tests, 0 failures (25 skipped). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > **Persisted event byte limits are now per environment**, matching `capacity(int)` and the iOS client change, instead of splitting `capacityBytes` evenly across all configured mobile keys. > > `ComponentsImpl` drops `shareOfCapacityBytes` and passes the configured `capacityBytes` straight into `EventStore.create`. **`EventProcessorBuilder` docs** are updated to state each secondary environment gets the full limit, so adding environments no longer shrinks others and apps with many envs (e.g. seven) aren’t stuck with tiny per-env quotas. > > The unit test is renamed and asserts that with seven environments and a 2,400-byte limit, an ~850-byte custom event still flushes—behavior that would fail under the old equal-share rule. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a809095. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: Cursor <cursoragent@cursor.com>
Changes `EventProcessorBuilder.DEFAULT_MAX_AGE_MILLIS` from 7 days to 24 hours. Persisted events that have not been delivered within 24 hours are discarded and counted as dropped, and so is what the SDK stored for a mobile key the application stopped using. Applications can still call `maxAgeMillis(long)` to keep events longer. It has no effect where `eventPersistence` is `DISABLED`. Stacked on #408 (tier 3). - `DEFAULT_MAX_AGE_MILLIS` is now `24L * 60 * 60 * 1000`, with its Javadoc updated. - `EventStoreBoundsTest.keepsABatchYoungerThanTheMaximumAge` aged its batch by 6 days, which is now past the default; it ages it by 12 hours. The tests that age by 8 days still exceed the maximum age and are unchanged. iOS counterpart: launchdarkly/ios-client-sdk#549. Tested: `:launchdarkly-android-client-sdk:testDebugUnitTest`, 1257 tests, 0 failures. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > **Shortens the default retention window** for persisted analytics events from **7 days to 24 hours** by updating `EventProcessorBuilder.DEFAULT_MAX_AGE_MILLIS` and its Javadoc. > > When event persistence is enabled, undelivered batches older than the default max age are discarded (and counted as dropped); apps can still override via `maxAgeMillis(long)`. The change has **no effect** when `eventPersistence` is `DISABLED`. > > `EventStoreBoundsTest.keepsABatchYoungerThanTheMaximumAge` now ages a batch by **12 hours** instead of 6 days so it still falls under the new default. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 057a2ef. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: Cursor <cursoragent@cursor.com>
The unknown-flag de-duplication set added in 68d3dbf is backed by a ConcurrentHashMap, which rejects null, so variation(null, ...) threw a NullPointerException on the caller's thread. A null key now skips the de-duplication and returns the default, as it did before. Co-authored-by: Cursor <cursoragent@cursor.com>
…event-directory-name
…ty-tier1-buffer Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/build.gradle # launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/ComponentsImpl.java # shared-test-code/build.gradle
…-durability-tier2-bounded-flush
…y/event-durability-tier3-persistence
…event-directory-name
Persisted batches are posted by AnalyticsEventSender, which ignored EventProcessorBuilder.enableCompression, so only diagnostic events were compressed. The batch on disk stays plain JSON; each attempt compresses it, and one that cannot be compressed goes uncompressed. Co-authored-by: Cursor <cursoragent@cursor.com>
…event-directory-name
…o be discarded sdk-test-harness v2.46.0 added "events/delivery retry/payload is discarded if the retry also fails". With persistence, a batch whose retry fails is kept and posted again later (DeliveryRetryState: a failure never stops delivery), so the next post repeats the payload instead of carrying only the later event. The other delivery retry tests pass. Co-authored-by: Cursor <cursoragent@cursor.com>
…event-directory-name
Base automatically changed from
andrey/event-durability-tier3-persistence
to
main
November 21, 2026 01:50
This branch has not been deployed
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.


EventDirectory.defaultDirectorynow takes a name that is already hashed and uses it as it is. The hashing moves out toLDUtil.hashedStorageName(mobileKey), which theEventStorefactories call. This follows the review on iOS (ios-client-sdk#538), whereEventDirectory.defaultUrlnow takes an already hashed name in the same way.Stacked on #408 (tier 3).
hashedStorageNameis the samehexDigest(mobileKey, 16)thatEventDirectoryused privately, so events stored by tier 3 are found where they were.EventDirectoryno longer knows about mobile keys. It places a store undernoBackupFilesDir/com.launchdarkly.events/<name>, and whoever supplies the name decides how it is hashed.EventStorageLocationcallsEventDirectory.defaultDirectory(noBackupFilesDir, mobileKey), which would still compile after this change but would point at a directory named for the raw key. Whichever of the two merges second should callLDUtil.hashedStorageName(mobileKey)there.Tests:
LDUtilTestpinshashedStorageName("mob-12345")to3a4f14b3feba38b362ad80b504238faaand checks that it does not hold the key.EventStoreTestchecks thatdefaultDirectoryuses the name it is given without hashing it again.DirectEventProcessorTestbuilds the directory through oneenvironmentDirectory()helper instead of five copies of the call../gradlew :launchdarkly-android-client-sdk:testDebugUnitTest: 1259 tests, 0 failures (25 skipped).Note
Overview
Moves mobile-key hashing out of
EventDirectoryand into callers, matching the iOS client pattern.EventDirectory.defaultDirectorynow accepts a ready-made environment name and uses it verbatim (no second hash).LDUtil.hashedStorageName(mobileKey)centralizes the oldhexDigest(mobileKey, 16)logic;EventStore.createfactories hash before resolving the directory. On-disk layout is unchanged—same digest as before.Tests add coverage for
hashedStorageNameand no double-hashing, plus a sharedenvironmentDirectory()helper in integration tests.Reviewed by Cursor Bugbot for commit 439c0f9. Bugbot is set up for automated code reviews on this repo. Configure here.