Search in sources :

Example 1 with CommitLogSegmentFileComparator

use of org.apache.cassandra.db.commitlog.CommitLogSegment.CommitLogSegmentFileComparator in project cassandra by apache.

the class CommitLog method recoverSegmentsOnDisk.

/**
 * Perform recovery on commit logs located in the directory specified by the config file.
 *
 * @return the number of mutations replayed
 * @throws IOException
 */
public int recoverSegmentsOnDisk() throws IOException {
    BiPredicate<File, String> unmanagedFilesFilter = (dir, name) -> CommitLogDescriptor.isValid(name) && CommitLogSegment.shouldReplay(name);
    // archiving pass, which we should not treat as serious.
    for (File file : new File(segmentManager.storageDirectory).tryList(unmanagedFilesFilter)) {
        archiver.maybeArchive(file.path(), file.name());
        archiver.maybeWaitForArchiving(file.name());
    }
    assert archiver.archivePending.isEmpty() : "Not all commit log archive tasks were completed before restore";
    archiver.maybeRestoreArchive();
    // List the files again as archiver may have added segments.
    File[] files = new File(segmentManager.storageDirectory).tryList(unmanagedFilesFilter);
    int replayed = 0;
    if (files.length == 0) {
        logger.info("No commitlog files found; skipping replay");
    } else {
        Arrays.sort(files, new CommitLogSegmentFileComparator());
        logger.info("Replaying {}", StringUtils.join(files, ", "));
        replayed = recoverFiles(files);
        logger.info("Log replay complete, {} replayed mutations", replayed);
        for (File f : files) segmentManager.handleReplayedSegment(f);
    }
    return replayed;
}
Also used : DataOutputBufferFixed(org.apache.cassandra.io.util.DataOutputBufferFixed) java.util(java.util) BufferedDataOutputStreamPlus(org.apache.cassandra.io.util.BufferedDataOutputStreamPlus) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) TableId(org.apache.cassandra.schema.TableId) EncryptionContext(org.apache.cassandra.security.EncryptionContext) File(org.apache.cassandra.io.util.File) LoggerFactory(org.slf4j.LoggerFactory) org.apache.cassandra.db(org.apache.cassandra.db) ICompressor(org.apache.cassandra.io.compress.ICompressor) Function(java.util.function.Function) StringUtils(org.apache.commons.lang3.StringUtils) FBUtilities.updateChecksum(org.apache.cassandra.utils.FBUtilities.updateChecksum) ByteBuffer(java.nio.ByteBuffer) BiPredicate(java.util.function.BiPredicate) Allocation(org.apache.cassandra.db.commitlog.CommitLogSegment.Allocation) CDCWriteException(org.apache.cassandra.exceptions.CDCWriteException) PathUtils(org.apache.cassandra.io.util.PathUtils) CommitLogMetrics(org.apache.cassandra.metrics.CommitLogMetrics) FBUtilities.updateChecksumInt(org.apache.cassandra.utils.FBUtilities.updateChecksumInt) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) JVMStabilityInspector(org.apache.cassandra.utils.JVMStabilityInspector) FSWriteError(org.apache.cassandra.io.FSWriteError) MessagingService(org.apache.cassandra.net.MessagingService) Logger(org.slf4j.Logger) FileStore(java.nio.file.FileStore) StorageService(org.apache.cassandra.service.StorageService) IOException(java.io.IOException) ENTRY_OVERHEAD_SIZE(org.apache.cassandra.db.commitlog.CommitLogSegment.ENTRY_OVERHEAD_SIZE) CompressionParams(org.apache.cassandra.schema.CompressionParams) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) ParameterizedClass(org.apache.cassandra.config.ParameterizedClass) FileUtils(org.apache.cassandra.io.util.FileUtils) MBeanWrapper(org.apache.cassandra.utils.MBeanWrapper) CRC32(java.util.zip.CRC32) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) CommitLogSegmentFileComparator(org.apache.cassandra.db.commitlog.CommitLogSegment.CommitLogSegmentFileComparator) File(org.apache.cassandra.io.util.File) CommitLogSegmentFileComparator(org.apache.cassandra.db.commitlog.CommitLogSegment.CommitLogSegmentFileComparator)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 FileStore (java.nio.file.FileStore)1 java.util (java.util)1 BiPredicate (java.util.function.BiPredicate)1 Function (java.util.function.Function)1 CRC32 (java.util.zip.CRC32)1 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)1 ParameterizedClass (org.apache.cassandra.config.ParameterizedClass)1 org.apache.cassandra.db (org.apache.cassandra.db)1 Allocation (org.apache.cassandra.db.commitlog.CommitLogSegment.Allocation)1 CommitLogSegmentFileComparator (org.apache.cassandra.db.commitlog.CommitLogSegment.CommitLogSegmentFileComparator)1 ENTRY_OVERHEAD_SIZE (org.apache.cassandra.db.commitlog.CommitLogSegment.ENTRY_OVERHEAD_SIZE)1 CDCWriteException (org.apache.cassandra.exceptions.CDCWriteException)1 FSWriteError (org.apache.cassandra.io.FSWriteError)1 ICompressor (org.apache.cassandra.io.compress.ICompressor)1 BufferedDataOutputStreamPlus (org.apache.cassandra.io.util.BufferedDataOutputStreamPlus)1 DataOutputBuffer (org.apache.cassandra.io.util.DataOutputBuffer)1