提交 12afe134 authored 作者: Noel Grandin's avatar Noel Grandin

FileStore count fields need to be atomically accessed

shows up as random failures in the TestMVStore.testFastDelete test case
上级 45ff40c5
......@@ -10,7 +10,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.channels.OverlappingFileLockException;
import java.util.concurrent.atomic.AtomicLong;
import org.h2.mvstore.cache.FilePathCache;
import org.h2.store.fs.FilePath;
import org.h2.store.fs.FilePathDisk;
......@@ -27,22 +27,22 @@ public class FileStore {
/**
* The number of read operations.
*/
protected long readCount;
protected final AtomicLong readCount = new AtomicLong(0);
/**
* The number of read bytes.
*/
protected long readBytes;
protected final AtomicLong readBytes = new AtomicLong(0);
/**
* The number of write operations.
*/
protected long writeCount;
protected final AtomicLong writeCount = new AtomicLong(0);
/**
* The number of written bytes.
*/
protected long writeBytes;
protected final AtomicLong writeBytes = new AtomicLong(0);
/**
* The free spaces between the chunks. The first block to use is block 2
......@@ -96,8 +96,8 @@ public class FileStore {
public ByteBuffer readFully(long pos, int len) {
ByteBuffer dst = ByteBuffer.allocate(len);
DataUtils.readFully(file, pos, dst);
readCount++;
readBytes += len;
readCount.incrementAndGet();
readBytes.addAndGet(len);
return dst;
}
......@@ -111,8 +111,8 @@ public class FileStore {
int len = src.remaining();
fileSize = Math.max(fileSize, pos + len);
DataUtils.writeFully(file, pos, src);
writeCount++;
writeBytes += len;
writeCount.incrementAndGet();
writeBytes.addAndGet(len);
}
/**
......@@ -231,7 +231,7 @@ public class FileStore {
*/
public void truncate(long size) {
try {
writeCount++;
writeCount.incrementAndGet();
file.truncate(size);
fileSize = Math.min(fileSize, size);
} catch (IOException e) {
......@@ -273,7 +273,7 @@ public class FileStore {
* @return the number of write operations
*/
public long getWriteCount() {
return writeCount;
return writeCount.get();
}
/**
......@@ -282,7 +282,7 @@ public class FileStore {
* @return the number of write operations
*/
public long getWriteBytes() {
return writeBytes;
return writeBytes.get();
}
/**
......@@ -292,7 +292,7 @@ public class FileStore {
* @return the number of read operations
*/
public long getReadCount() {
return readCount;
return readCount.get();
}
/**
......@@ -301,7 +301,7 @@ public class FileStore {
* @return the number of write operations
*/
public long getReadBytes() {
return readBytes;
return readBytes.get();
}
public boolean isReadOnly() {
......
......@@ -1292,7 +1292,7 @@ public final class MVStore {
private Set<Integer> collectReferencedChunks() {
long testVersion = lastChunk.version;
DataUtils.checkArgument(testVersion > 0, "Collect references on version 0");
long readCount = getFileStore().readCount;
long readCount = getFileStore().readCount.get();
Set<Integer> referenced = New.hashSet();
for (Cursor<String, String> c = meta.cursor("root."); c.hasNext();) {
String key = c.next();
......@@ -1308,7 +1308,7 @@ public final class MVStore {
}
long pos = lastChunk.metaRootPos;
collectReferencedChunks(referenced, 0, pos, 0);
readCount = fileStore.readCount - readCount;
readCount = fileStore.readCount.get() - readCount;
return referenced;
}
......
......@@ -37,8 +37,8 @@ public class OffHeapStore extends FileStore {
DataUtils.ERROR_READING_FAILED,
"Could not read from position {0}", pos);
}
readCount++;
readBytes += len;
readCount.incrementAndGet();
readBytes.addAndGet(len);
ByteBuffer buff = memEntry.getValue();
ByteBuffer read = buff.duplicate();
int offset = (int) (pos - memEntry.getKey());
......@@ -80,8 +80,8 @@ public class OffHeapStore extends FileStore {
"Could not write to position {0}; " +
"partial overwrite is not supported", pos);
}
writeCount++;
writeBytes += length;
writeCount.incrementAndGet();
writeBytes.addAndGet(length);
buff.rewind();
buff.put(src);
return;
......@@ -97,8 +97,8 @@ public class OffHeapStore extends FileStore {
private void writeNewEntry(long pos, ByteBuffer src) {
int length = src.remaining();
writeCount++;
writeBytes += length;
writeCount.incrementAndGet();
writeBytes.addAndGet(length);
ByteBuffer buff = ByteBuffer.allocateDirect(length);
buff.put(src);
buff.rewind();
......@@ -107,7 +107,7 @@ public class OffHeapStore extends FileStore {
@Override
public void truncate(long size) {
writeCount++;
writeCount.incrementAndGet();
if (size == 0) {
fileSize = 0;
memory.clear();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论