diff --git a/core/src/main/scala/kafka/log/streamaspect/ElasticLog.scala b/core/src/main/scala/kafka/log/streamaspect/ElasticLog.scala index b3e5e743e2..cbdcae104e 100644 --- a/core/src/main/scala/kafka/log/streamaspect/ElasticLog.scala +++ b/core/src/main/scala/kafka/log/streamaspect/ElasticLog.scala @@ -462,9 +462,11 @@ class ElasticLog(val metaStream: MetaStream, partitionMeta.setRecoverOffset(recoveryPoint) maybeHandleIOException(s"Error while closing $topicPartition in dir ${dir.getParent}") { - CoreUtils.swallow(persistLogMeta(), this) CoreUtils.swallow(checkIfMemoryMappedBufferClosed(), this) CoreUtils.swallow(segments.close(), this) + // https://github.com/AutoMQ/automq/issues/2038 + // ElasticLogMeta should be saved after all segments are closed cause of the last segment may append new time index when close. + CoreUtils.swallow(persistLogMeta(), this) CoreUtils.swallow(persistPartitionMeta(), this) CoreUtils.swallow(closeStreams().get(), this) }