Skip to content
Merged
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
2 changes: 1 addition & 1 deletion core/src/main/scala/kafka/network/SocketServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ private[kafka] class Processor(
// AutoMQ will pipeline the requests to accelerate the performance and also keep the request order.

// Mute the channel if the inflight requests exceed the threshold.
if (channelContext.nextCorrelationId.size() >= 64 && !channel.isMuted) {
if (channelContext.nextCorrelationId.size() >= SocketServerConfigs.MAX_INFLIGHT_REQUESTS_PER_CONNECTION && !channel.isMuted) {
if (isTraceEnabled) {
trace(s"Mute channel ${channel.id} because the inflight requests exceed the threshold, inflight count is ${channelContext.nextCorrelationId.size()}.")
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/scala/kafka/server/ReplicaManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import java.nio.file.{Files, Paths}
import java.util
import java.util.concurrent.atomic.{AtomicBoolean, AtomicLong}
import java.util.concurrent.locks.Lock
import java.util.concurrent.{ArrayBlockingQueue, CompletableFuture, Future, RejectedExecutionException, TimeUnit}
import java.util.concurrent.{CompletableFuture, Future, LinkedBlockingQueue, RejectedExecutionException, TimeUnit}
import java.util.{Collections, Optional, OptionalInt, OptionalLong}
import scala.collection.{Map, Seq, Set, mutable}
import scala.compat.java8.OptionConverters._
Expand Down Expand Up @@ -942,7 +942,8 @@ class ReplicaManager(val config: KafkaConfig,

case class Verification(
hasInflight: AtomicBoolean,
waitingRequests: ArrayBlockingQueue[TransactionVerificationRequest],
// Use an unbounded queue to prevent deadlock from happening. See https://github.com/AutoMQ/automq/issues/2902
waitingRequests: LinkedBlockingQueue[TransactionVerificationRequest],
timestamp: AtomicLong,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@ class ElasticReplicaManager(
transactionWaitingForValidationMap.computeIfAbsent(producerId, _ => {
Verification(
new AtomicBoolean(false),
new ArrayBlockingQueue[TransactionVerificationRequest](5),
new LinkedBlockingQueue[TransactionVerificationRequest](),
new AtomicLong(time.milliseconds()))
})
} else {
Expand Down Expand Up @@ -1474,17 +1474,20 @@ class ElasticReplicaManager(
error("Error in transaction verification callback", e)
}
if (verification != null) {
var request: TransactionVerificationRequest = null
verification.synchronized {
verification.timestamp.set(time.milliseconds())
if (!verification.waitingRequests.isEmpty) {
// Since the callback thread and task thread may be different, we need to ensure that the tasks are executed sequentially.
val request = verification.waitingRequests.poll()
request.task()
request = verification.waitingRequests.poll()
} else {
// If there are no tasks in the queue, set hasInflight to false
verification.hasInflight.set(false)
}
}
if (request != null) {
request.task()
}
val lastCleanTimestamp = lastTransactionCleanTimestamp.get();
val now = time.milliseconds()
if (now - lastCleanTimestamp > 60 * 1000 && lastTransactionCleanTimestamp.compareAndSet(lastCleanTimestamp, now)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ public class SocketServerConfigs {
public static final int NUM_NETWORK_THREADS_DEFAULT = 3;
public static final String NUM_NETWORK_THREADS_DOC = "The number of threads that the server uses for receiving requests from the network and sending responses to the network. Noted: each listener (except for controller listener) creates its own thread pool.";

// AutoMQ inject start
public static final int MAX_INFLIGHT_REQUESTS_PER_CONNECTION = 64;
// AutoMQ inject end

public static final ConfigDef CONFIG_DEF = new ConfigDef()
.define(LISTENERS_CONFIG, STRING, LISTENERS_DEFAULT, HIGH, LISTENERS_DOC)
.define(ADVERTISED_LISTENERS_CONFIG, STRING, null, HIGH, ADVERTISED_LISTENERS_DOC)
Expand Down
Loading