Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ public class IndexCDCConsumer implements Runnable {
"phoenix.index.cdc.consumer.poll.interval.ms";
private static final long DEFAULT_POLL_INTERVAL_MS = 500;

/**
* The interval in milliseconds between polls when the previous poll found no new events.
*/
public static final String INDEX_CDC_CONSUMER_IDLE_POLL_INTERVAL_MS =
"phoenix.index.cdc.consumer.idle.poll.interval.ms";
private static final long DEFAULT_IDLE_POLL_INTERVAL_MS = 4000;

/**
* The time buffer in milliseconds subtracted from current time when querying CDC mutations to
* help avoid reading mutations that are too recent.
Expand Down Expand Up @@ -157,6 +164,7 @@ public class IndexCDCConsumer implements Runnable {
private final long startupDelayMs;
private final int batchSize;
private final long pollIntervalMs;
private final long idlePollIntervalMs;
private final long timestampBufferMs;
private final int maxDataVisibilityRetries;
private final long parentProgressPauseMs;
Expand Down Expand Up @@ -237,6 +245,10 @@ public IndexCDCConsumer(RegionCoprocessorEnvironment env, String dataTableName,
this.batchSize = baseBatchSize + jitter;
this.pollIntervalMs =
config.getLong(INDEX_CDC_CONSUMER_POLL_INTERVAL_MS, DEFAULT_POLL_INTERVAL_MS);
long baseIdlePollInterval =
config.getLong(INDEX_CDC_CONSUMER_IDLE_POLL_INTERVAL_MS, DEFAULT_IDLE_POLL_INTERVAL_MS);
this.idlePollIntervalMs =
baseIdlePollInterval + ThreadLocalRandom.current().nextLong(baseIdlePollInterval / 5 + 1);
this.timestampBufferMs =
config.getLong(INDEX_CDC_CONSUMER_TIMESTAMP_BUFFER_MS, DEFAULT_TIMESTAMP_BUFFER_MS);
this.maxDataVisibilityRetries = config.getInt(INDEX_CDC_CONSUMER_MAX_DATA_VISIBILITY_RETRIES,
Expand Down Expand Up @@ -449,11 +461,11 @@ public void run() {
lagEmissionEnabled = true;
LOG.info(
"IndexCDCConsumer started for table {} region {}"
+ " [batchSize: {}, pollIntervalMs: {}, timestampBufferMs: {}, startupDelayMs: {},"
+ " pause: {}, maxDataVisibilityRetries: {}, parentProgressPauseMs: {},"
+ " serializeCDCMutations: {}]",
dataTableName, encodedRegionName, batchSize, pollIntervalMs, timestampBufferMs,
startupDelayMs, pause, maxDataVisibilityRetries, parentProgressPauseMs,
+ " [batchSize: {}, pollIntervalMs: {}, idlePollIntervalMs: {}, timestampBufferMs: {},"
+ " startupDelayMs: {}, pause: {}, maxDataVisibilityRetries: {},"
+ " parentProgressPauseMs: {}, serializeCDCMutations: {}]",
dataTableName, encodedRegionName, batchSize, pollIntervalMs, idlePollIntervalMs,
timestampBufferMs, startupDelayMs, pause, maxDataVisibilityRetries, parentProgressPauseMs,
serializeCDCMutations);
if (!waitForCDCStreamEntry()) {
LOG.error(
Expand Down Expand Up @@ -502,10 +514,10 @@ public void run() {
lastProcessedTimestamp = processCDCBatchGenerated(encodedRegionName,
encodedRegionName, lastProcessedTimestamp, false);
}
retryCount = 0;
if (lastProcessedTimestamp == previousTimestamp) {
sleepWithLagSampling(ConnectionUtils.getPauseTime(pause, ++retryCount));
sleepWithLagSampling(idlePollIntervalMs);
} else {
retryCount = 0;
sleepWithLagSampling(pollIntervalMs);
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public class IndexCDCConsumerLagIT extends ParallelStatsDisabledIT {
private static final int TIMESTAMP_BUFFER_MS = 2_000;
private static final int POLL_INTERVAL_MS = 500;
private static final int LAG_SAMPLE_INTERVAL_MS = 500;
// Small retry pause so empty-poll backoff doesn't dominate idle behavior.
private static final int RETRY_PAUSE_MS = 100;
// Budget for the consumer to start up and emit its first lag sample. Generous because the
// consumer waits up to INDEX_CDC_CONSUMER_STARTUP_DELAY_MS (default 10s) and then performs
Expand Down