@@ -23,7 +23,7 @@ import kafka.log.remote.RemoteLogManager
23
23
import kafka .log .{LogManager , OffsetResultHolder , UnifiedLog }
24
24
import kafka .server .HostedPartition .Online
25
25
import kafka .server .QuotaFactory .QuotaManagers
26
- import kafka .server .ReplicaManager .{AtMinIsrPartitionCountMetricName , FailedIsrUpdatesPerSecMetricName , IsrExpandsPerSecMetricName , IsrShrinksPerSecMetricName , LeaderCountMetricName , OfflineReplicaCountMetricName , PartitionCountMetricName , PartitionsWithLateTransactionsCountMetricName , ProducerIdCountMetricName , ReassigningPartitionsMetricName , UnderMinIsrPartitionCountMetricName , UnderReplicatedPartitionsMetricName , createLogReadResult }
26
+ import kafka .server .ReplicaManager .{AtMinIsrPartitionCountMetricName , FailedIsrUpdatesPerSecMetricName , IsrExpandsPerSecMetricName , IsrShrinksPerSecMetricName , LeaderCountMetricName , OfflineReplicaCountMetricName , PartitionCountMetricName , PartitionsWithLateTransactionsCountMetricName , ProducerIdCountMetricName , ReassigningPartitionsMetricName , UnderMinIsrPartitionCountMetricName , UnderReplicatedPartitionsMetricName , createLogReadResult , isListOffsetsTimestampUnsupported }
27
27
import kafka .server .metadata .ZkMetadataCache
28
28
import kafka .utils .Implicits ._
29
29
import kafka .utils ._
@@ -226,6 +226,14 @@ object ReplicaManager {
226
226
227
227
private [server] val MetricNames = GaugeMetricNames .union(MeterMetricNames )
228
228
229
+ private val timestampMinSupportedVersion : immutable.Map [Long , Short ] = immutable.Map [Long , Short ](
230
+ ListOffsetsRequest .EARLIEST_TIMESTAMP -> 1 .toShort,
231
+ ListOffsetsRequest .LATEST_TIMESTAMP -> 1 .toShort,
232
+ ListOffsetsRequest .MAX_TIMESTAMP -> 7 .toShort,
233
+ ListOffsetsRequest .EARLIEST_LOCAL_TIMESTAMP -> 8 .toShort,
234
+ ListOffsetsRequest .LATEST_TIERED_TIMESTAMP -> 9 .toShort
235
+ )
236
+
229
237
def createLogReadResult (highWatermark : Long ,
230
238
leaderLogStartOffset : Long ,
231
239
leaderLogEndOffset : Long ,
@@ -252,6 +260,11 @@ object ReplicaManager {
252
260
lastStableOffset = None ,
253
261
exception = Some (e))
254
262
}
263
+
264
+ private [server] def isListOffsetsTimestampUnsupported (timestamp : JLong , version : Short ): Boolean = {
265
+ timestamp < 0 &&
266
+ (! timestampMinSupportedVersion.contains(timestamp) || version < timestampMinSupportedVersion(timestamp))
267
+ }
255
268
}
256
269
257
270
class ReplicaManager (val config : KafkaConfig ,
@@ -1462,13 +1475,6 @@ class ReplicaManager(val config: KafkaConfig,
1462
1475
version : Short ,
1463
1476
buildErrorResponse : (Errors , ListOffsetsPartition ) => ListOffsetsPartitionResponse ,
1464
1477
responseCallback : List [ListOffsetsTopicResponse ] => Unit ): Unit = {
1465
- val timestampMinSupportedVersion = immutable.Map [Long , Short ](
1466
- ListOffsetsRequest .EARLIEST_TIMESTAMP -> 1 .toShort,
1467
- ListOffsetsRequest .LATEST_TIMESTAMP -> 1 .toShort,
1468
- ListOffsetsRequest .MAX_TIMESTAMP -> 7 .toShort,
1469
- ListOffsetsRequest .EARLIEST_LOCAL_TIMESTAMP -> 8 .toShort,
1470
- ListOffsetsRequest .LATEST_TIERED_TIMESTAMP -> 9 .toShort
1471
- )
1472
1478
val statusByPartition = mutable.Map [TopicPartition , ListOffsetsPartitionStatus ]()
1473
1479
topics.foreach { topic =>
1474
1480
topic.partitions.asScala.foreach { partition =>
@@ -1477,9 +1483,8 @@ class ReplicaManager(val config: KafkaConfig,
1477
1483
debug(s " OffsetRequest with correlation id $correlationId from client $clientId on partition $topicPartition " +
1478
1484
s " failed because the partition is duplicated in the request. " )
1479
1485
statusByPartition += topicPartition -> ListOffsetsPartitionStatus (Some (buildErrorResponse(Errors .INVALID_REQUEST , partition)))
1480
- } else if (partition.timestamp() < 0 &&
1481
- (! timestampMinSupportedVersion.contains(partition.timestamp()) || version < timestampMinSupportedVersion(partition.timestamp()))) {
1482
- buildErrorResponse(Errors .UNSUPPORTED_VERSION , partition)
1486
+ } else if (isListOffsetsTimestampUnsupported(partition.timestamp(), version)) {
1487
+ statusByPartition += topicPartition -> ListOffsetsPartitionStatus (Some (buildErrorResponse(Errors .UNSUPPORTED_VERSION , partition)))
1483
1488
} else {
1484
1489
try {
1485
1490
val fetchOnlyFromLeader = replicaId != ListOffsetsRequest .DEBUGGING_REPLICA_ID
0 commit comments