You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "gongxuanzhang (via GitHub)" <gi...@apache.org> on 2025/03/18 09:24:30 UTC
[PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
gongxuanzhang opened a new pull request, #19226:
URL: https://github.com/apache/kafka/pull/19226
move DeleteRecordsPartitionStatus.scala to server-common module.
scala --> java
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on PR #19226:
URL: https://github.com/apache/kafka/pull/19226#issuecomment-2783221120
`RemoteLogManager` only uses `DelayedRemoteListOffsets` hence why we put that in the `storage` module. But as far as I can tell other purgatory code could be in `server`.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #19226:
URL: https://github.com/apache/kafka/pull/19226#discussion_r2021394324
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedDeleteRecords.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.purgatory;
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData.DeleteRecordsPartitionResult;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+/**
+ * A delayed delete records operation that can be created by the replica manager and watched
+ * in the delete records operation purgatory
+ */
+public class DelayedDeleteRecords extends DelayedOperation {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DelayedDeleteRecords.class);
+
+ // migration from kafka.server.DelayedDeleteRecordsMetrics
+ private static final KafkaMetricsGroup METRICS_GROUP = new KafkaMetricsGroup("kafka.server", "DelayedDeleteRecordsMetrics");
+ private static final Meter AGGREGATE_EXPIRATION_METER = METRICS_GROUP.newMeter("ExpiresPerSec", "requests",
+ TimeUnit.SECONDS);
+
+ private final Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus;
+ private final BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending;
+ private final Consumer<Map<TopicPartition, DeleteRecordsPartitionResult>> responseCallback;
+
+ public DelayedDeleteRecords(long delayMs,
+ Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus,
+ // To maintain compatibility with dependency packages, the logic has been moved to the caller.
+ BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending,
+ Consumer<Map<TopicPartition, DeleteRecordsPartitionResult>> responseCallback) {
+ super(delayMs);
+ this.onAcksPending = onAcksPending;
+ this.deleteRecordsStatus = Collections.unmodifiableMap(deleteRecordsStatus);
+ this.responseCallback = responseCallback;
+ // first update the acks pending variable according to the error code
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ if (status.responseStatus().errorCode() == Errors.NONE.code()) {
+ // Timeout error state will be cleared when required acks are received
+ status.setAcksPending(true);
+ status.responseStatus().setErrorCode(Errors.REQUEST_TIMED_OUT.code());
+ } else {
+ status.setAcksPending(false);
+ }
+ });
+ }
+
+ /**
+ * The delayed delete records operation can be completed if every partition specified in the request satisfied one of the following:
+ *
+ * 1) There was an error while checking if all replicas have caught up to the deleteRecordsOffset: set an error in response
+ * 2) The low watermark of the partition has caught up to the deleteRecordsOffset. set the low watermark in response
+ *
+ */
+ @Override
+ public boolean tryComplete() {
+ // check for each partition if it still has pending acks
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ LOG.trace("Checking delete records satisfaction for {}, current status {}", topicPartition, status);
+ // skip those partitions that have already been satisfied
+ if (status.acksPending()) {
+ onAcksPending.accept(topicPartition, status);
+ }
+ });
+ // check if every partition has satisfied at least one of case A or B
+ return deleteRecordsStatus.values().stream().noneMatch(DeleteRecordsPartitionStatus::acksPending) && forceComplete();
+ }
+
+ @Override
+ public void onExpiration() {
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
Review Comment:
@gongxuanzhang WDYT?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "gongxuanzhang (via GitHub)" <gi...@apache.org>.
gongxuanzhang commented on code in PR #19226:
URL: https://github.com/apache/kafka/pull/19226#discussion_r2009028990
##########
server-common/src/main/java/org/apache/kafka/server/common/DelayedDeleteRecords.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData.DeleteRecordsPartitionResult;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+import org.apache.kafka.server.purgatory.DelayedOperation;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+/**
+ * A delayed delete records operation that can be created by the replica manager and watched
+ * in the delete records operation purgatory
+ */
+public class DelayedDeleteRecords extends DelayedOperation {
+
+ private static final Logger log = LoggerFactory.getLogger(DelayedDeleteRecords.class);
+
+ // migration from kafka.server.DelayedDeleteRecordsMetrics
+ private static final KafkaMetricsGroup METRICS_GROUP = new KafkaMetricsGroup("kafka.server", "DelayedDeleteRecordsMetrics");
+ private static final Meter AGGREGATE_EXPIRATION_METER = METRICS_GROUP.newMeter("ExpiresPerSec", "requests",
+ TimeUnit.SECONDS);
+
+ private final Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus;
+ private final BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending;
+ private final Consumer<Map<TopicPartition, DeleteRecordsPartitionResult>> responseCallback;
+
+ public DelayedDeleteRecords(long delayMs,
+ Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus,
+ // To maintain compatibility with dependency packages, the logic has been moved to the caller.
+ BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending,
+ Consumer<Map<TopicPartition, DeleteRecordsPartitionResult>> responseCallback) {
+ super(delayMs);
+ this.onAcksPending = onAcksPending;
+ this.deleteRecordsStatus = new ConcurrentHashMap<>(deleteRecordsStatus);
Review Comment:
I'll make it immutable and avoid copying. Thanks
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #19226:
URL: https://github.com/apache/kafka/pull/19226#discussion_r2008109446
##########
server-common/src/main/java/org/apache/kafka/server/common/DelayedDeleteRecords.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData.DeleteRecordsPartitionResult;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+import org.apache.kafka.server.purgatory.DelayedOperation;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+/**
+ * A delayed delete records operation that can be created by the replica manager and watched
+ * in the delete records operation purgatory
+ */
+public class DelayedDeleteRecords extends DelayedOperation {
+
+ private static final Logger log = LoggerFactory.getLogger(DelayedDeleteRecords.class);
Review Comment:
`LOG`
##########
server-common/src/main/java/org/apache/kafka/server/common/DelayedDeleteRecords.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData.DeleteRecordsPartitionResult;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+import org.apache.kafka.server.purgatory.DelayedOperation;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+/**
+ * A delayed delete records operation that can be created by the replica manager and watched
+ * in the delete records operation purgatory
+ */
+public class DelayedDeleteRecords extends DelayedOperation {
+
+ private static final Logger log = LoggerFactory.getLogger(DelayedDeleteRecords.class);
+
+ // migration from kafka.server.DelayedDeleteRecordsMetrics
+ private static final KafkaMetricsGroup METRICS_GROUP = new KafkaMetricsGroup("kafka.server", "DelayedDeleteRecordsMetrics");
+ private static final Meter AGGREGATE_EXPIRATION_METER = METRICS_GROUP.newMeter("ExpiresPerSec", "requests",
+ TimeUnit.SECONDS);
+
+ private final Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus;
+ private final BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending;
+ private final Consumer<Map<TopicPartition, DeleteRecordsPartitionResult>> responseCallback;
+
+ public DelayedDeleteRecords(long delayMs,
+ Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus,
+ // To maintain compatibility with dependency packages, the logic has been moved to the caller.
+ BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending,
+ Consumer<Map<TopicPartition, DeleteRecordsPartitionResult>> responseCallback) {
+ super(delayMs);
+ this.onAcksPending = onAcksPending;
+ this.deleteRecordsStatus = new ConcurrentHashMap<>(deleteRecordsStatus);
Review Comment:
why to copy `deleteRecordsStatus`? it is immutable, right?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #19226:
URL: https://github.com/apache/kafka/pull/19226#discussion_r2020587635
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -1282,8 +1281,31 @@ class ReplicaManager(val config: KafkaConfig,
}
if (delayedDeleteRecordsRequired(localDeleteRecordsResults)) {
+ def onAcks(topicPartition: TopicPartition, status: DeleteRecordsPartitionStatus): Unit = {
+ val (lowWatermarkReached, error, lw) = getPartition(topicPartition) match {
+ case HostedPartition.Online(partition) =>
+ partition.leaderLogIfLocal match {
+ case Some(_) =>
+ val leaderLW = partition.lowWatermarkIfLeader
+ (leaderLW >= status.requiredOffset, Errors.NONE, leaderLW)
+ case None =>
+ (false, Errors.NOT_LEADER_OR_FOLLOWER, DeleteRecordsResponse.INVALID_LOW_WATERMARK)
+ }
+
+ case HostedPartition.Offline(_) =>
+ (false, Errors.KAFKA_STORAGE_ERROR, DeleteRecordsResponse.INVALID_LOW_WATERMARK)
+
+ case HostedPartition.None =>
+ (false, Errors.UNKNOWN_TOPIC_OR_PARTITION, DeleteRecordsResponse.INVALID_LOW_WATERMARK)
+ }
+ if (error != Errors.NONE || lowWatermarkReached) {
+ status.setAcksPending(false)
+ status.responseStatus.setErrorCode(error.code)
+ status.responseStatus.setLowWatermark(lw)
+ }
+ }
// create delayed delete records operation
- val delayedDeleteRecords = new DelayedDeleteRecords(timeout, deleteRecordsStatus, this, responseCallback)
+ val delayedDeleteRecords = new DelayedDeleteRecords(timeout, deleteRecordsStatus.asJava, onAcks , response => responseCallback(response.asScala))
Review Comment:
`sJava, onAcks , response =` -> `sJava, onAcks, response =`
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedDeleteRecords.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.purgatory;
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData.DeleteRecordsPartitionResult;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+/**
+ * A delayed delete records operation that can be created by the replica manager and watched
+ * in the delete records operation purgatory
+ */
+public class DelayedDeleteRecords extends DelayedOperation {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DelayedDeleteRecords.class);
+
+ // migration from kafka.server.DelayedDeleteRecordsMetrics
+ private static final KafkaMetricsGroup METRICS_GROUP = new KafkaMetricsGroup("kafka.server", "DelayedDeleteRecordsMetrics");
+ private static final Meter AGGREGATE_EXPIRATION_METER = METRICS_GROUP.newMeter("ExpiresPerSec", "requests",
+ TimeUnit.SECONDS);
+
+ private final Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus;
+ private final BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending;
+ private final Consumer<Map<TopicPartition, DeleteRecordsPartitionResult>> responseCallback;
+
+ public DelayedDeleteRecords(long delayMs,
+ Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus,
+ // To maintain compatibility with dependency packages, the logic has been moved to the caller.
+ BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending,
+ Consumer<Map<TopicPartition, DeleteRecordsPartitionResult>> responseCallback) {
+ super(delayMs);
+ this.onAcksPending = onAcksPending;
+ this.deleteRecordsStatus = Collections.unmodifiableMap(deleteRecordsStatus);
+ this.responseCallback = responseCallback;
+ // first update the acks pending variable according to the error code
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ if (status.responseStatus().errorCode() == Errors.NONE.code()) {
+ // Timeout error state will be cleared when required acks are received
+ status.setAcksPending(true);
+ status.responseStatus().setErrorCode(Errors.REQUEST_TIMED_OUT.code());
+ } else {
+ status.setAcksPending(false);
+ }
+ });
+ }
+
+ /**
+ * The delayed delete records operation can be completed if every partition specified in the request satisfied one of the following:
+ *
+ * 1) There was an error while checking if all replicas have caught up to the deleteRecordsOffset: set an error in response
+ * 2) The low watermark of the partition has caught up to the deleteRecordsOffset. set the low watermark in response
+ *
+ */
+ @Override
+ public boolean tryComplete() {
+ // check for each partition if it still has pending acks
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ LOG.trace("Checking delete records satisfaction for {}, current status {}", topicPartition, status);
+ // skip those partitions that have already been satisfied
+ if (status.acksPending()) {
+ onAcksPending.accept(topicPartition, status);
+ }
+ });
+ // check if every partition has satisfied at least one of case A or B
+ return deleteRecordsStatus.values().stream().noneMatch(DeleteRecordsPartitionStatus::acksPending) && forceComplete();
+ }
+
+ @Override
+ public void onExpiration() {
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
Review Comment:
```java
AGGREGATE_EXPIRATION_METER.mark(deleteRecordsStatus.values().stream().filter(DeleteRecordsPartitionStatus::acksPending).count());
```
##########
core/src/main/scala/kafka/server/DelayedDeleteRecords.scala:
##########
@@ -1,134 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package kafka.server
-
-
-import kafka.utils.Logging
-
-import java.util.concurrent.TimeUnit
-import org.apache.kafka.common.TopicPartition
-import org.apache.kafka.common.message.DeleteRecordsResponseData
-import org.apache.kafka.common.protocol.Errors
-import org.apache.kafka.common.requests.DeleteRecordsResponse
-import org.apache.kafka.server.metrics.KafkaMetricsGroup
-import org.apache.kafka.server.purgatory.DelayedOperation
-
-import scala.collection._
-
-
-case class DeleteRecordsPartitionStatus(requiredOffset: Long,
- responseStatus: DeleteRecordsResponseData.DeleteRecordsPartitionResult) {
- @volatile var acksPending = false
-
- override def toString: String = "[acksPending: %b, error: %s, lowWatermark: %d, requiredOffset: %d]"
- .format(acksPending, Errors.forCode(responseStatus.errorCode).toString, responseStatus.lowWatermark, requiredOffset)
-}
-
-/**
- * A delayed delete records operation that can be created by the replica manager and watched
- * in the delete records operation purgatory
- */
-class DelayedDeleteRecords(delayMs: Long,
- deleteRecordsStatus: Map[TopicPartition, DeleteRecordsPartitionStatus],
- replicaManager: ReplicaManager,
- responseCallback: Map[TopicPartition, DeleteRecordsResponseData.DeleteRecordsPartitionResult] => Unit)
- extends DelayedOperation(delayMs) with Logging {
-
- // first update the acks pending variable according to the error code
- deleteRecordsStatus.foreachEntry { (topicPartition, status) =>
- if (status.responseStatus.errorCode == Errors.NONE.code) {
- // Timeout error state will be cleared when required acks are received
- status.acksPending = true
- status.responseStatus.setErrorCode(Errors.REQUEST_TIMED_OUT.code)
- } else {
- status.acksPending = false
- }
-
- trace("Initial partition status for %s is %s".format(topicPartition, status))
Review Comment:
please keep this log
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #19226:
URL: https://github.com/apache/kafka/pull/19226#discussion_r2016093160
##########
server-common/src/main/java/org/apache/kafka/server/common/DelayedDeleteRecords.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
Review Comment:
+1 to `org.apache.kafka.server.purgatory`
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st commented on code in PR #19226:
URL: https://github.com/apache/kafka/pull/19226#discussion_r2001136334
##########
server-common/src/main/java/org/apache/kafka/server/common/DeleteRecordsPartitionStatus.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
+
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+import org.apache.kafka.server.purgatory.DelayedOperation;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+public class DeleteRecordsPartitionStatus {
+ private final long requiredOffset;
+ private final DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus;
+ private volatile boolean acksPending;
+
+ public DeleteRecordsPartitionStatus(long requiredOffset,
+ DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus) {
+ this.requiredOffset = requiredOffset;
+ this.responseStatus = responseStatus;
+ this.acksPending = false;
+ }
+
+ public boolean isAcksPending() {
+ return acksPending;
+ }
+
+ public void setAcksPending(boolean acksPending) {
+ this.acksPending = acksPending;
+ }
+
+
+ public DeleteRecordsResponseData.DeleteRecordsPartitionResult getResponseStatus() {
+ return responseStatus;
+ }
+
+ public long getRequiredOffset() {
+ return requiredOffset;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("[acksPending: %b, error: %s, lowWatermark: %d, requiredOffset: %d]",
+ acksPending, Errors.forCode(responseStatus.errorCode()).toString(), responseStatus.lowWatermark(),
+ requiredOffset);
+ }
+
+ /**
+ * A delayed delete records operation that can be created by the replica manager and watched
+ * in the delete records operation purgatory
+ */
+ public static class DelayedDeleteRecords extends DelayedOperation {
+ private final Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus;
+ private final BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending;
+ private final Consumer<Map<TopicPartition, DeleteRecordsResponseData.DeleteRecordsPartitionResult>> responseCallback;
+ private static final Logger log = LoggerFactory.getLogger(DelayedDeleteRecords.class);
+
+ public DelayedDeleteRecords(long delayMs,
+ Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus,
+ // To maintain compatibility with dependency packages, the logic has been moved to the caller.
+ BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending,
+ Consumer<Map<TopicPartition,
+ DeleteRecordsResponseData.DeleteRecordsPartitionResult>> responseCallback) {
+ super(delayMs);
+ this.onAcksPending = onAcksPending;
+ this.deleteRecordsStatus = new ConcurrentHashMap<>(deleteRecordsStatus);
+ this.responseCallback = responseCallback;
+ // first update the acks pending variable according to the error code
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ if (status.getResponseStatus().errorCode() == Errors.NONE.code()) {
+ // Timeout error state will be cleared when required acks are received
+ status.setAcksPending(true);
+ status.getResponseStatus().setErrorCode(Errors.REQUEST_TIMED_OUT.code());
+ } else {
+ status.setAcksPending(false);
+ }
+ });
+ }
+
+ /**
+ * The delayed delete records operation can be completed if every partition specified in the request satisfied one of the following:
+ *
+ * 1) There was an error while checking if all replicas have caught up to the deleteRecordsOffset: set an error in response
+ * 2) The low watermark of the partition has caught up to the deleteRecordsOffset. set the low watermark in response
+ *
+ */
+ @Override
+ public boolean tryComplete() {
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ log.trace("Checking delete records satisfaction for {}, current status {}", topicPartition, status);
+ if (status.isAcksPending()) {
+ onAcksPending.accept(topicPartition, status);
+ }
+ });
+ return deleteRecordsStatus.values().stream().noneMatch(DeleteRecordsPartitionStatus::isAcksPending) && forceComplete();
+ }
+
+ @Override
+ public void onExpiration() {
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ if (status.isAcksPending()) {
+ DelayedDeleteRecordsMetrics.recordExpiration(topicPartition);
+ }
+ });
+ }
+
+ /**
+ * Upon completion, return the current response status along with the error code per partition
+ */
+ @Override
+ public void onComplete() {
+ Map<TopicPartition, DeleteRecordsResponseData.DeleteRecordsPartitionResult> responseStatus =
+ new HashMap<>();
+ deleteRecordsStatus.forEach((k, status) -> {
+ responseStatus.put(k, status.getResponseStatus());
+ });
+ responseCallback.accept(responseStatus);
+ }
+ }
+
+ private static class DelayedDeleteRecordsMetrics {
+ private static final KafkaMetricsGroup METRICS_GROUP = new KafkaMetricsGroup(DelayedDeleteRecordsMetrics.class);
+ private static final Meter AGGREGATE_EXPIRATION_METER = METRICS_GROUP.newMeter("ExpiresPerSec", "requests",
+ TimeUnit.SECONDS);
+
+ public static void recordExpiration(TopicPartition partition) {
Review Comment:
This `TopicPartition partition` doesn't use, I think we can remove it.
##########
server-common/src/main/java/org/apache/kafka/server/common/DeleteRecordsPartitionStatus.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
+
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+import org.apache.kafka.server.purgatory.DelayedOperation;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+public class DeleteRecordsPartitionStatus {
+ private final long requiredOffset;
+ private final DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus;
+ private volatile boolean acksPending;
+
+ public DeleteRecordsPartitionStatus(long requiredOffset,
+ DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus) {
+ this.requiredOffset = requiredOffset;
+ this.responseStatus = responseStatus;
+ this.acksPending = false;
+ }
+
+ public boolean isAcksPending() {
+ return acksPending;
+ }
+
+ public void setAcksPending(boolean acksPending) {
+ this.acksPending = acksPending;
+ }
+
+
+ public DeleteRecordsResponseData.DeleteRecordsPartitionResult getResponseStatus() {
Review Comment:
It seems that the get prefix is rarely used in Kafka, should change to `responseStatus`
##########
server-common/src/main/java/org/apache/kafka/server/common/DeleteRecordsPartitionStatus.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
+
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+import org.apache.kafka.server.purgatory.DelayedOperation;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+public class DeleteRecordsPartitionStatus {
+ private final long requiredOffset;
+ private final DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus;
+ private volatile boolean acksPending;
+
+ public DeleteRecordsPartitionStatus(long requiredOffset,
+ DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus) {
+ this.requiredOffset = requiredOffset;
+ this.responseStatus = responseStatus;
+ this.acksPending = false;
+ }
+
+ public boolean isAcksPending() {
+ return acksPending;
+ }
+
+ public void setAcksPending(boolean acksPending) {
+ this.acksPending = acksPending;
+ }
+
+
+ public DeleteRecordsResponseData.DeleteRecordsPartitionResult getResponseStatus() {
+ return responseStatus;
+ }
+
+ public long getRequiredOffset() {
Review Comment:
ditto It seems that the get prefix is rarely used in Kafka, should change to `requiredOffset`
##########
server-common/src/main/java/org/apache/kafka/server/common/DeleteRecordsPartitionStatus.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
+
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+import org.apache.kafka.server.purgatory.DelayedOperation;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+public class DeleteRecordsPartitionStatus {
+ private final long requiredOffset;
+ private final DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus;
+ private volatile boolean acksPending;
+
+ public DeleteRecordsPartitionStatus(long requiredOffset,
+ DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus) {
+ this.requiredOffset = requiredOffset;
+ this.responseStatus = responseStatus;
+ this.acksPending = false;
+ }
+
+ public boolean isAcksPending() {
+ return acksPending;
+ }
+
+ public void setAcksPending(boolean acksPending) {
+ this.acksPending = acksPending;
+ }
+
+
+ public DeleteRecordsResponseData.DeleteRecordsPartitionResult getResponseStatus() {
+ return responseStatus;
+ }
+
+ public long getRequiredOffset() {
+ return requiredOffset;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("[acksPending: %b, error: %s, lowWatermark: %d, requiredOffset: %d]",
+ acksPending, Errors.forCode(responseStatus.errorCode()).toString(), responseStatus.lowWatermark(),
+ requiredOffset);
+ }
+
+ /**
+ * A delayed delete records operation that can be created by the replica manager and watched
+ * in the delete records operation purgatory
+ */
+ public static class DelayedDeleteRecords extends DelayedOperation {
+ private final Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus;
+ private final BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending;
+ private final Consumer<Map<TopicPartition, DeleteRecordsResponseData.DeleteRecordsPartitionResult>> responseCallback;
+ private static final Logger log = LoggerFactory.getLogger(DelayedDeleteRecords.class);
+
+ public DelayedDeleteRecords(long delayMs,
+ Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus,
+ // To maintain compatibility with dependency packages, the logic has been moved to the caller.
+ BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending,
+ Consumer<Map<TopicPartition,
+ DeleteRecordsResponseData.DeleteRecordsPartitionResult>> responseCallback) {
+ super(delayMs);
+ this.onAcksPending = onAcksPending;
+ this.deleteRecordsStatus = new ConcurrentHashMap<>(deleteRecordsStatus);
+ this.responseCallback = responseCallback;
+ // first update the acks pending variable according to the error code
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ if (status.getResponseStatus().errorCode() == Errors.NONE.code()) {
+ // Timeout error state will be cleared when required acks are received
+ status.setAcksPending(true);
+ status.getResponseStatus().setErrorCode(Errors.REQUEST_TIMED_OUT.code());
+ } else {
+ status.setAcksPending(false);
+ }
+ });
Review Comment:
We should remain this log `trace("Initial partition status for %s is %s".format(topicPartition, status))`
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "gongxuanzhang (via GitHub)" <gi...@apache.org>.
gongxuanzhang commented on PR #19226:
URL: https://github.com/apache/kafka/pull/19226#issuecomment-2740009251
@chia7712 PTAL
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on PR #19226:
URL: https://github.com/apache/kafka/pull/19226#issuecomment-2782354297
I was looking at https://github.com/apache/kafka/pull/19390 and wondering whether we should put these classes in `server` instead of `server-common` as they don't seem to be used elsewhere. For example we put `DelayedRemoteListOffsets` in the `storage` module. WDYT?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st commented on code in PR #19226:
URL: https://github.com/apache/kafka/pull/19226#discussion_r2011211038
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -19,13 +19,14 @@ package kafka.server
import com.yammer.metrics.core.Meter
import kafka.cluster.{Partition, PartitionListener}
import kafka.controller.StateChangeLogger
-import kafka.log.remote.RemoteLogManager
import kafka.log.LogManager
+import kafka.log.remote.RemoteLogManager
import kafka.server.HostedPartition.Online
import kafka.server.QuotaFactory.QuotaManagers
-import kafka.server.ReplicaManager.{AtMinIsrPartitionCountMetricName, FailedIsrUpdatesPerSecMetricName, IsrExpandsPerSecMetricName, IsrShrinksPerSecMetricName, LeaderCountMetricName, OfflineReplicaCountMetricName, PartitionCountMetricName, PartitionsWithLateTransactionsCountMetricName, ProducerIdCountMetricName, ReassigningPartitionsMetricName, UnderMinIsrPartitionCountMetricName, UnderReplicatedPartitionsMetricName, createLogReadResult, isListOffsetsTimestampUnsupported}
+import kafka.server.ReplicaManager._
Review Comment:
I think this change is unnecessary.
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -46,21 +47,19 @@ import org.apache.kafka.common.requests.FetchRequest.PartitionData
import org.apache.kafka.common.requests.ProduceResponse.PartitionResponse
import org.apache.kafka.common.requests._
import org.apache.kafka.common.utils.{Exit, Time, Utils}
-import org.apache.kafka.common.{IsolationLevel, Node, TopicIdPartition, TopicPartition, Uuid}
import org.apache.kafka.image.{LocalReplicaChanges, MetadataImage, TopicsDelta}
import org.apache.kafka.metadata.LeaderConstants.NO_LEADER
import org.apache.kafka.metadata.MetadataCache
-import org.apache.kafka.server.{ActionQueue, DelayedActionQueue, ListOffsetsPartitionStatus, common}
-import org.apache.kafka.server.common.{DirectoryEventHandler, RequestLocal, StopPartition, TopicOptionalIdPartition}
+import org.apache.kafka.server.common._
Review Comment:
I think this change is unnecessary.
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -46,21 +47,19 @@ import org.apache.kafka.common.requests.FetchRequest.PartitionData
import org.apache.kafka.common.requests.ProduceResponse.PartitionResponse
import org.apache.kafka.common.requests._
import org.apache.kafka.common.utils.{Exit, Time, Utils}
-import org.apache.kafka.common.{IsolationLevel, Node, TopicIdPartition, TopicPartition, Uuid}
import org.apache.kafka.image.{LocalReplicaChanges, MetadataImage, TopicsDelta}
import org.apache.kafka.metadata.LeaderConstants.NO_LEADER
import org.apache.kafka.metadata.MetadataCache
-import org.apache.kafka.server.{ActionQueue, DelayedActionQueue, ListOffsetsPartitionStatus, common}
-import org.apache.kafka.server.common.{DirectoryEventHandler, RequestLocal, StopPartition, TopicOptionalIdPartition}
+import org.apache.kafka.server.common._
import org.apache.kafka.server.metrics.KafkaMetricsGroup
import org.apache.kafka.server.network.BrokerEndPoint
import org.apache.kafka.server.purgatory.{DelayedOperationPurgatory, TopicPartitionOperationKey}
import org.apache.kafka.server.share.fetch.{DelayedShareFetchKey, DelayedShareFetchPartitionKey}
import org.apache.kafka.server.storage.log.{FetchParams, FetchPartitionData}
import org.apache.kafka.server.util.{Scheduler, ShutdownableThread}
+import org.apache.kafka.server.{ActionQueue, DelayedActionQueue, ListOffsetsPartitionStatus, common}
import org.apache.kafka.storage.internals.checkpoint.{LazyOffsetCheckpoints, OffsetCheckpointFile, OffsetCheckpoints}
-import org.apache.kafka.storage.internals.log.{AppendOrigin, FetchDataInfo, LeaderHwChange, LogAppendInfo, LogConfig, LogDirFailureChannel, LogOffsetMetadata, LogReadInfo, OffsetResultHolder, RecordValidationException, RemoteLogReadResult, RemoteStorageFetchInfo, UnifiedLog => UnifiedLog, VerificationGuard}
-
+import org.apache.kafka.storage.internals.log._
Review Comment:
I think this change is unnecessary.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #19226:
URL: https://github.com/apache/kafka/pull/19226#discussion_r2021394671
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -1282,8 +1281,31 @@ class ReplicaManager(val config: KafkaConfig,
}
if (delayedDeleteRecordsRequired(localDeleteRecordsResults)) {
+ def onAcks(topicPartition: TopicPartition, status: DeleteRecordsPartitionStatus): Unit = {
+ val (lowWatermarkReached, error, lw) = getPartition(topicPartition) match {
+ case HostedPartition.Online(partition) =>
+ partition.leaderLogIfLocal match {
+ case Some(_) =>
+ val leaderLW = partition.lowWatermarkIfLeader
+ (leaderLW >= status.requiredOffset, Errors.NONE, leaderLW)
+ case None =>
+ (false, Errors.NOT_LEADER_OR_FOLLOWER, DeleteRecordsResponse.INVALID_LOW_WATERMARK)
+ }
+
+ case HostedPartition.Offline(_) =>
+ (false, Errors.KAFKA_STORAGE_ERROR, DeleteRecordsResponse.INVALID_LOW_WATERMARK)
+
+ case HostedPartition.None =>
+ (false, Errors.UNKNOWN_TOPIC_OR_PARTITION, DeleteRecordsResponse.INVALID_LOW_WATERMARK)
+ }
+ if (error != Errors.NONE || lowWatermarkReached) {
+ status.setAcksPending(false)
+ status.responseStatus.setErrorCode(error.code)
+ status.responseStatus.setLowWatermark(lw)
+ }
+ }
// create delayed delete records operation
- val delayedDeleteRecords = new DelayedDeleteRecords(timeout, deleteRecordsStatus, this, responseCallback)
+ val delayedDeleteRecords = new DelayedDeleteRecords(timeout, deleteRecordsStatus.asJava, onAcks , response => responseCallback(response.asScala))
Review Comment:
this is not addressed
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "gongxuanzhang (via GitHub)" <gi...@apache.org>.
gongxuanzhang commented on code in PR #19226:
URL: https://github.com/apache/kafka/pull/19226#discussion_r2022688061
##########
server-common/src/main/java/org/apache/kafka/server/purgatory/DelayedDeleteRecords.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.purgatory;
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData.DeleteRecordsPartitionResult;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+/**
+ * A delayed delete records operation that can be created by the replica manager and watched
+ * in the delete records operation purgatory
+ */
+public class DelayedDeleteRecords extends DelayedOperation {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DelayedDeleteRecords.class);
+
+ // migration from kafka.server.DelayedDeleteRecordsMetrics
+ private static final KafkaMetricsGroup METRICS_GROUP = new KafkaMetricsGroup("kafka.server", "DelayedDeleteRecordsMetrics");
+ private static final Meter AGGREGATE_EXPIRATION_METER = METRICS_GROUP.newMeter("ExpiresPerSec", "requests",
+ TimeUnit.SECONDS);
+
+ private final Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus;
+ private final BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending;
+ private final Consumer<Map<TopicPartition, DeleteRecordsPartitionResult>> responseCallback;
+
+ public DelayedDeleteRecords(long delayMs,
+ Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus,
+ // To maintain compatibility with dependency packages, the logic has been moved to the caller.
+ BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending,
+ Consumer<Map<TopicPartition, DeleteRecordsPartitionResult>> responseCallback) {
+ super(delayMs);
+ this.onAcksPending = onAcksPending;
+ this.deleteRecordsStatus = Collections.unmodifiableMap(deleteRecordsStatus);
+ this.responseCallback = responseCallback;
+ // first update the acks pending variable according to the error code
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ if (status.responseStatus().errorCode() == Errors.NONE.code()) {
+ // Timeout error state will be cleared when required acks are received
+ status.setAcksPending(true);
+ status.responseStatus().setErrorCode(Errors.REQUEST_TIMED_OUT.code());
+ } else {
+ status.setAcksPending(false);
+ }
+ });
+ }
+
+ /**
+ * The delayed delete records operation can be completed if every partition specified in the request satisfied one of the following:
+ *
+ * 1) There was an error while checking if all replicas have caught up to the deleteRecordsOffset: set an error in response
+ * 2) The low watermark of the partition has caught up to the deleteRecordsOffset. set the low watermark in response
+ *
+ */
+ @Override
+ public boolean tryComplete() {
+ // check for each partition if it still has pending acks
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ LOG.trace("Checking delete records satisfaction for {}, current status {}", topicPartition, status);
+ // skip those partitions that have already been satisfied
+ if (status.acksPending()) {
+ onAcksPending.accept(topicPartition, status);
+ }
+ });
+ // check if every partition has satisfied at least one of case A or B
+ return deleteRecordsStatus.values().stream().noneMatch(DeleteRecordsPartitionStatus::acksPending) && forceComplete();
+ }
+
+ @Override
+ public void onExpiration() {
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
Review Comment:
excellent!
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on PR #19226:
URL: https://github.com/apache/kafka/pull/19226#issuecomment-2783237052
> RemoteLogManager only uses DelayedRemoteListOffsets hence why we put that in the storage module. But as far as I can tell other purgatory code could be in server.
`RemoteLogManager` also uses `TopicPartitionOperationKey` (and `DelayedOperationKey`), so I guess you meant other classes, such as `DeleteRecordsPartitionStatus`, `DelayedDeleteRecords`, and `DelayedOperation`, can be moved to `server` module, right?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 merged PR #19226:
URL: https://github.com/apache/kafka/pull/19226
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #19226:
URL: https://github.com/apache/kafka/pull/19226#discussion_r2006062890
##########
server-common/src/main/java/org/apache/kafka/server/common/DeleteRecordsPartitionStatus.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
+
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+import org.apache.kafka.server.purgatory.DelayedOperation;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+public class DeleteRecordsPartitionStatus {
+ private final long requiredOffset;
+ private final DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus;
+ private volatile boolean acksPending;
+
+ public DeleteRecordsPartitionStatus(long requiredOffset,
+ DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus) {
+ this.requiredOffset = requiredOffset;
+ this.responseStatus = responseStatus;
+ this.acksPending = false;
+ }
+
+ public boolean acksPending() {
+ return acksPending;
+ }
+
+ public void setAcksPending(boolean acksPending) {
+ this.acksPending = acksPending;
+ }
+
+
+ public DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus() {
+ return responseStatus;
+ }
+
+ public long requiredOffset() {
+ return requiredOffset;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("[acksPending: %b, error: %s, lowWatermark: %d, requiredOffset: %d]",
+ acksPending, Errors.forCode(responseStatus.errorCode()).toString(), responseStatus.lowWatermark(),
+ requiredOffset);
+ }
+
+ /**
+ * A delayed delete records operation that can be created by the replica manager and watched
+ * in the delete records operation purgatory
+ */
+ public static class DelayedDeleteRecords extends DelayedOperation {
+ private final Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus;
+ private final BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending;
+ private final Consumer<Map<TopicPartition, DeleteRecordsResponseData.DeleteRecordsPartitionResult>> responseCallback;
+ private static final Logger log = LoggerFactory.getLogger(DelayedDeleteRecords.class);
+
+ public DelayedDeleteRecords(long delayMs,
+ Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus,
+ // To maintain compatibility with dependency packages, the logic has been moved to the caller.
+ BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending,
+ Consumer<Map<TopicPartition,
+ DeleteRecordsResponseData.DeleteRecordsPartitionResult>> responseCallback) {
+ super(delayMs);
+ this.onAcksPending = onAcksPending;
+ this.deleteRecordsStatus = new ConcurrentHashMap<>(deleteRecordsStatus);
+ this.responseCallback = responseCallback;
+ // first update the acks pending variable according to the error code
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ if (status.responseStatus().errorCode() == Errors.NONE.code()) {
+ // Timeout error state will be cleared when required acks are received
+ status.setAcksPending(true);
+ status.responseStatus().setErrorCode(Errors.REQUEST_TIMED_OUT.code());
+ } else {
+ status.setAcksPending(false);
+ }
+ });
+ }
+
+ /**
+ * The delayed delete records operation can be completed if every partition specified in the request satisfied one of the following:
+ *
+ * 1) There was an error while checking if all replicas have caught up to the deleteRecordsOffset: set an error in response
+ * 2) The low watermark of the partition has caught up to the deleteRecordsOffset. set the low watermark in response
+ *
+ */
+ @Override
+ public boolean tryComplete() {
+ // check for each partition if it still has pending acks
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ log.trace("Checking delete records satisfaction for {}, current status {}", topicPartition, status);
+ // skip those partitions that have already been satisfied
+ if (status.acksPending()) {
+ onAcksPending.accept(topicPartition, status);
+ }
+ });
+ // check if every partition has satisfied at least one of case A or B
+ return deleteRecordsStatus.values().stream().noneMatch(DeleteRecordsPartitionStatus::acksPending) && forceComplete();
+ }
+
+ @Override
+ public void onExpiration() {
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ if (status.acksPending()) {
+ DelayedDeleteRecordsMetrics.recordExpiration(topicPartition);
+ }
+ });
+ }
+
+ /**
+ * Upon completion, return the current response status along with the error code per partition
+ */
+ @Override
+ public void onComplete() {
+ Map<TopicPartition, DeleteRecordsResponseData.DeleteRecordsPartitionResult> responseStatus =
+ new HashMap<>();
+ deleteRecordsStatus.forEach((k, status) -> {
+ responseStatus.put(k, status.responseStatus());
+ });
+ responseCallback.accept(responseStatus);
+ }
+ }
+
+ private static class DelayedDeleteRecordsMetrics {
Review Comment:
we don't need this static class as all static variables can be moved to `DelayedDeleteRecords`
##########
server-common/src/main/java/org/apache/kafka/server/common/DeleteRecordsPartitionStatus.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
+
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+import org.apache.kafka.server.purgatory.DelayedOperation;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+public class DeleteRecordsPartitionStatus {
+ private final long requiredOffset;
+ private final DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus;
+ private volatile boolean acksPending;
+
+ public DeleteRecordsPartitionStatus(long requiredOffset,
+ DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus) {
+ this.requiredOffset = requiredOffset;
+ this.responseStatus = responseStatus;
+ this.acksPending = false;
+ }
+
+ public boolean acksPending() {
+ return acksPending;
+ }
+
+ public void setAcksPending(boolean acksPending) {
+ this.acksPending = acksPending;
+ }
+
+
+ public DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus() {
+ return responseStatus;
+ }
+
+ public long requiredOffset() {
+ return requiredOffset;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("[acksPending: %b, error: %s, lowWatermark: %d, requiredOffset: %d]",
+ acksPending, Errors.forCode(responseStatus.errorCode()).toString(), responseStatus.lowWatermark(),
+ requiredOffset);
+ }
+
+ /**
+ * A delayed delete records operation that can be created by the replica manager and watched
+ * in the delete records operation purgatory
+ */
+ public static class DelayedDeleteRecords extends DelayedOperation {
+ private final Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus;
+ private final BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending;
+ private final Consumer<Map<TopicPartition, DeleteRecordsResponseData.DeleteRecordsPartitionResult>> responseCallback;
+ private static final Logger log = LoggerFactory.getLogger(DelayedDeleteRecords.class);
+
+ public DelayedDeleteRecords(long delayMs,
+ Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus,
+ // To maintain compatibility with dependency packages, the logic has been moved to the caller.
+ BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending,
+ Consumer<Map<TopicPartition,
+ DeleteRecordsResponseData.DeleteRecordsPartitionResult>> responseCallback) {
+ super(delayMs);
+ this.onAcksPending = onAcksPending;
+ this.deleteRecordsStatus = new ConcurrentHashMap<>(deleteRecordsStatus);
+ this.responseCallback = responseCallback;
+ // first update the acks pending variable according to the error code
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ if (status.responseStatus().errorCode() == Errors.NONE.code()) {
+ // Timeout error state will be cleared when required acks are received
+ status.setAcksPending(true);
+ status.responseStatus().setErrorCode(Errors.REQUEST_TIMED_OUT.code());
+ } else {
+ status.setAcksPending(false);
+ }
+ });
+ }
+
+ /**
+ * The delayed delete records operation can be completed if every partition specified in the request satisfied one of the following:
+ *
+ * 1) There was an error while checking if all replicas have caught up to the deleteRecordsOffset: set an error in response
+ * 2) The low watermark of the partition has caught up to the deleteRecordsOffset. set the low watermark in response
+ *
+ */
+ @Override
+ public boolean tryComplete() {
+ // check for each partition if it still has pending acks
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ log.trace("Checking delete records satisfaction for {}, current status {}", topicPartition, status);
+ // skip those partitions that have already been satisfied
+ if (status.acksPending()) {
+ onAcksPending.accept(topicPartition, status);
+ }
+ });
+ // check if every partition has satisfied at least one of case A or B
+ return deleteRecordsStatus.values().stream().noneMatch(DeleteRecordsPartitionStatus::acksPending) && forceComplete();
+ }
+
+ @Override
+ public void onExpiration() {
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ if (status.acksPending()) {
+ DelayedDeleteRecordsMetrics.recordExpiration(topicPartition);
+ }
+ });
+ }
+
+ /**
+ * Upon completion, return the current response status along with the error code per partition
+ */
+ @Override
+ public void onComplete() {
+ Map<TopicPartition, DeleteRecordsResponseData.DeleteRecordsPartitionResult> responseStatus =
+ new HashMap<>();
+ deleteRecordsStatus.forEach((k, status) -> {
+ responseStatus.put(k, status.responseStatus());
+ });
+ responseCallback.accept(responseStatus);
Review Comment:
```java
responseCallback.accept(deleteRecordsStatus.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().responseStatus())));
```
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -1282,8 +1282,33 @@ class ReplicaManager(val config: KafkaConfig,
}
if (delayedDeleteRecordsRequired(localDeleteRecordsResults)) {
+ def onAcks(topicPartition: TopicPartition, status: DeleteRecordsPartitionStatus): Unit = {
+ val (lowWatermarkReached, error, lw) = getPartition(topicPartition) match {
+ case HostedPartition.Online(partition) =>
+ partition.leaderLogIfLocal match {
+ case Some(_) =>
+ val leaderLW = partition.lowWatermarkIfLeader
+ (leaderLW >= status.requiredOffset, Errors.NONE, leaderLW)
+ case None =>
+ (false, Errors.NOT_LEADER_OR_FOLLOWER, DeleteRecordsResponse.INVALID_LOW_WATERMARK)
+ }
+
+ case HostedPartition.Offline(_) =>
+ (false, Errors.KAFKA_STORAGE_ERROR, DeleteRecordsResponse.INVALID_LOW_WATERMARK)
+
+ case HostedPartition.None =>
+ (false, Errors.UNKNOWN_TOPIC_OR_PARTITION, DeleteRecordsResponse.INVALID_LOW_WATERMARK)
+ }
+ if (error != Errors.NONE || lowWatermarkReached) {
+ status.setAcksPending(false)
+ status.responseStatus.setErrorCode(error.code)
+ status.responseStatus.setLowWatermark(lw)
+ }
+ }
+ val responseCallbackJava: java.util.function.Consumer[util.Map[TopicPartition, DeleteRecordsPartitionResult]] =
+ response => responseCallback(response.asScala)
// create delayed delete records operation
- val delayedDeleteRecords = new DelayedDeleteRecords(timeout, deleteRecordsStatus, this, responseCallback)
+ val delayedDeleteRecords = new DeleteRecordsPartitionStatus.DelayedDeleteRecords(timeout, deleteRecordsStatus.asJava,onAcks , responseCallbackJava)
Review Comment:
`deleteRecordsStatus.asJava, onAcks, responseCallbackJava`
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -1282,8 +1282,33 @@ class ReplicaManager(val config: KafkaConfig,
}
if (delayedDeleteRecordsRequired(localDeleteRecordsResults)) {
+ def onAcks(topicPartition: TopicPartition, status: DeleteRecordsPartitionStatus): Unit = {
+ val (lowWatermarkReached, error, lw) = getPartition(topicPartition) match {
+ case HostedPartition.Online(partition) =>
+ partition.leaderLogIfLocal match {
+ case Some(_) =>
+ val leaderLW = partition.lowWatermarkIfLeader
+ (leaderLW >= status.requiredOffset, Errors.NONE, leaderLW)
+ case None =>
+ (false, Errors.NOT_LEADER_OR_FOLLOWER, DeleteRecordsResponse.INVALID_LOW_WATERMARK)
+ }
+
+ case HostedPartition.Offline(_) =>
+ (false, Errors.KAFKA_STORAGE_ERROR, DeleteRecordsResponse.INVALID_LOW_WATERMARK)
+
+ case HostedPartition.None =>
+ (false, Errors.UNKNOWN_TOPIC_OR_PARTITION, DeleteRecordsResponse.INVALID_LOW_WATERMARK)
+ }
+ if (error != Errors.NONE || lowWatermarkReached) {
+ status.setAcksPending(false)
+ status.responseStatus.setErrorCode(error.code)
+ status.responseStatus.setLowWatermark(lw)
+ }
+ }
+ val responseCallbackJava: java.util.function.Consumer[util.Map[TopicPartition, DeleteRecordsPartitionResult]] =
Review Comment:
It seems we don't need to create this object, right? we can pass `response => responseCallback(response.asScala)` directly
##########
server-common/src/main/java/org/apache/kafka/server/common/DeleteRecordsPartitionStatus.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
+
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+import org.apache.kafka.server.purgatory.DelayedOperation;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+public class DeleteRecordsPartitionStatus {
+ private final long requiredOffset;
+ private final DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus;
+ private volatile boolean acksPending;
+
+ public DeleteRecordsPartitionStatus(long requiredOffset,
+ DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus) {
+ this.requiredOffset = requiredOffset;
+ this.responseStatus = responseStatus;
+ this.acksPending = false;
+ }
+
+ public boolean acksPending() {
+ return acksPending;
+ }
+
+ public void setAcksPending(boolean acksPending) {
+ this.acksPending = acksPending;
+ }
+
+
+ public DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus() {
+ return responseStatus;
+ }
+
+ public long requiredOffset() {
+ return requiredOffset;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("[acksPending: %b, error: %s, lowWatermark: %d, requiredOffset: %d]",
+ acksPending, Errors.forCode(responseStatus.errorCode()).toString(), responseStatus.lowWatermark(),
+ requiredOffset);
+ }
+
+ /**
+ * A delayed delete records operation that can be created by the replica manager and watched
+ * in the delete records operation purgatory
+ */
+ public static class DelayedDeleteRecords extends DelayedOperation {
+ private final Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus;
+ private final BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending;
+ private final Consumer<Map<TopicPartition, DeleteRecordsResponseData.DeleteRecordsPartitionResult>> responseCallback;
+ private static final Logger log = LoggerFactory.getLogger(DelayedDeleteRecords.class);
+
+ public DelayedDeleteRecords(long delayMs,
+ Map<TopicPartition, DeleteRecordsPartitionStatus> deleteRecordsStatus,
+ // To maintain compatibility with dependency packages, the logic has been moved to the caller.
+ BiConsumer<TopicPartition, DeleteRecordsPartitionStatus> onAcksPending,
+ Consumer<Map<TopicPartition,
+ DeleteRecordsResponseData.DeleteRecordsPartitionResult>> responseCallback) {
+ super(delayMs);
+ this.onAcksPending = onAcksPending;
+ this.deleteRecordsStatus = new ConcurrentHashMap<>(deleteRecordsStatus);
+ this.responseCallback = responseCallback;
+ // first update the acks pending variable according to the error code
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ if (status.responseStatus().errorCode() == Errors.NONE.code()) {
+ // Timeout error state will be cleared when required acks are received
+ status.setAcksPending(true);
+ status.responseStatus().setErrorCode(Errors.REQUEST_TIMED_OUT.code());
+ } else {
+ status.setAcksPending(false);
+ }
+ });
+ }
+
+ /**
+ * The delayed delete records operation can be completed if every partition specified in the request satisfied one of the following:
+ *
+ * 1) There was an error while checking if all replicas have caught up to the deleteRecordsOffset: set an error in response
+ * 2) The low watermark of the partition has caught up to the deleteRecordsOffset. set the low watermark in response
+ *
+ */
+ @Override
+ public boolean tryComplete() {
+ // check for each partition if it still has pending acks
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ log.trace("Checking delete records satisfaction for {}, current status {}", topicPartition, status);
+ // skip those partitions that have already been satisfied
+ if (status.acksPending()) {
+ onAcksPending.accept(topicPartition, status);
+ }
+ });
+ // check if every partition has satisfied at least one of case A or B
+ return deleteRecordsStatus.values().stream().noneMatch(DeleteRecordsPartitionStatus::acksPending) && forceComplete();
+ }
+
+ @Override
+ public void onExpiration() {
+ deleteRecordsStatus.forEach((topicPartition, status) -> {
+ if (status.acksPending()) {
+ DelayedDeleteRecordsMetrics.recordExpiration(topicPartition);
+ }
+ });
+ }
+
+ /**
+ * Upon completion, return the current response status along with the error code per partition
+ */
+ @Override
+ public void onComplete() {
+ Map<TopicPartition, DeleteRecordsResponseData.DeleteRecordsPartitionResult> responseStatus =
+ new HashMap<>();
+ deleteRecordsStatus.forEach((k, status) -> {
+ responseStatus.put(k, status.responseStatus());
+ });
+ responseCallback.accept(responseStatus);
+ }
+ }
+
+ private static class DelayedDeleteRecordsMetrics {
+ private static final KafkaMetricsGroup METRICS_GROUP = new KafkaMetricsGroup(DelayedDeleteRecordsMetrics.class);
Review Comment:
this break the compatibility of metrics name, so please use "kafka.server.DelayedDeleteRecordsMetrics" instead
##########
server-common/src/main/java/org/apache/kafka/server/common/DeleteRecordsPartitionStatus.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
+
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+import org.apache.kafka.server.purgatory.DelayedOperation;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+public class DeleteRecordsPartitionStatus {
Review Comment:
the main class should be `DelayedDeleteRecords` rather than `DeleteRecordsPartitionStatus`
##########
server-common/src/main/java/org/apache/kafka/server/common/DeleteRecordsPartitionStatus.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
+
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+import org.apache.kafka.server.purgatory.DelayedOperation;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+public class DeleteRecordsPartitionStatus {
+ private final long requiredOffset;
+ private final DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus;
+ private volatile boolean acksPending;
+
+ public DeleteRecordsPartitionStatus(long requiredOffset,
+ DeleteRecordsResponseData.DeleteRecordsPartitionResult responseStatus) {
Review Comment:
could you please import `DeleteRecordsResponseData.DeleteRecordsPartitionResult`?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #19226:
URL: https://github.com/apache/kafka/pull/19226#discussion_r2018399561
##########
server-common/src/main/java/org/apache/kafka/server/common/DelayedDeleteRecords.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData.DeleteRecordsPartitionResult;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+import org.apache.kafka.server.purgatory.DelayedOperation;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+/**
+ * A delayed delete records operation that can be created by the replica manager and watched
+ * in the delete records operation purgatory
+ */
+public class DelayedDeleteRecords extends DelayedOperation {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DelayedDeleteRecords.class);
Review Comment:
Logger names are what users set in their log4j2 configuration. But it seems we've not consistently kept names for other classes we moved, so this is probably fine.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "gongxuanzhang (via GitHub)" <gi...@apache.org>.
gongxuanzhang commented on code in PR #19226:
URL: https://github.com/apache/kafka/pull/19226#discussion_r2019096133
##########
server-common/src/main/java/org/apache/kafka/server/common/DelayedDeleteRecords.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData.DeleteRecordsPartitionResult;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+import org.apache.kafka.server.purgatory.DelayedOperation;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+/**
+ * A delayed delete records operation that can be created by the replica manager and watched
+ * in the delete records operation purgatory
+ */
+public class DelayedDeleteRecords extends DelayedOperation {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DelayedDeleteRecords.class);
Review Comment:
thanks for your answer
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on PR #19226:
URL: https://github.com/apache/kafka/pull/19226#issuecomment-2783375231
@gongxuanzhang WDYT? If you agree @mimaison's comment, could you please create a MINOR to address it?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on PR #19226:
URL: https://github.com/apache/kafka/pull/19226#issuecomment-2783031557
> I was looking at https://github.com/apache/kafka/pull/19390 and wondering whether we should put these classes in server instead of server-common as they don't seem to be used elsewhere. For example we put DelayedRemoteListOffsets in the storage module. WDYT?
It seems `RemoteLogManager` could use those Purgatory-related code. I guess `RemoteLogManager` will be moved to storage module in the future? If so, those Purgatory code should be in server-common module
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #19226:
URL: https://github.com/apache/kafka/pull/19226#discussion_r2018399561
##########
server-common/src/main/java/org/apache/kafka/server/common/DelayedDeleteRecords.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData.DeleteRecordsPartitionResult;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+import org.apache.kafka.server.purgatory.DelayedOperation;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+/**
+ * A delayed delete records operation that can be created by the replica manager and watched
+ * in the delete records operation purgatory
+ */
+public class DelayedDeleteRecords extends DelayedOperation {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DelayedDeleteRecords.class);
Review Comment:
Logger names are what users set in their log4j2 configuration. But it seems we've not consistently kept names for other classes we moved.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "gongxuanzhang (via GitHub)" <gi...@apache.org>.
gongxuanzhang commented on code in PR #19226:
URL: https://github.com/apache/kafka/pull/19226#discussion_r2017802756
##########
server-common/src/main/java/org/apache/kafka/server/common/DelayedDeleteRecords.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData.DeleteRecordsPartitionResult;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+import org.apache.kafka.server.purgatory.DelayedOperation;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+/**
+ * A delayed delete records operation that can be created by the replica manager and watched
+ * in the delete records operation purgatory
+ */
+public class DelayedDeleteRecords extends DelayedOperation {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DelayedDeleteRecords.class);
Review Comment:
I don't think changing the name will affect anything. Do we have a special need to keep the name
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #19226:
URL: https://github.com/apache/kafka/pull/19226#discussion_r2012290418
##########
server-common/src/main/java/org/apache/kafka/server/common/DelayedDeleteRecords.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
Review Comment:
Would the `org.apache.kafka.server.purgatory` package be a better place for these classes? So it's next to the abstract class `DelayedOperation` it's extending.
##########
server-common/src/main/java/org/apache/kafka/server/common/DelayedDeleteRecords.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.common;
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.message.DeleteRecordsResponseData.DeleteRecordsPartitionResult;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.server.metrics.KafkaMetricsGroup;
+import org.apache.kafka.server.purgatory.DelayedOperation;
+
+import com.yammer.metrics.core.Meter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+/**
+ * A delayed delete records operation that can be created by the replica manager and watched
+ * in the delete records operation purgatory
+ */
+public class DelayedDeleteRecords extends DelayedOperation {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DelayedDeleteRecords.class);
Review Comment:
Should we keep `kafka.server.DelayedDeleteRecords` as the logger name?
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -19,13 +19,14 @@ package kafka.server
import com.yammer.metrics.core.Meter
import kafka.cluster.{Partition, PartitionListener}
import kafka.controller.StateChangeLogger
-import kafka.log.remote.RemoteLogManager
import kafka.log.LogManager
+import kafka.log.remote.RemoteLogManager
import kafka.server.HostedPartition.Online
import kafka.server.QuotaFactory.QuotaManagers
-import kafka.server.ReplicaManager.{AtMinIsrPartitionCountMetricName, FailedIsrUpdatesPerSecMetricName, IsrExpandsPerSecMetricName, IsrShrinksPerSecMetricName, LeaderCountMetricName, OfflineReplicaCountMetricName, PartitionCountMetricName, PartitionsWithLateTransactionsCountMetricName, ProducerIdCountMetricName, ReassigningPartitionsMetricName, UnderMinIsrPartitionCountMetricName, UnderReplicatedPartitionsMetricName, createLogReadResult, isListOffsetsTimestampUnsupported}
+import kafka.server.ReplicaManager._
Review Comment:
Let's keep the explicit imports
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #19226:
URL: https://github.com/apache/kafka/pull/19226#discussion_r2021438233
##########
checkstyle/import-control-server-common.xml:
##########
@@ -97,6 +97,7 @@
<subpackage name="purgatory">
<allow pkg="org.apache.kafka.server.metrics" />
<allow pkg="org.apache.kafka.server.util" />
+ <allow pkg="com.yammer.metrics" />
Review Comment:
Should this be `com.yammer.metrics.core`?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "gongxuanzhang (via GitHub)" <gi...@apache.org>.
gongxuanzhang commented on PR #19226:
URL: https://github.com/apache/kafka/pull/19226#issuecomment-2771132888
@chia7712 PTAL
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "gongxuanzhang (via GitHub)" <gi...@apache.org>.
gongxuanzhang commented on PR #19226:
URL: https://github.com/apache/kafka/pull/19226#issuecomment-2735105040
@m1a2st thanks for your review, i have changed the code.
I think this pr is a migration. we can't delete this parameter
```java
public static void recordExpiration(TopicPartition partition) {
AGGREGATE_EXPIRATION_METER.mark();
}
```
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "gongxuanzhang (via GitHub)" <gi...@apache.org>.
gongxuanzhang commented on PR #19226:
URL: https://github.com/apache/kafka/pull/19226#issuecomment-2743888376
@chia7712 PTAL
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "gongxuanzhang (via GitHub)" <gi...@apache.org>.
gongxuanzhang commented on PR #19226:
URL: https://github.com/apache/kafka/pull/19226#issuecomment-2746097255
@chia7712 PTAL
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on PR #19226:
URL: https://github.com/apache/kafka/pull/19226#issuecomment-2783370917
Yes
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "gongxuanzhang (via GitHub)" <gi...@apache.org>.
gongxuanzhang commented on PR #19226:
URL: https://github.com/apache/kafka/pull/19226#issuecomment-2783399502
@mimaison @chia7712
Thanks for your comments
I will create a MINOR PR to address it
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-19004:Move DelayedDeleteRecords to server-common module [kafka]
Posted by "gongxuanzhang (via GitHub)" <gi...@apache.org>.
gongxuanzhang commented on PR #19226:
URL: https://github.com/apache/kafka/pull/19226#issuecomment-2762049890
I changed this pr @mimaison PTAL
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org