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();
}
}
}
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;
}
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);
}
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;
}
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());
}
Aggregations