kfaraz commented on code in PR #14468:
URL: https://github.com/apache/druid/pull/14468#discussion_r1247510317
##########
server/src/main/java/org/apache/druid/server/coordination/ChangeRequestHttpSyncer.java:
##########
@@ -157,56 +176,85 @@ public void stop()
}
}
- /** Wait for first fetch of segment listing from server. */
- public boolean awaitInitialization(long timeout, TimeUnit timeUnit) throws
InterruptedException
+ /**
+ * Waits for the first successful sync with this server up to .
+ */
+ public boolean awaitInitialization() throws InterruptedException
{
- return initializationLatch.await(timeout, timeUnit);
+ return initializationLatch.await(maxMillisToWaitForSync,
TimeUnit.MILLISECONDS);
}
/**
- * This method returns the debugging information for printing, must not be
used for any other purpose.
+ * Waits upto 1 milliseconds for the first successful sync with this server.
*/
- public Map<String, Object> getDebugInfo()
+ public boolean isInitialized() throws InterruptedException
{
- long currTime = System.currentTimeMillis();
+ return initializationLatch.await(1, TimeUnit.MILLISECONDS);
+ }
- Object notSuccessfullySyncedFor;
- if (lastSuccessfulSyncTime == 0) {
- notSuccessfullySyncedFor = "Never Successfully Synced";
- } else {
- notSuccessfullySyncedFor = (currTime - lastSuccessfulSyncTime) / 1000;
- }
+ /**
+ * Returns debugging information for printing, must not be used for any
other purpose.
+ */
+ public Map<String, Object> getDebugInfo()
+ {
return ImmutableMap.of(
- "notSyncedForSecs", lastSyncTime == 0 ? "Never Synced" : (currTime -
lastSyncTime) / 1000,
- "notSuccessfullySyncedFor", notSuccessfullySyncedFor,
- "consecutiveFailedAttemptCount", consecutiveFailedAttemptCount,
+ "millisSinceLastSync",
+ sinceLastSyncRequest.isRunning() ?
DateTimes.millisElapsed(sinceLastSyncRequest) : "Never synced",
+ "millisSinceLastSuccess",
+ sinceLastSyncSuccess.isRunning() ?
DateTimes.millisElapsed(sinceLastSyncSuccess) : "Never synced successfully",
+ "millisUnstableDuration",
+ sinceUnstable.isRunning() ? DateTimes.millisElapsed(sinceUnstable) :
"Stable",
+ "numRecentFailures", numRecentFailures,
"syncScheduled", startStopLock.isStarted()
);
}
+ private boolean hasSyncedSuccessfullyOnce()
+ {
+ return initializationLatch.getCount() <= 0;
+ }
+
/**
- * Exposed for monitoring use to see if sync is working fine and not stopped
due to any coding bugs. If this
- * ever returns false then caller of this method must create an alert and it
should be looked into for any
- * bugs.
+ * Whether this syncer should be reset. This method returning true typically
+ * indicates a problem with the sync scheduler.
+ *
+ * @return true if the delay since the last sync request sent to the server
+ * has exceeded {@link #maxDelayBetweenSyncRequests}, false otherwise.
*/
- public boolean isOK()
+ public boolean needsReset()
{
- return (System.currentTimeMillis() - lastSyncTime) < MAX_RETRY_BACKOFF + 3
* serverHttpTimeout;
+ return DateTimes.hasElapsed(maxDelayBetweenSyncRequests,
sinceLastSyncRequest);
+ }
+
+ /**
+ * @return true if there have been no sync failures recently and the last
+ * successful sync was not more than {@link #maxMillisToWaitForSync} ago.
+ */
+ public boolean isSyncedSuccessfully()
+ {
+ final Duration timeoutDuration = Duration.millis(maxMillisToWaitForSync);
+ if (numRecentFailures > 0) {
+ return false;
+ } else if (hasSyncedSuccessfullyOnce()) {
+ return DateTimes.hasNotElapsed(timeoutDuration, sinceLastSyncSuccess);
+ } else {
+ return DateTimes.hasNotElapsed(timeoutDuration, sinceSyncerStart);
Review Comment:
Yeah, good point. I will rename the method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]