Search in sources :

Example 46 with SequentialFile

use of org.apache.activemq.artemis.core.io.SequentialFile in project activemq-artemis by apache.

the class JournalImpl method cleanupTmpFiles.

/**
 * @throws Exception
 */
private void cleanupTmpFiles(final String extension) throws Exception {
    List<String> leftFiles = fileFactory.listFiles(getFileExtension() + extension);
    if (leftFiles.size() > 0) {
        ActiveMQJournalLogger.LOGGER.tempFilesLeftOpen();
        for (String fileToDelete : leftFiles) {
            ActiveMQJournalLogger.LOGGER.deletingOrphanedFile(fileToDelete);
            SequentialFile file = fileFactory.createSequentialFile(fileToDelete);
            file.delete();
        }
    }
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile)

Example 47 with SequentialFile

use of org.apache.activemq.artemis.core.io.SequentialFile in project activemq-artemis by apache.

the class JournalImpl method orderFiles.

/**
 * this method is used internally only however tools may use it to maintenance.
 * It won't be part of the interface as the tools should be specific to the implementation
 */
public List<JournalFile> orderFiles() throws Exception {
    List<String> fileNames = fileFactory.listFiles(filesRepository.getFileExtension());
    List<JournalFile> orderedFiles = new ArrayList<>(fileNames.size());
    for (String fileName : fileNames) {
        SequentialFile file = fileFactory.createSequentialFile(fileName);
        if (file.size() >= SIZE_HEADER) {
            file.open();
            try {
                JournalFileImpl jrnFile = readFileHeader(file);
                orderedFiles.add(jrnFile);
            } finally {
                file.close();
            }
        } else {
            ActiveMQJournalLogger.LOGGER.ignoringShortFile(fileName);
            file.delete();
        }
    }
    // Now order them by ordering id - we can't use the file name for ordering
    // since we can re-use dataFiles
    Collections.sort(orderedFiles, new JournalFileComparator());
    return orderedFiles;
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) ArrayList(java.util.ArrayList)

Example 48 with SequentialFile

use of org.apache.activemq.artemis.core.io.SequentialFile in project activemq-artemis by apache.

the class JournalFilesRepository method createFile0.

private JournalFile createFile0(final boolean keepOpened, final boolean multiAIO, final boolean init, final boolean tmpCompact, final long fileIdPreSet) throws Exception {
    long fileID = fileIdPreSet != -1 ? fileIdPreSet : generateFileID();
    final String fileName = createFileName(tmpCompact, fileID);
    if (logger.isTraceEnabled()) {
        logger.trace("Creating file " + fileName);
    }
    String tmpFileName = fileName + ".tmp";
    SequentialFile sequentialFile = fileFactory.createSequentialFile(tmpFileName);
    sequentialFile.open(1, false);
    if (init) {
        sequentialFile.fill(fileSize);
        JournalImpl.initFileHeader(fileFactory, sequentialFile, userVersion, fileID);
    }
    long position = sequentialFile.position();
    sequentialFile.close();
    if (logger.isTraceEnabled()) {
        logger.trace("Renaming file " + tmpFileName + " as " + fileName);
    }
    sequentialFile.renameTo(fileName);
    if (keepOpened) {
        if (multiAIO) {
            sequentialFile.open();
        } else {
            sequentialFile.open(1, false);
        }
        sequentialFile.position(position);
    }
    return new JournalFileImpl(sequentialFile, fileID, JournalImpl.FORMAT_VERSION);
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile)

Example 49 with SequentialFile

use of org.apache.activemq.artemis.core.io.SequentialFile in project activemq-artemis by apache.

the class JournalFilesRepository method reinitializeFile.

// Discard the old JournalFile and set it with a new ID
private JournalFile reinitializeFile(final JournalFile file) throws Exception {
    long newFileID = generateFileID();
    SequentialFile sf = file.getFile();
    sf.open(1, false);
    int position = JournalImpl.initFileHeader(fileFactory, sf, userVersion, newFileID);
    JournalFile jf = new JournalFileImpl(sf, newFileID, JournalImpl.FORMAT_VERSION);
    sf.position(position);
    sf.close();
    return jf;
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile)

Example 50 with SequentialFile

use of org.apache.activemq.artemis.core.io.SequentialFile in project activemq-artemis by apache.

the class NIOJournalCompactTest method testControlFile.

// General tests
// =============
@Test
public void testControlFile() throws Exception {
    ArrayList<JournalFile> dataFiles = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        SequentialFile file = fileFactory.createSequentialFile("file-" + i + ".tst");
        dataFiles.add(new JournalFileImpl(file, 0, JournalImpl.FORMAT_VERSION));
    }
    ArrayList<JournalFile> newFiles = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        SequentialFile file = fileFactory.createSequentialFile("file-" + i + ".tst.new");
        newFiles.add(new JournalFileImpl(file, 0, JournalImpl.FORMAT_VERSION));
    }
    ArrayList<Pair<String, String>> renames = new ArrayList<>();
    renames.add(new Pair<>("a", "b"));
    renames.add(new Pair<>("c", "d"));
    AbstractJournalUpdateTask.writeControlFile(fileFactory, dataFiles, newFiles, renames);
    ArrayList<String> strDataFiles = new ArrayList<>();
    ArrayList<String> strNewFiles = new ArrayList<>();
    ArrayList<Pair<String, String>> renamesRead = new ArrayList<>();
    Assert.assertNotNull(JournalCompactor.readControlFile(fileFactory, strDataFiles, strNewFiles, renamesRead));
    Assert.assertEquals(dataFiles.size(), strDataFiles.size());
    Assert.assertEquals(newFiles.size(), strNewFiles.size());
    Assert.assertEquals(renames.size(), renamesRead.size());
    Iterator<String> iterDataFiles = strDataFiles.iterator();
    for (JournalFile file : dataFiles) {
        Assert.assertEquals(file.getFile().getFileName(), iterDataFiles.next());
    }
    Assert.assertFalse(iterDataFiles.hasNext());
    Iterator<String> iterNewFiles = strNewFiles.iterator();
    for (JournalFile file : newFiles) {
        Assert.assertEquals(file.getFile().getFileName(), iterNewFiles.next());
    }
    Assert.assertFalse(iterNewFiles.hasNext());
    Iterator<Pair<String, String>> iterRename = renames.iterator();
    for (Pair<String, String> rename : renamesRead) {
        Pair<String, String> original = iterRename.next();
        Assert.assertEquals(original.getA(), rename.getA());
        Assert.assertEquals(original.getB(), rename.getB());
    }
    Assert.assertFalse(iterNewFiles.hasNext());
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) ArrayList(java.util.ArrayList) JournalFile(org.apache.activemq.artemis.core.journal.impl.JournalFile) JournalFileImpl(org.apache.activemq.artemis.core.journal.impl.JournalFileImpl) Pair(org.apache.activemq.artemis.api.core.Pair) Test(org.junit.Test)

Aggregations

SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)53 Test (org.junit.Test)21 ByteBuffer (java.nio.ByteBuffer)15 ArrayList (java.util.ArrayList)10 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)9 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)7 Pair (org.apache.activemq.artemis.api.core.Pair)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)4 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)4 Page (org.apache.activemq.artemis.core.paging.impl.Page)4 JDBCSequentialFile (org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile)4 SimpleEncoding (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding)4 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)3 IOCriticalErrorListener (org.apache.activemq.artemis.core.io.IOCriticalErrorListener)3 PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)3 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2