Repository navigation
Conversation
Co-Authored-By: Bee Klimt <bklimt@launchdarkly.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
| return interrupted(errorInfo, fdv1Fallback, null, completionCallback); | ||
| } | ||
|
|
||
| public static FDv2SourceResult interrupted(DataSourceStatusProvider.ErrorInfo errorInfo, boolean fdv1Fallback, Duration fdv1FallbackTTL, Function<Void, Void> completionCallback) { |
There was a problem hiding this comment.
I think a more future-proof design might be to replace boolean fdv1Fallback, Duration fdv1FallbackTT with a new nullable FDv1Fallback object that contains a Duration ttl. That way, if the format changes in the future, we don't have to change all the interfaces.
There was a problem hiding this comment.
Done in 71beeaa. There's a new datasources.FDv1Fallback, holding a nullable Duration ttl. The FDv2SourceResult factories now take a nullable FDv1Fallback in place of the boolean, where null means no directive, so the extra TTL overloads are gone. getFdv1Fallback() returns the directive, and isFdv1Fallback() remains as a != null shorthand.
Co-Authored-By: Bee Klimt <bklimt@launchdarkly.com>
Co-Authored-By: Bee Klimt <bklimt@launchdarkly.com>
There was a problem hiding this comment.
Risk: medium.
Automated risk review (dry run): Medium
This PR would not be automatically approved. Human approval required.
Why: This changes FDv1 fallback TTL handling in the Java server SDK data source (FDv2DataSource, PollingBase, StreamingSynchronizerImpl, HeaderConstants, and experimental FDv2SourceResult/FDv1Fallback), a protocol-behavior change across polling, streaming, initializer, and synchronizer paths. Tests cover the new TTL rules, but the blast radius is more than a narrow low-risk edit.
Human review is needed and no reviewers were assigned.
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
| @@ -0,0 +1,30 @@ | |||
| package com.launchdarkly.sdk.server.datasources; | |||
|
|
|||
| import java.time.Duration; | |||
There was a problem hiding this comment.
This is probably fine in server, but we did recently make a PR to change one of these in internal or common. Because it isn't in the android API level that we use. But I wonder if we want to just not use java.time.Duration, or we just avoid it in the common libraries.
There was a problem hiding this comment.
This is only in the server SDK, which already uses java.time.Duration in 33 main source files on main, including the existing defaultFDv1FallbackTTL. The goodbye TTL comes from the internal lib as nullable Long millis, as of #273, and is converted to a Duration only here. As far as I can tell, lib/shared/common and lib/shared/internal have no java.time.Duration left. So "avoid it in the common libraries" seems to be the rule today, and this PR follows it. I'll leave it as is unless you'd like the server SDK to avoid it too.
There was a problem hiding this comment.
aside: I've seen so many bugs from code that disagreed about whether a Long was seconds or millis, I'm inclined to use Duration where we can. But I know we don't want to require desugaring in Android, so... well, I'll deal either way.
| ); | ||
| // For initializers, file errors are terminal. For synchronizers, they are recoverable. | ||
| return FDv2SourceResult.interrupted(errorInfo, false); | ||
| return FDv2SourceResult.interrupted(errorInfo, null); |
There was a problem hiding this comment.
I am not convinced of the comment I am making, but it is worth consideration. Should we have some FDv1Fallback.None() or something instead of null?
There was a problem hiding this comment.
I went with null because:
FDv2SourceResult.isFdv1Fallback()already wraps the null check, so callers don't touch null directly.- A
NONEsentinel would need its own "is this a fallback?" flag, or an identity check against the sentinel. That brings back the separate boolean this object replaced.
The cost is that any caller using getFdv1Fallback() has to null-check it, and missing that check isn't caught at compile time. Today the only one is FDv2DataSource, and only after isFdv1Fallback(). I could also return Optional<FDv1Fallback> from the getter, since this is server-only so Android isn't a concern. I'll leave it as is unless you or Bee would prefer one of those.
There was a problem hiding this comment.
Correction to my reply above: FileInitializer also calls getFdv1Fallback(), but it only passes the value on to a new result and never dereferences it. FDv2DataSource is still the only place that reads it.
There was a problem hiding this comment.
aside: I don't feel strongly about this, but None() doesn't feel very idiomatic Java to me. Optional would be fine, if you prefer it to null checking.


Requirements
Related issues
Closes SDK-2987. Follows #265 and #273, the goodbye TTL parsing in
java-sdk-internal1.13.1. Spec: DATASYSTEM 1.6 (sdk-specs#251).Describe the solution you've provided
Previously the server SDK always used the jittered 1h default as the FDv1 fallback TTL. It now uses the TTL the server sends.
X-LD-FD-Fallback-TTLfrom the response that carriesX-LD-FD-Fallback, for both polling and streaming.goodbyethat hasprotocolFallbackTTLis now itself a fallback directive, and its TTL takes precedence over the header's.(0, 1h]is used as-is, with no jitter. A missing, malformed, zero, negative, or >1h TTL uses the jittered 1h default.FDv2SourceResult(experimental package) now carries a nullableFDv1Fallbackdirective, with a nullablegetTtl(), in place of theboolean fdv1Fallback.Implementation details
launchdarklyJavaSdkInternalfrom 1.13.0 to 1.13.1, which providesFDv2ActionGoodbye.getProtocolFallbackTTLMillis().HeaderConstants. A non-integer value gives a directive with a null TTL, which means the default.(0, 1h]check and the jitter live in one place,FDv2DataSource.fallbackTTL(Duration).InitializerOutcomenow carries the directive.false(file data source,TestDataV2,DataSourceSynchronizerAdapter) now passnull../gradlew test checkstyleMain checkstyleTestpasses inlib/sdk/server.Link to Devin session: https://app.devin.ai/sessions/cce64c67519f4babaa75176c06961c5e
Open in Devin Desktop: https://app.devin.ai/desktop/session/cce64c67519f4babaa75176c06961c5e?variant=devin
Requested by: @beekld
Note
Overview
Replaces the FDv1 fallback boolean with a structured
FDv1Fallbackdirective (optional TTL) onFDv2SourceResult, and honors server-provided TTL when switching to FDv1.Polling and streaming now read
X-LD-FD-Fallback-TTLalongsideX-LD-FD-Fallback, andgoodbyeevents withprotocolFallbackTTLcan carry the directive with TTL taking precedence over headers.FDv2DataSource.fallbackTTLuses server TTL when it is in (0, 1h] without jitter; otherwise it keeps the jittered default (~1h). That logic applies on initializer fallback, synchronizer fallback, and when a new directive arrives during an active FDv1 fallback run (replacing the remaining TTL). Call sites that meant “no directive” now passnullinstead offalse. Tests cover header/goodbye parsing, TTL validation, directive survival through result copies, and end-to-end fallback timing.Reviewed by Cursor Bugbot for commit a4151c3. Bugbot is set up for automated code reviews on this repo. Configure here.