Skip to content

Commit

Permalink
Revert memq consumer reset logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemTetenkin committed Apr 23, 2024
1 parent cf31c8d commit e53ad97
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 86 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,10 @@
import com.pinterest.psc.metrics.MetricName;
import com.pinterest.psc.metrics.PscMetricRegistryManager;
import com.pinterest.psc.metrics.PscMetrics;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.commons.logging.Log;
import software.amazon.awssdk.core.exception.SdkClientException;

import java.io.IOException;
import java.time.Duration;
Expand Down Expand Up @@ -277,11 +273,7 @@ public PscConsumerPollMessageIterator<K, V> poll(Duration pollTimeout) throws Co
CloseableIterator<MemqLogMessage<byte[], byte[]>> memqLogMessageIterator;
try {
MutableInt count = new MutableInt();
if (pscConfigurationInternal.isAutoResolutionEnabled()) {
memqLogMessageIterator = preFetchPollResultIntoMemoryWithAutoResolution(memqConsumer.poll(pollTimeout, count));
} else {
memqLogMessageIterator = new MemqIteratorAdapter<>(memqConsumer.poll(pollTimeout, count));
}
memqLogMessageIterator = new MemqIteratorAdapter<>(memqConsumer.poll(pollTimeout, count));
} catch (NoTopicsSubscribedException e) {
throw new ConsumerException("[Memq] Consumer is not subscribed to any topic.", e);
} catch (IOException e) {
Expand All @@ -301,52 +293,6 @@ memqLogMessageIterator, backendTopicToTopicUri, getConsumerInterceptors(),
initialSeekOffsets);
}

private MemqPreFetchIteratorAdapter<MemqLogMessage<byte[], byte[]>> preFetchPollResultIntoMemoryWithAutoResolution(com.pinterest.memq.commons.CloseableIterator<MemqLogMessage<byte[], byte[]>> it) {
List<MemqLogMessage<byte[], byte[]>> preFetched = new ArrayList<>();
int count = 0;
while (it.hasNext()) {
try {
preFetched.add(it.next());
count++;
} catch (SdkClientException e) {
logger.warn("Error while pre-fetching messages, " +
"resetting backend MemQ consumer and returning " + count + " messages in iterator for now", e);
try {
it.close();
resetBackendClient();
break;
} catch (ConsumerException | IOException ex) {
throw new RuntimeException("Failed to reset backend Memq consumer", ex);
}
}
}
return new MemqPreFetchIteratorAdapter<>(preFetched);

}

protected void resetBackendClient() throws ConsumerException {
super.resetBackendClient();
executeBackendCallWithRetries(() -> {
try {
memqConsumer.close();
} catch (IOException e) {
throw new RuntimeException("Failed to close Memq consumer instance.", e);
}
});

try {
memqConsumer = new MemqConsumer<>(properties);
} catch (Exception e) {
throw new RuntimeException("Unable to instantiate a Memq consumer instance.", e);
}

if (!currentAssignment.isEmpty())
assign(currentAssignment);
else if (!currentSubscription.isEmpty())
subscribe(currentSubscription);

}

private void handleMemqConsumerMetrics(MetricRegistry metricRegistry) {

}
Expand Down

0 comments on commit e53ad97

Please sign in to comment.