From a80909587cb7e15fe1bc4c9d23d8c81d8a9f4b1a Mon Sep 17 00:00:00 2001 From: Andrey Belonogov Date: Fri, 13 Nov 2026 11:54:54 -0800 Subject: [PATCH] Give each environment the whole byte capacity, rather than an equal share of it Co-authored-by: Cursor --- .../sdk/android/ComponentsImpl.java | 12 +----- .../integrations/EventProcessorBuilder.java | 18 ++++----- .../sdk/android/DirectEventProcessorTest.java | 40 ++++++++----------- 3 files changed, 26 insertions(+), 44 deletions(-) diff --git a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/ComponentsImpl.java b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/ComponentsImpl.java index 82b8de8d..1ab8b640 100644 --- a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/ComponentsImpl.java +++ b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/ComponentsImpl.java @@ -186,22 +186,12 @@ private EventStore makeEventStore(ClientContext clientContext, ClientContextImpl impl.getPlatformState(), clientContext.getMobileKey(), capacity, - shareOfCapacityBytes(clientContext.getConfig()), + capacityBytes, maxAgeMillis, eventPersistence != EventPersistence.DISABLED, clientContext.getBaseLogger()); } - /** - * This environment's share of the byte capacity, which is for every environment the application configured - * together, where the event capacity is for each one. - */ - private long shareOfCapacityBytes(LDConfig config) { - int environments = config == null ? 1 : Math.max(1, config.getMobileKeys().size()); - // At least one byte, since the store reads zero as the default. - return Math.max(1, capacityBytes / environments); - } - @Override public LDValue describeConfiguration(ClientContext clientContext) { return LDValue.buildObject() diff --git a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/integrations/EventProcessorBuilder.java b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/integrations/EventProcessorBuilder.java index fa5d53b8..aa1ffa04 100644 --- a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/integrations/EventProcessorBuilder.java +++ b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/integrations/EventProcessorBuilder.java @@ -87,7 +87,7 @@ public abstract class EventProcessorBuilder implements ComponentConfigurer - * It is for every environment the application configures together: with - * {@link com.launchdarkly.sdk.android.LDConfig.Builder#secondaryMobileKeys(java.util.Map)}, each - * environment gets an equal share of it. That is unlike {@link #capacity(int)}, which each environment - * has in full. + * Like {@link #capacity(int)}, each environment in + * {@link com.launchdarkly.sdk.android.LDConfig.Builder#secondaryMobileKeys(java.util.Map)} has it in full. *

- * When an environment reaches its share, the SDK discards new events until it successfully delivers the stored ones, as + * When an environment reaches it, the SDK discards new events until it successfully delivers the stored ones, as * it does when {@link #capacity(int)} is reached; it never deletes stored events to make room. A fifth - * of each share is kept for the summaries of flag evaluations, so that evaluations are still counted after + * of it is kept for the summaries of flag evaluations, so that evaluations are still counted after * full events start being discarded. *

* Ordinary events reach {@link #capacity(int)} long before this. It binds where events are unusually @@ -209,7 +207,7 @@ public EventProcessorBuilder eventPersistence(EventPersistence eventPersistence) * accumulate. The default value is {@link #DEFAULT_CAPACITY_BYTES}; a value of zero or less means the * default. * - * @param capacityBytes the most bytes of events to keep, for all environments together + * @param capacityBytes the most bytes of events to keep, for each environment * @return the builder */ public EventProcessorBuilder capacityBytes(long capacityBytes) { diff --git a/launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/DirectEventProcessorTest.java b/launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/DirectEventProcessorTest.java index 0489e132..0f7225ba 100644 --- a/launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/DirectEventProcessorTest.java +++ b/launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/DirectEventProcessorTest.java @@ -1377,35 +1377,29 @@ public void aFlushFailsWhenAnAcceptedEventIsTooLargeForTheBytesLeft() throws Exc } @Test - public void theByteCapacityIsSharedEquallyByTheConfiguredEnvironments() throws Exception { + public void eachEnvironmentHasTheWholeByteCapacityHoweverManyAreConfigured() throws Exception { assumePersisting(); StringBuilder data = new StringBuilder(); for (int i = 0; i < 700; i++) { data.append('x'); } Map secondaryMobileKeys = new HashMap<>(); - secondaryMobileKeys.put("second", "mob-second"); - secondaryMobileKeys.put("third", "mob-third"); - secondaryMobileKeys.put("fourth", "mob-fourth"); - for (boolean shared : new boolean[]{false, true}) { - try (HttpServer server = startEventsServer()) { - EventProcessor eventProcessor = buildOfflineEventProcessor(server.getUri(), - eventsBuilder(DEFAULT_CAPACITY).capacityBytes(2_400), true, platformState(), - shared ? secondaryMobileKeys : null); - eventProcessor.setOffline(false); - try { - // About 850 bytes: within the full 2,400 bytes, and past a quarter of them. - eventProcessor.recordCustomEvent(CONTEXT, "large", LDValue.of(data.toString()), null); - - assertEquals(!shared, awaitFlush(eventProcessor, 10, TimeUnit.SECONDS)); - if (shared) { - assertEquals(0, server.getRecorder().count()); - } else { - assertEquals(1, collectDelivered(server).size()); - } - } finally { - eventProcessor.close(); - } + for (int i = 2; i <= 7; i++) { + secondaryMobileKeys.put("env-" + i, "mob-" + i); + } + try (HttpServer server = startEventsServer()) { + EventProcessor eventProcessor = buildOfflineEventProcessor(server.getUri(), + eventsBuilder(DEFAULT_CAPACITY).capacityBytes(2_400), true, platformState(), + secondaryMobileKeys); + eventProcessor.setOffline(false); + try { + // About 850 bytes: within the full 2,400 bytes, and past a seventh of them. + eventProcessor.recordCustomEvent(CONTEXT, "large", LDValue.of(data.toString()), null); + + assertTrue(awaitFlush(eventProcessor, 10, TimeUnit.SECONDS)); + assertEquals(1, collectDelivered(server).size()); + } finally { + eventProcessor.close(); } } }