提交 fdc5aa12 authored 作者: Noel Grandin's avatar Noel Grandin

rename FileOperation to FileWriteOperation

上级 8959c4f3
...@@ -13,7 +13,6 @@ import java.nio.channels.FileChannel; ...@@ -13,7 +13,6 @@ import java.nio.channels.FileChannel;
import java.nio.channels.FileLock; import java.nio.channels.FileLock;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random; import java.util.Random;
import org.h2.store.fs.FileBase; import org.h2.store.fs.FileBase;
import org.h2.store.fs.FilePath; import org.h2.store.fs.FilePath;
import org.h2.store.fs.FilePathWrapper; import org.h2.store.fs.FilePathWrapper;
...@@ -163,7 +162,7 @@ class FileReorderWrites extends FileBase { ...@@ -163,7 +162,7 @@ class FileReorderWrites extends FileBase {
/** /**
* The list of not yet applied to the base channel. It is sorted by time. * The list of not yet applied to the base channel. It is sorted by time.
*/ */
private ArrayList<FileOperation> notAppliedList = new ArrayList<FileOperation>(); private ArrayList<FileWriteOperation> notAppliedList = new ArrayList<FileWriteOperation>();
private int id; private int id;
...@@ -212,17 +211,17 @@ class FileReorderWrites extends FileBase { ...@@ -212,17 +211,17 @@ class FileReorderWrites extends FileBase {
if (oldSize <= newSize) { if (oldSize <= newSize) {
return this; return this;
} }
addOperation(new FileOperation(id++, newSize, null)); addOperation(new FileWriteOperation(id++, newSize, null));
return this; return this;
} }
private int addOperation(FileOperation op) throws IOException { private int addOperation(FileWriteOperation op) throws IOException {
trace("op " + op); trace("op " + op);
checkError(); checkError();
notAppliedList.add(op); notAppliedList.add(op);
long now = op.getTime(); long now = op.getTime();
for (int i = 0; i < notAppliedList.size() - 1; i++) { for (int i = 0; i < notAppliedList.size() - 1; i++) {
FileOperation old = notAppliedList.get(i); FileWriteOperation old = notAppliedList.get(i);
boolean applyOld = false; boolean applyOld = false;
// String reason = ""; // String reason = "";
if (old.getTime() + 45000 < now) { if (old.getTime() + 45000 < now) {
...@@ -247,7 +246,7 @@ class FileReorderWrites extends FileBase { ...@@ -247,7 +246,7 @@ class FileReorderWrites extends FileBase {
private void applyAll() throws IOException { private void applyAll() throws IOException {
trace("applyAll"); trace("applyAll");
for (FileOperation op : notAppliedList) { for (FileWriteOperation op : notAppliedList) {
op.apply(base); op.apply(base);
} }
notAppliedList.clear(); notAppliedList.clear();
...@@ -262,12 +261,12 @@ class FileReorderWrites extends FileBase { ...@@ -262,12 +261,12 @@ class FileReorderWrites extends FileBase {
@Override @Override
public int write(ByteBuffer src) throws IOException { public int write(ByteBuffer src) throws IOException {
return addOperation(new FileOperation(id++, readBase.position(), src)); return addOperation(new FileWriteOperation(id++, readBase.position(), src));
} }
@Override @Override
public int write(ByteBuffer src, long position) throws IOException { public int write(ByteBuffer src, long position) throws IOException {
return addOperation(new FileOperation(id++, position, src)); return addOperation(new FileWriteOperation(id++, position, src));
} }
private void checkError() throws IOException { private void checkError() throws IOException {
...@@ -298,13 +297,13 @@ class FileReorderWrites extends FileBase { ...@@ -298,13 +297,13 @@ class FileReorderWrites extends FileBase {
* A file operation (that might be re-ordered with other operations, or not * A file operation (that might be re-ordered with other operations, or not
* be applied on power failure). * be applied on power failure).
*/ */
static class FileOperation { static class FileWriteOperation {
private final int id; private final int id;
private final long time; private final long time;
private final ByteBuffer buffer; private final ByteBuffer buffer;
private final long position; private final long position;
FileOperation(int id, long position, ByteBuffer src) { FileWriteOperation(int id, long position, ByteBuffer src) {
this.id = id; this.id = id;
this.time = System.currentTimeMillis(); this.time = System.currentTimeMillis();
if (src == null) { if (src == null) {
...@@ -329,7 +328,7 @@ class FileReorderWrites extends FileBase { ...@@ -329,7 +328,7 @@ class FileReorderWrites extends FileBase {
* @param other the other operation * @param other the other operation
* @return if there is an overlap * @return if there is an overlap
*/ */
boolean overlaps(FileOperation other) { boolean overlaps(FileWriteOperation other) {
if (isTruncate() && other.isTruncate()) { if (isTruncate() && other.isTruncate()) {
// we just keep the latest truncate operation // we just keep the latest truncate operation
return true; return true;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论