This commit is contained in:
Timothy Bish 2013-12-19 18:36:05 -05:00
parent 7656e8262c
commit c50b6c39ba
6 changed files with 28 additions and 12 deletions

View File

@ -155,7 +155,7 @@ class CallerBufferingDataFileAppender extends DataFileAppender {
}
if (forceToDisk) {
file.getFD().sync();
file.getChannel().force(false);
}
Journal.WriteCommand lastWrite = wb.writes.getTail();

View File

@ -155,7 +155,7 @@ final class DataFileAccessor {
int size = Math.min(data.getLength(), location.getSize());
file.write(data.getData(), data.getOffset(), size);
if (sync) {
file.getFD().sync();
file.getChannel().force(false);
}
}

View File

@ -365,7 +365,7 @@ class DataFileAppender implements FileAppender {
}
if (forceToDisk) {
file.getFD().sync();
file.getChannel().force(false);
}
Journal.WriteCommand lastWrite = wb.writes.getTail();

View File

@ -610,10 +610,10 @@ public class PageFile {
// So we don't loose it.. write it 2 times...
writeFile.seek(0);
writeFile.write(d);
writeFile.getFD().sync();
writeFile.getChannel().force(false);
writeFile.seek(PAGE_FILE_HEADER_SIZE / 2);
writeFile.write(d);
writeFile.getFD().sync();
writeFile.getChannel().force(false);
}
private void storeFreeList() throws IOException {
@ -1081,9 +1081,9 @@ public class PageFile {
if (enableDiskSyncs) {
// Sync to make sure recovery buffer writes land on disk..
if (enableRecoveryFile) {
recoveryFile.getFD().sync();
recoveryFile.getChannel().force(false);
}
writeFile.getFD().sync();
writeFile.getChannel().force(false);
}
} finally {
synchronized (writes) {
@ -1185,7 +1185,7 @@ public class PageFile {
}
// And sync it to disk
writeFile.getFD().sync();
writeFile.getChannel().force(false);
return nextTxId;
}

View File

@ -233,9 +233,9 @@ public class DiskBenchmark {
}
// Sync to disk so that the we actually write the data to disk.. otherwise
// OS buffering might not really do the write.
raf.getFD().sync();
raf.getChannel().force(false);
}
raf.getFD().sync();
raf.getChannel().force(false);
raf.close();
now = System.currentTimeMillis();
@ -254,7 +254,7 @@ public class DiskBenchmark {
for( long i=0; i+data.length < size; i+=data.length) {
raf.seek(i);
raf.write(data);
raf.getFD().sync();
raf.getChannel().force(false);
ioCount++;
now = System.currentTimeMillis();
if( (now-start)>sampleInterval ) {

View File

@ -16,7 +16,12 @@
*/
package org.apache.activemq.util;
import java.io.*;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
public class RecoverableRandomAccessFile implements java.io.DataOutput, java.io.DataInput, java.io.Closeable {
@ -388,6 +393,17 @@ public class RecoverableRandomAccessFile implements java.io.DataOutput, java.io.
throw ioe;
}
}
public FileChannel getChannel() throws IOException {
try {
return getRaf().getChannel();
} catch (IOException ioe)
{
handleException();
throw ioe;
}
}
public int read(byte[] b, int off, int len) throws IOException {
try {