src/java/org/apache/cassandra/db/commitlog/CommitLog.java
/**
     * Perform recovery on commit logs located in the directory specified by the config file.
     *
     * @return the number of mutations replayed
     */
Perform recovery on commit logs located in the directory specified by the config file.
@return the number of mutations replayed
Perform recovery on commit logs located in the directory specified by the config file . @return the number of mutations replayed
public int recover() throws IOException
    {
        File[] files = new File(DatabaseDescriptor.getCommitLogLocation()).listFiles(new FilenameFilter()
        {
            public boolean accept(File dir, String name)
            {
                return CommitLogSegment.possibleCommitLogFile(name) && !instance.allocator.manages(name);
            }
        });
        int replayed = 0;
        if (files.length == 0)
        {
            logger.info("No commitlog files found; skipping replay");
        }
        else
        {
            Arrays.sort(files, new FileUtils.FileComparator());
            logger.info("Replaying " + StringUtils.join(files, ", "));
            replayed = recover(files);
            logger.info("Log replay complete, " + replayed + " replayed mutations");
            for (File f : files)
                CommitLog.instance.allocator.recycleSegment(f);
        }
        allocator.enableReserveSegmentCreation();
        return replayed;
    }
public int recover ( ) throws IOException { File [ ] files = new File ( DatabaseDescriptor . getCommitLogLocation ( ) ) . listFiles ( new FilenameFilter ( ) { public boolean accept ( File dir , String name ) { return CommitLogSegment . possibleCommitLogFile ( name ) && ! instance . allocator . manages ( name ) ; } } ) ; int replayed = 0 ; if ( files . length == 0 ) { logger . info ( "No commitlog files found; skipping replay" ) ; } else { Arrays . sort ( files , new FileUtils . FileComparator ( ) ) ; logger . info ( "Replaying " + StringUtils . join ( files , ", " ) ) ; replayed = recover ( files ) ; logger . info ( "Log replay complete, " + replayed + " replayed mutations" ) ; for ( File f : files ) CommitLog . instance . allocator . recycleSegment ( f ) ; } allocator . enableReserveSegmentCreation ( ) ; return replayed ; }
Perform recovery on commit logs located in the directory specified by the config file.
Perform recovery on commit logs located in the directory specified by the config file .
// we used to try to avoid instantiating commitlog (thus creating an empty segment ready for writes) // until after recover was finished.  this turns out to be fragile; it is less error-prone to go // ahead and allow writes before recover(), and just skip active segments when we do.