forked from apache/kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MINOR Refactored the existing CheckpointFile in core module, moved to…
… server-common module and introduced it as SnapshotFile. (apache#11060) MINOR Refactored the existing CheckpointFile in core module, moved to server-common module. Refactored CheckpointFile to server-common module as a Java class and it is reused by LeaderCheckpointFile, OffsetCheckpointFile. This will be used by CommittedOffsetsFile which checkpoints remote log metadata partitions with respective offsets in the default RemoteLogMetadataManager implementation. Existing tests are available for LeaderCheckpointFile, OffsetCheckpointFile. Reviewers: Jun Rao <junrao@gmail.com>
- Loading branch information
Showing
7 changed files
with
274 additions
and
163 deletions.
There are no files selected for viewing
142 changes: 0 additions & 142 deletions
142
core/src/main/scala/kafka/server/checkpoints/CheckpointFile.scala
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
core/src/main/scala/kafka/server/checkpoints/CheckpointFileWithFailureHandler.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* 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.checkpoints | ||
|
||
import kafka.server.LogDirFailureChannel | ||
import org.apache.kafka.common.errors.KafkaStorageException | ||
import org.apache.kafka.server.common.CheckpointFile | ||
import CheckpointFile.EntryFormatter | ||
|
||
import java.io._ | ||
import scala.collection.Seq | ||
import scala.jdk.CollectionConverters._ | ||
|
||
class CheckpointFileWithFailureHandler[T](val file: File, | ||
version: Int, | ||
formatter: EntryFormatter[T], | ||
logDirFailureChannel: LogDirFailureChannel, | ||
logDir: String) { | ||
private val checkpointFile = new CheckpointFile[T](file, version, formatter) | ||
|
||
def write(entries: Iterable[T]): Unit = { | ||
try { | ||
checkpointFile.write(entries.toSeq.asJava) | ||
} catch { | ||
case e: IOException => | ||
val msg = s"Error while writing to checkpoint file ${file.getAbsolutePath}" | ||
logDirFailureChannel.maybeAddOfflineLogDir(logDir, msg, e) | ||
throw new KafkaStorageException(msg, e) | ||
} | ||
} | ||
|
||
def read(): Seq[T] = { | ||
try { | ||
checkpointFile.read().asScala | ||
} catch { | ||
case e: IOException => | ||
val msg = s"Error while reading checkpoint file ${file.getAbsolutePath}" | ||
logDirFailureChannel.maybeAddOfflineLogDir(logDir, msg, e) | ||
throw new KafkaStorageException(msg, e) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.