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