Unverified 提交 3bf8fd6a authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #1241 from grandinj/misc1

Various tweaks in attempting to fix TestDiskFull test
...@@ -10,7 +10,6 @@ import java.util.Iterator; ...@@ -10,7 +10,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.PriorityQueue; import java.util.PriorityQueue;
import java.util.Queue; import java.util.Queue;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.command.dml.AllColumnsForPlan; import org.h2.command.dml.AllColumnsForPlan;
import org.h2.engine.Database; import org.h2.engine.Database;
...@@ -69,7 +68,9 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex { ...@@ -69,7 +68,9 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
dataMap = t.openMap(mapName, keyType, valueType); dataMap = t.openMap(mapName, keyType, valueType);
t.commit(); t.commit();
if (!keyType.equals(dataMap.getKeyType())) { if (!keyType.equals(dataMap.getKeyType())) {
throw DbException.throwInternalError("Incompatible key type"); throw DbException.throwInternalError(
"Incompatible key type, expected " + keyType + " but got "
+ dataMap.getKeyType() + " for index " + indexName);
} }
} }
...@@ -174,7 +175,9 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex { ...@@ -174,7 +175,9 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
MVMap<ValueArray, Value> map = database.getMvStore(). MVMap<ValueArray, Value> map = database.getMvStore().
getStore().openMap(mapName, builder); getStore().openMap(mapName, builder);
if (!keyType.equals(map.getKeyType())) { if (!keyType.equals(map.getKeyType())) {
throw DbException.throwInternalError("Incompatible key type"); throw DbException.throwInternalError(
"Incompatible key type, expected " + keyType + " but got "
+ map.getKeyType() + " for map " + mapName);
} }
return map; return map;
} }
......
...@@ -17,6 +17,14 @@ import java.nio.channels.WritableByteChannel; ...@@ -17,6 +17,14 @@ import java.nio.channels.WritableByteChannel;
* Fake file channel to use by in-memory and ZIP file systems. * Fake file channel to use by in-memory and ZIP file systems.
*/ */
public class FakeFileChannel extends FileChannel { public class FakeFileChannel extends FileChannel {
/**
* No need to allocate these, they have no state
*/
public static final FakeFileChannel INSTANCE = new FakeFileChannel();
private FakeFileChannel() {}
@Override @Override
protected void implCloseChannel() throws IOException { protected void implCloseChannel() throws IOException {
throw new IOException(); throw new IOException();
......
...@@ -9,6 +9,7 @@ import java.io.IOException; ...@@ -9,6 +9,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.nio.channels.FileLock; import java.nio.channels.FileLock;
import java.nio.channels.NonWritableChannelException; import java.nio.channels.NonWritableChannelException;
...@@ -19,7 +20,6 @@ import java.util.List; ...@@ -19,7 +20,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.compress.CompressLZF; import org.h2.compress.CompressLZF;
import org.h2.message.DbException; import org.h2.message.DbException;
...@@ -268,7 +268,7 @@ class FileMem extends FileBase { ...@@ -268,7 +268,7 @@ class FileMem extends FileBase {
/** /**
* The file data. * The file data.
*/ */
final FileMemData data; FileMemData data;
private final boolean readOnly; private final boolean readOnly;
private long pos; private long pos;
...@@ -289,6 +289,9 @@ class FileMem extends FileBase { ...@@ -289,6 +289,9 @@ class FileMem extends FileBase {
if (readOnly) { if (readOnly) {
throw new NonWritableChannelException(); throw new NonWritableChannelException();
} }
if (data == null) {
throw new ClosedChannelException();
}
if (newLength < size()) { if (newLength < size()) {
data.touch(readOnly); data.touch(readOnly);
pos = Math.min(pos, newLength); pos = Math.min(pos, newLength);
...@@ -305,6 +308,9 @@ class FileMem extends FileBase { ...@@ -305,6 +308,9 @@ class FileMem extends FileBase {
@Override @Override
public int write(ByteBuffer src, long position) throws IOException { public int write(ByteBuffer src, long position) throws IOException {
if (data == null) {
throw new ClosedChannelException();
}
int len = src.remaining(); int len = src.remaining();
if (len == 0) { if (len == 0) {
return 0; return 0;
...@@ -318,6 +324,9 @@ class FileMem extends FileBase { ...@@ -318,6 +324,9 @@ class FileMem extends FileBase {
@Override @Override
public int write(ByteBuffer src) throws IOException { public int write(ByteBuffer src) throws IOException {
if (data == null) {
throw new ClosedChannelException();
}
int len = src.remaining(); int len = src.remaining();
if (len == 0) { if (len == 0) {
return 0; return 0;
...@@ -331,6 +340,9 @@ class FileMem extends FileBase { ...@@ -331,6 +340,9 @@ class FileMem extends FileBase {
@Override @Override
public int read(ByteBuffer dst, long position) throws IOException { public int read(ByteBuffer dst, long position) throws IOException {
if (data == null) {
throw new ClosedChannelException();
}
int len = dst.remaining(); int len = dst.remaining();
if (len == 0) { if (len == 0) {
return 0; return 0;
...@@ -347,6 +359,9 @@ class FileMem extends FileBase { ...@@ -347,6 +359,9 @@ class FileMem extends FileBase {
@Override @Override
public int read(ByteBuffer dst) throws IOException { public int read(ByteBuffer dst) throws IOException {
if (data == null) {
throw new ClosedChannelException();
}
int len = dst.remaining(); int len = dst.remaining();
if (len == 0) { if (len == 0) {
return 0; return 0;
...@@ -370,6 +385,7 @@ class FileMem extends FileBase { ...@@ -370,6 +385,7 @@ class FileMem extends FileBase {
@Override @Override
public void implCloseChannel() throws IOException { public void implCloseChannel() throws IOException {
pos = 0; pos = 0;
data = null;
} }
@Override @Override
...@@ -380,6 +396,9 @@ class FileMem extends FileBase { ...@@ -380,6 +396,9 @@ class FileMem extends FileBase {
@Override @Override
public synchronized FileLock tryLock(long position, long size, public synchronized FileLock tryLock(long position, long size,
boolean shared) throws IOException { boolean shared) throws IOException {
if (data == null) {
throw new ClosedChannelException();
}
if (shared) { if (shared) {
if (!data.lockShared()) { if (!data.lockShared()) {
return null; return null;
...@@ -390,7 +409,7 @@ class FileMem extends FileBase { ...@@ -390,7 +409,7 @@ class FileMem extends FileBase {
} }
} }
return new FileLock(new FakeFileChannel(), position, size, shared) { return new FileLock(FakeFileChannel.INSTANCE, position, size, shared) {
@Override @Override
public boolean isValid() { public boolean isValid() {
...@@ -406,7 +425,7 @@ class FileMem extends FileBase { ...@@ -406,7 +425,7 @@ class FileMem extends FileBase {
@Override @Override
public String toString() { public String toString() {
return data.getName(); return data == null ? "<closed>" : data.getName();
} }
} }
...@@ -521,11 +540,13 @@ class FileMemData { ...@@ -521,11 +540,13 @@ class FileMemData {
/** /**
* Unlock the file. * Unlock the file.
*/ */
synchronized void unlock() { synchronized void unlock() throws IOException {
if (isLockedExclusive) { if (isLockedExclusive) {
isLockedExclusive = false; isLockedExclusive = false;
} else if (sharedLockCount > 0) {
sharedLockCount--;
} else { } else {
sharedLockCount = Math.max(0, sharedLockCount - 1); throw new IOException("not locked");
} }
} }
......
...@@ -9,6 +9,7 @@ import java.io.IOException; ...@@ -9,6 +9,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.nio.channels.FileLock; import java.nio.channels.FileLock;
import java.nio.channels.NonWritableChannelException; import java.nio.channels.NonWritableChannelException;
...@@ -19,7 +20,6 @@ import java.util.Map; ...@@ -19,7 +20,6 @@ import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.compress.CompressLZF; import org.h2.compress.CompressLZF;
import org.h2.message.DbException; import org.h2.message.DbException;
...@@ -277,7 +277,7 @@ class FileNioMem extends FileBase { ...@@ -277,7 +277,7 @@ class FileNioMem extends FileBase {
/** /**
* The file data. * The file data.
*/ */
final FileNioMemData data; FileNioMemData data;
private final boolean readOnly; private final boolean readOnly;
private long pos; private long pos;
...@@ -298,6 +298,9 @@ class FileNioMem extends FileBase { ...@@ -298,6 +298,9 @@ class FileNioMem extends FileBase {
if (readOnly) { if (readOnly) {
throw new NonWritableChannelException(); throw new NonWritableChannelException();
} }
if (data == null) {
throw new ClosedChannelException();
}
if (newLength < size()) { if (newLength < size()) {
data.touch(readOnly); data.touch(readOnly);
pos = Math.min(pos, newLength); pos = Math.min(pos, newLength);
...@@ -314,6 +317,9 @@ class FileNioMem extends FileBase { ...@@ -314,6 +317,9 @@ class FileNioMem extends FileBase {
@Override @Override
public int write(ByteBuffer src) throws IOException { public int write(ByteBuffer src) throws IOException {
if (data == null) {
throw new ClosedChannelException();
}
int len = src.remaining(); int len = src.remaining();
if (len == 0) { if (len == 0) {
return 0; return 0;
...@@ -327,6 +333,9 @@ class FileNioMem extends FileBase { ...@@ -327,6 +333,9 @@ class FileNioMem extends FileBase {
@Override @Override
public int read(ByteBuffer dst) throws IOException { public int read(ByteBuffer dst) throws IOException {
if (data == null) {
throw new ClosedChannelException();
}
int len = dst.remaining(); int len = dst.remaining();
if (len == 0) { if (len == 0) {
return 0; return 0;
...@@ -343,6 +352,9 @@ class FileNioMem extends FileBase { ...@@ -343,6 +352,9 @@ class FileNioMem extends FileBase {
@Override @Override
public int read(ByteBuffer dst, long position) throws IOException { public int read(ByteBuffer dst, long position) throws IOException {
if (data == null) {
throw new ClosedChannelException();
}
int len = dst.remaining(); int len = dst.remaining();
if (len == 0) { if (len == 0) {
return 0; return 0;
...@@ -365,6 +377,7 @@ class FileNioMem extends FileBase { ...@@ -365,6 +377,7 @@ class FileNioMem extends FileBase {
@Override @Override
public void implCloseChannel() throws IOException { public void implCloseChannel() throws IOException {
pos = 0; pos = 0;
data = null;
} }
@Override @Override
...@@ -375,6 +388,9 @@ class FileNioMem extends FileBase { ...@@ -375,6 +388,9 @@ class FileNioMem extends FileBase {
@Override @Override
public synchronized FileLock tryLock(long position, long size, public synchronized FileLock tryLock(long position, long size,
boolean shared) throws IOException { boolean shared) throws IOException {
if (data == null) {
throw new ClosedChannelException();
}
if (shared) { if (shared) {
if (!data.lockShared()) { if (!data.lockShared()) {
return null; return null;
...@@ -385,7 +401,7 @@ class FileNioMem extends FileBase { ...@@ -385,7 +401,7 @@ class FileNioMem extends FileBase {
} }
} }
return new FileLock(new FakeFileChannel(), position, size, shared) { return new FileLock(FakeFileChannel.INSTANCE, position, size, shared) {
@Override @Override
public boolean isValid() { public boolean isValid() {
...@@ -401,7 +417,7 @@ class FileNioMem extends FileBase { ...@@ -401,7 +417,7 @@ class FileNioMem extends FileBase {
@Override @Override
public String toString() { public String toString() {
return data.getName(); return data == null ? "<closed>" : data.getName();
} }
} }
......
...@@ -16,7 +16,6 @@ import java.util.ArrayList; ...@@ -16,7 +16,6 @@ import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
...@@ -354,7 +353,7 @@ class FileZip extends FileBase { ...@@ -354,7 +353,7 @@ class FileZip extends FileBase {
public synchronized FileLock tryLock(long position, long size, public synchronized FileLock tryLock(long position, long size,
boolean shared) throws IOException { boolean shared) throws IOException {
if (shared) { if (shared) {
return new FileLock(new FakeFileChannel(), position, size, shared) { return new FileLock(FakeFileChannel.INSTANCE, position, size, shared) {
@Override @Override
public boolean isValid() { public boolean isValid() {
......
...@@ -14,7 +14,6 @@ import java.io.Reader; ...@@ -14,7 +14,6 @@ import java.io.Reader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.engine.Mode; import org.h2.engine.Mode;
import org.h2.engine.SysProperties; import org.h2.engine.SysProperties;
...@@ -45,20 +44,38 @@ public class ValueLobDb extends Value { ...@@ -45,20 +44,38 @@ public class ValueLobDb extends Value {
* the value type (Value.BLOB or CLOB) * the value type (Value.BLOB or CLOB)
*/ */
private final int valueType; private final int valueType;
/**
* If the LOB is managed by the one the LobStorageBackend classes, these are the
* unique key inside that storage.
*/
private final int tableId;
private final long lobId; private final long lobId;
/**
* If this is a client-side ValueLobDb object returned by a ResultSet, the
* hmac acts a security cookie that the client can send back to the server
* to ask for data related to this LOB.
*/
private final byte[] hmac; private final byte[] hmac;
/**
* If the LOB is below the inline size, we just store/load it directly
* here.
*/
private final byte[] small; private final byte[] small;
private final DataHandler handler; private final DataHandler handler;
/** /**
* For a BLOB, precision is length in bytes. * For a BLOB, precision is length in bytes.
* For a CLOB, precision is length in chars. * For a CLOB, precision is length in chars.
*/ */
private final long precision; private final long precision;
/**
* If the LOB is a temporary LOB being managed by a temporary ResultSet,
* it is stored in a temporary file.
*/
private final String fileName; private final String fileName;
private final FileStore tempFile; private final FileStore tempFile;
private final int tableId; /**
* Cache the hashCode because it can be expensive to compute.
*/
private int hash; private int hash;
//Arbonaut: 13.07.2016 //Arbonaut: 13.07.2016
......
...@@ -15,7 +15,6 @@ import java.nio.channels.FileLock; ...@@ -15,7 +15,6 @@ import java.nio.channels.FileLock;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.store.fs.FakeFileChannel; import org.h2.store.fs.FakeFileChannel;
...@@ -427,7 +426,7 @@ class FileZip2 extends FileBase { ...@@ -427,7 +426,7 @@ class FileZip2 extends FileBase {
public synchronized FileLock tryLock(long position, long size, public synchronized FileLock tryLock(long position, long size,
boolean shared) throws IOException { boolean shared) throws IOException {
if (shared) { if (shared) {
return new FileLock(new FakeFileChannel(), position, size, shared) { return new FileLock(FakeFileChannel.INSTANCE, position, size, shared) {
@Override @Override
public boolean isValid() { public boolean isValid() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论