zhaijia created BOOKKEEPER-821:
----------------------------------

             Summary: Failing to write lastId to ledger directories should not 
fail startup of bookies
                 Key: BOOKKEEPER-821
                 URL: https://issues.apache.org/jira/browse/BOOKKEEPER-821
             Project: Bookkeeper
          Issue Type: Bug
          Components: bookkeeper-server
    Affects Versions: 4.3.0
            Reporter: zhaijia
            Assignee: zhaijia
             Fix For: 4.3.1


In EntryLoggerAllocator::allocateNewLog(), setLastLogId() failed, should not 
fail startup of bookies. 

Failed setLastLogId could tolerate because the while loop handles it.
{code}
        /**
         * Allocate a new log file.
         */
        BufferedLogChannel allocateNewLog() throws IOException {
            List<File> list = ledgerDirsManager.getWritableLedgerDirs();
            Collections.shuffle(list);
            // It would better not to overwrite existing entry log files
            File newLogFile = null;
            do {
                String logFileName = Long.toHexString(++preallocatedLogId) + 
".log";
                for (File dir : list) {
                    newLogFile = new File(dir, logFileName);
                    currentDir = dir;
                    if (newLogFile.exists()) {     < === this will handle last 
set fail, only caused a more loop.
                        LOG.warn("Found existed entry log " + newLogFile
                               + " when trying to create it as a new log.");
                        newLogFile = null;
                        break;
                    }
                }
            } while (newLogFile == null);

            FileChannel channel = new RandomAccessFile(newLogFile, 
"rw").getChannel();
            BufferedLogChannel logChannel = new BufferedLogChannel(channel,
                    conf.getWriteBufferBytes(), conf.getReadBufferBytes(), 
preallocatedLogId);
            logChannel.write((ByteBuffer) LOGFILE_HEADER.clear());

            for (File f : list) {
                setLastLogId(f, preallocatedLogId);
            }
            LOG.info("Preallocated entry logger {}.", preallocatedLogId);
            return logChannel;
        }
{code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to