Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UpdatePartitionState to avoid restarting Producer #375

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -178,6 +178,20 @@ private void initializeStateForPartitions(int partitionNum) {
}
_partitionNum.set(partitionNum);
}

private void updateStateForPartitions(int partitionNum) {
Map<Integer, String> keyMapping = generateKeyMappings(partitionNum);
for (int partition = 0; partition < partitionNum; partition++) {
String key = keyMapping.get(partition);
/* This is what preserves sequence numbers across restarts */
if (!_nextIndexPerPartition.containsKey(partition)) {
_nextIndexPerPartition.put(partition, new AtomicLong(0));
_sensors.addPartitionSensors(partition);
_produceExecutor.scheduleWithFixedDelay(new ProduceRunnable(partition, key), _produceDelayMs, _produceDelayMs, TimeUnit.MILLISECONDS);
}
}
_partitionNum.set(partitionNum);
}

private Map<Integer, String> generateKeyMappings(int partitionNum) {
HashMap<Integer, String> keyMapping = new HashMap<>();
Expand Down Expand Up @@ -280,7 +294,7 @@ public void run() {
}
LOG.info("{}/ProduceService detected new partitions of topic {}", _name, _topic);
//TODO: Should the ProduceService exit if we can't restart the producer runnables?
_produceExecutor.shutdown();
/* _produceExecutor.shutdown();
try {
_produceExecutor.awaitTermination(Integer.MAX_VALUE, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Expand All @@ -295,6 +309,8 @@ public void run() {
}
_produceExecutor = Executors.newScheduledThreadPool(_threadsNum);
initializeStateForPartitions(currentPartitionNum);
*/
updateStateForPartitions(currentPartitionNum);
LOG.info("New partitions added to monitoring.");
} catch (InterruptedException e) {
LOG.error("InterruptedException occurred.", e);
Expand Down