提交 0b219336 authored 作者: Thomas Mueller's avatar Thomas Mueller

Formatting, javadocs

上级 58bea228
...@@ -175,7 +175,7 @@ public class SysProperties { ...@@ -175,7 +175,7 @@ public class SysProperties {
* maximum delay. * maximum delay.
*/ */
public static final int DELAY_WRONG_PASSWORD_MAX = Utils.getProperty("h2.delayWrongPasswordMax", 4000); public static final int DELAY_WRONG_PASSWORD_MAX = Utils.getProperty("h2.delayWrongPasswordMax", 4000);
/** /**
* System property <code>h2.javaSystemCompiler</code> (default: true).<br /> * System property <code>h2.javaSystemCompiler</code> (default: true).<br />
* Whether to use the Java system compiler * Whether to use the Java system compiler
......
...@@ -2498,7 +2498,7 @@ public class Database implements DataHandler { ...@@ -2498,7 +2498,7 @@ public class Database implements DataHandler {
conn.setTraceLevel(TraceSystem.OFF); conn.setTraceLevel(TraceSystem.OFF);
return conn; return conn;
} }
public void setLogMode(int log) { public void setLogMode(int log) {
if (log < 0 || log > 2) { if (log < 0 || log > 2) {
throw DbException.getInvalidValueException("LOG", log); throw DbException.getInvalidValueException("LOG", log);
......
...@@ -122,7 +122,7 @@ public class DataUtils { ...@@ -122,7 +122,7 @@ public class DataUtils {
* The estimated number of bytes used per child entry. * The estimated number of bytes used per child entry.
*/ */
public static final int PAGE_MEMORY_CHILD = 16; public static final int PAGE_MEMORY_CHILD = 16;
/** /**
* Name of the character encoding format. * Name of the character encoding format.
*/ */
...@@ -137,7 +137,7 @@ public class DataUtils { ...@@ -137,7 +137,7 @@ public class DataUtils {
* The maximum byte to grow a buffer at a time. * The maximum byte to grow a buffer at a time.
*/ */
private static final int MAX_GROW = 16 * 1024 * 1024; private static final int MAX_GROW = 16 * 1024 * 1024;
/** /**
* Get the length of the variable size int. * Get the length of the variable size int.
* *
...@@ -805,7 +805,7 @@ public class DataUtils { ...@@ -805,7 +805,7 @@ public class DataUtils {
/** /**
* Parse a string as a number. * Parse a string as a number.
* *
* @param x the number * @param x the number
* @param defaultValue if x is null * @param defaultValue if x is null
* @return the parsed value * @return the parsed value
...@@ -818,14 +818,14 @@ public class DataUtils { ...@@ -818,14 +818,14 @@ public class DataUtils {
try { try {
return Long.parseLong(x); return Long.parseLong(x);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw newIllegalStateException(ERROR_FILE_CORRUPT, throw newIllegalStateException(ERROR_FILE_CORRUPT,
"Error parsing the value {0} as a long", x, e); "Error parsing the value {0} as a long", x, e);
} }
} }
/** /**
* Try to parse a string as a number. * Try to parse a string as a number.
* *
* @param x the number * @param x the number
* @param defaultValue if x is null * @param defaultValue if x is null
* @param errorValue if parsing fails * @param errorValue if parsing fails
......
...@@ -24,28 +24,64 @@ import org.h2.store.fs.FilePathNio; ...@@ -24,28 +24,64 @@ import org.h2.store.fs.FilePathNio;
*/ */
public class FileStore { public class FileStore {
/**
* The number of read operations.
*/
protected long readCount; protected long readCount;
/**
* The number of write operations.
*/
protected long writeCount; protected long writeCount;
/** /**
* The free spaces between the chunks. The first block to use is block 2 * The free spaces between the chunks. The first block to use is block 2
* (the first two blocks are the store header). * (the first two blocks are the store header).
*/ */
protected final FreeSpaceBitSet freeSpace = new FreeSpaceBitSet(2, MVStore.BLOCK_SIZE); protected final FreeSpaceBitSet freeSpace = new FreeSpaceBitSet(2, MVStore.BLOCK_SIZE);
/**
* The file name.
*/
protected String fileName; protected String fileName;
/**
* Whether this store is read-only.
*/
protected boolean readOnly; protected boolean readOnly;
/**
* The file size (cached).
*/
protected long fileSize; protected long fileSize;
/**
* The file.
*/
protected FileChannel file; protected FileChannel file;
protected FileLock fileLock;
/**
* The encrypted file (if encryption is used).
*/
protected FileChannel encryptedFile;
/**
* The file lock.
*/
protected FileLock fileLock;
@Override @Override
public String toString() { public String toString() {
return fileName; return fileName;
} }
/**
* Read from the file.
*
* @param pos the write position
* @param len the number of bytes to read
* @return the byte buffer
*/
public ByteBuffer readFully(long pos, int len) { public ByteBuffer readFully(long pos, int len) {
readCount++; readCount++;
ByteBuffer dst = ByteBuffer.allocate(len); ByteBuffer dst = ByteBuffer.allocate(len);
...@@ -53,12 +89,27 @@ public class FileStore { ...@@ -53,12 +89,27 @@ public class FileStore {
return dst; return dst;
} }
/**
* Write to the file.
*
* @param pos the write position
* @param src the source buffer
*/
public void writeFully(long pos, ByteBuffer src) { public void writeFully(long pos, ByteBuffer src) {
writeCount++; writeCount++;
fileSize = Math.max(fileSize, pos + src.remaining()); fileSize = Math.max(fileSize, pos + src.remaining());
DataUtils.writeFully(file, pos, src); DataUtils.writeFully(file, pos, src);
} }
/**
* Try to open the file.
*
* @param fileName the file name
* @param readOnly whether the file should only be opened in read-only mode,
* even if the file is writable
* @param encryptionKey the encryption key, or null if encryption is not
* used
*/
public void open(String fileName, boolean readOnly, char[] encryptionKey) { public void open(String fileName, boolean readOnly, char[] encryptionKey) {
if (fileName != null && fileName.indexOf(':') < 0) { if (fileName != null && fileName.indexOf(':') < 0) {
// NIO is used, unless a different file system is specified // NIO is used, unless a different file system is specified
...@@ -80,6 +131,7 @@ public class FileStore { ...@@ -80,6 +131,7 @@ public class FileStore {
file = f.open(readOnly ? "r" : "rw"); file = f.open(readOnly ? "r" : "rw");
if (encryptionKey != null) { if (encryptionKey != null) {
byte[] password = FilePathCrypt.getPasswordBytes(encryptionKey); byte[] password = FilePathCrypt.getPasswordBytes(encryptionKey);
encryptedFile = file;
file = new FilePathCrypt.FileCrypt(fileName, password, file); file = new FilePathCrypt.FileCrypt(fileName, password, file);
} }
file = FilePathCache.wrap(file); file = FilePathCache.wrap(file);
...@@ -104,7 +156,10 @@ public class FileStore { ...@@ -104,7 +156,10 @@ public class FileStore {
"Could not open file {0}", fileName, e); "Could not open file {0}", fileName, e);
} }
} }
/**
* Close this store.
*/
public void close() { public void close() {
try { try {
if (fileLock != null) { if (fileLock != null) {
...@@ -121,7 +176,10 @@ public class FileStore { ...@@ -121,7 +176,10 @@ public class FileStore {
file = null; file = null;
} }
} }
/**
* Flush all changes.
*/
public void sync() { public void sync() {
try { try {
file.force(true); file.force(true);
...@@ -131,11 +189,21 @@ public class FileStore { ...@@ -131,11 +189,21 @@ public class FileStore {
"Could not sync file {0}", fileName, e); "Could not sync file {0}", fileName, e);
} }
} }
/**
* Get the file size.
*
* @return the file size
*/
public long size() { public long size() {
return fileSize; return fileSize;
} }
/**
* Truncate the file.
*
* @param size the new file size
*/
public void truncate(long size) { public void truncate(long size) {
try { try {
writeCount++; writeCount++;
...@@ -150,29 +218,43 @@ public class FileStore { ...@@ -150,29 +218,43 @@ public class FileStore {
} }
/** /**
* Get the file instance in use. The application may read from the file (for * Get the file instance in use.
* example for online backup), but not write to it or truncate it. * <p>
* * The application may read from the file (for example for online backup),
* but not write to it or truncate it.
*
* @return the file * @return the file
*/ */
public FileChannel getFile() { public FileChannel getFile() {
return file; return file;
} }
/**
* Get the encrypted file instance, if encryption is used.
* <p>
* The application may read from the file (for example for online backup),
* but not write to it or truncate it.
*
* @return the encrypted file, or null if encryption is not used
*/
public FileChannel getEncryptedFile() {
return encryptedFile;
}
/** /**
* Get the number of write operations since this store was opened. * Get the number of write operations since this store was opened.
* For file based stores, this is the number of file write operations. * For file based stores, this is the number of file write operations.
* *
* @return the number of write operations * @return the number of write operations
*/ */
public long getWriteCount() { public long getWriteCount() {
return writeCount; return writeCount;
} }
/** /**
* Get the number of read operations since this store was opened. * Get the number of read operations since this store was opened.
* For file based stores, this is the number of file read operations. * For file based stores, this is the number of file read operations.
* *
* @return the number of read operations * @return the number of read operations
*/ */
public long getReadCount() { public long getReadCount() {
...@@ -183,14 +265,31 @@ public class FileStore { ...@@ -183,14 +265,31 @@ public class FileStore {
return readOnly; return readOnly;
} }
/**
* Get the default retention time for this store in milliseconds.
*
* @return the retention time
*/
public int getDefaultRetentionTime() { public int getDefaultRetentionTime() {
return 45000; return 45000;
} }
public void markUsed(long start, int len) { /**
freeSpace.markUsed(start, len); * Mark the space as in use.
*
* @param pos the position in bytes
* @param length the number of bytes
*/
public void markUsed(long pos, int length) {
freeSpace.markUsed(pos, length);
} }
/**
* Allocate a number of blocks and mark them as used.
*
* @param length the number of bytes to allocate
* @return the start position in bytes
*/
public long allocate(int length) { public long allocate(int length) {
return freeSpace.allocate(length); return freeSpace.allocate(length);
} }
...@@ -213,6 +312,9 @@ public class FileStore { ...@@ -213,6 +312,9 @@ public class FileStore {
return freeSpace.getFirstFree(); return freeSpace.getFirstFree();
} }
/**
* Mark the file as empty.
*/
public void clear() { public void clear() {
freeSpace.clear(); freeSpace.clear();
} }
......
...@@ -986,7 +986,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -986,7 +986,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
/** /**
* Get the number of entries, as a integer. Integer.MAX_VALUE is returned if * Get the number of entries, as a integer. Integer.MAX_VALUE is returned if
* there are more than this entries. * there are more than this entries.
* *
* @return the number of entries, as an integer * @return the number of entries, as an integer
*/ */
@Override @Override
...@@ -994,10 +994,10 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -994,10 +994,10 @@ public class MVMap<K, V> extends AbstractMap<K, V>
long size = sizeAsLong(); long size = sizeAsLong();
return size > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) size; return size > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) size;
} }
/** /**
* Get the number of entries, as a long. * Get the number of entries, as a long.
* *
* @return the number of entries * @return the number of entries
*/ */
public long sizeAsLong() { public long sizeAsLong() {
......
...@@ -48,7 +48,7 @@ TestMVStoreDataLoss ...@@ -48,7 +48,7 @@ TestMVStoreDataLoss
MVTableEngine: MVTableEngine:
- use StreamStore - use StreamStore
- when the MVStore was enabled before, use it again - when the MVStore was enabled before, use it again
(probably by checking existence of the mvstore file) (probably by checking existence of the mvstore file)
TransactionStore: TransactionStore:
...@@ -62,46 +62,32 @@ MVStore: ...@@ -62,46 +62,32 @@ MVStore:
- defragment (re-creating maps, specially those with small pages) - defragment (re-creating maps, specially those with small pages)
- chunk header: store changed chunk data as row; maybe after the root - chunk header: store changed chunk data as row; maybe after the root
- chunk checksum (header, last page, 2 bytes per page?) - chunk checksum (header, last page, 2 bytes per page?)
- on insert, if the child page is already full, don't load and modify it
split directly (specially for leaves with one large entry)
- maybe let a chunk point to a list of potential next chunks - maybe let a chunk point to a list of potential next chunks
(so no fixed location header is needed), similar to a skip list (so no fixed location header is needed), similar to a skip list
- triggers (can be implemented with a custom map);
maybe implement database indexing with triggers
- store number of write operations per page (maybe defragment - store number of write operations per page (maybe defragment
if much different than count) if much different than count)
- r-tree: nearest neighbor search - r-tree: nearest neighbor search
- support maps without values (just existence of the key)
- support maps without keys (counted b-tree features)
- use a small object value cache (StringCache), test on Android - use a small object value cache (StringCache), test on Android
for default serialization for default serialization
- MVStoreTool.dump: dump values (using a callback) - MVStoreTool.dump: dump values (using a callback)
- map split / merge (fast if no overlap) - ensure data is overwritten eventually if the system doesn't have a
(use case: partitioning) real-time clock (Raspberry Pi) and if there are few writes per startup
- StreamStore optimization: avoid copying bytes in memory
- Feature shrink a store (create, copy, rename, delete)
and for MVStore on Windows, auto-detect renamed file
- ensure data is overwritten eventually if the system doesn't have a
real-time clock (Raspberry Pi) and if there are few writes per startup
- SSD-friendly write (always in blocks of 4 MB / 1 second?) - SSD-friendly write (always in blocks of 4 MB / 1 second?)
- close the file on out of memory or disk write error (out of disk space or so) - close the file on out of memory or disk write error (out of disk space or so)
- implement a sharded map (in one store, multiple stores) - implement a sharded map (in one store, multiple stores)
to support concurrent updates and writes, and very large maps to support concurrent updates and writes, and very large maps
- maybe support for writing to branches
- maybe add an optional finalizer and exit hook
to store committed changes
- to save space when persisting very small transactions, - to save space when persisting very small transactions,
use a transaction log where only the deltas are stored use a transaction log where only the deltas are stored
- serialization for lists, sets, sets, sorted sets, maps, sorted maps - serialization for lists, sets, sets, sorted sets, maps, sorted maps
- maybe rename 'rollback' to 'revert' to distinguish from transactions - maybe rename 'rollback' to 'revert' to distinguish from transactions
- support other compression algorithms (deflate, LZ4,...) - support other compression algorithms (deflate, LZ4,...)
- only retain the last version, unless explicitly set (setRetainVersion)
- support opening (existing) maps by id - support opening (existing) maps by id
- more consistent null handling (keys/values sometimes may be null) - more consistent null handling (keys/values sometimes may be null)
- autocommit (to avoid having to call commit, - autocommit (to avoid having to call commit,
as it could be called too often or it is easily forgotten) as it could be called too often or it is easily forgotten)
- remove features that are not really needed; simplify the code - remove features that are not really needed; simplify the code
possibly using a separate layer or tools possibly using a separate layer or tools
(retainVersion?)
- rename "store" to "save", as "store" is used in "storeVersion" - rename "store" to "save", as "store" is used in "storeVersion"
- MVStoreTool.dump should dump the data if possible; - MVStoreTool.dump should dump the data if possible;
possibly using a callback for serialization possibly using a callback for serialization
...@@ -114,8 +100,8 @@ MVStore: ...@@ -114,8 +100,8 @@ MVStore:
- simple rollback method (rollback to last committed version) - simple rollback method (rollback to last committed version)
- MVMap to implement SortedMap, then NavigableMap - MVMap to implement SortedMap, then NavigableMap
- Test with OSGi - Test with OSGi
- storage that splits database into multiple files, - storage that splits database into multiple files,
to speed up compact and allow using trim to speed up compact and allow using trim
(by truncating / deleting empty files) (by truncating / deleting empty files)
*/ */
...@@ -138,20 +124,20 @@ public class MVStore { ...@@ -138,20 +124,20 @@ public class MVStore {
private static final int FORMAT_WRITE = 1; private static final int FORMAT_WRITE = 1;
private static final int FORMAT_READ = 1; private static final int FORMAT_READ = 1;
/** /**
* The background thread, if any. * The background thread, if any.
*/ */
volatile Thread backgroundThread; volatile Thread backgroundThread;
private volatile boolean reuseSpace = true; private volatile boolean reuseSpace = true;
private boolean closed; private boolean closed;
private FileStore fileStore; private FileStore fileStore;
private final int pageSplitSize; private final int pageSplitSize;
private long rootChunkStart; private long rootChunkStart;
/** /**
...@@ -189,7 +175,7 @@ public class MVStore { ...@@ -189,7 +175,7 @@ public class MVStore {
private ByteBuffer writeBuffer; private ByteBuffer writeBuffer;
private int lastMapId; private int lastMapId;
private long retainVersion = -1; private long retainVersion = -1;
/** /**
...@@ -197,7 +183,7 @@ public class MVStore { ...@@ -197,7 +183,7 @@ public class MVStore {
* (old) compressed pages. * (old) compressed pages.
*/ */
private final boolean compress; private final boolean compress;
private final Compressor compressor = new CompressLZF(); private final Compressor compressor = new CompressLZF();
private final UncaughtExceptionHandler backgroundExceptionHandler; private final UncaughtExceptionHandler backgroundExceptionHandler;
...@@ -208,7 +194,7 @@ public class MVStore { ...@@ -208,7 +194,7 @@ public class MVStore {
* The version of the last stored chunk. * The version of the last stored chunk.
*/ */
private long lastStoredVersion; private long lastStoredVersion;
private int unsavedPageCount; private int unsavedPageCount;
private int unsavedPageCountMax; private int unsavedPageCountMax;
...@@ -245,6 +231,7 @@ public class MVStore { ...@@ -245,6 +231,7 @@ public class MVStore {
/** /**
* Create and open the store. * Create and open the store.
* *
* @param config the configuration to use
* @throws IllegalStateException if the file is corrupt, or an exception * @throws IllegalStateException if the file is corrupt, or an exception
* occurred while opening * occurred while opening
* @throws IllegalArgumentException if the directory does not exist * @throws IllegalArgumentException if the directory does not exist
...@@ -302,7 +289,7 @@ public class MVStore { ...@@ -302,7 +289,7 @@ public class MVStore {
if (format > FORMAT_WRITE && !fileStore.isReadOnly()) { if (format > FORMAT_WRITE && !fileStore.isReadOnly()) {
throw DataUtils.newIllegalStateException( throw DataUtils.newIllegalStateException(
DataUtils.ERROR_UNSUPPORTED_FORMAT, DataUtils.ERROR_UNSUPPORTED_FORMAT,
"The write format {0} is larger than the supported format {1}, " + "The write format {0} is larger than the supported format {1}, " +
"and the file was not opened in read-only mode", "and the file was not opened in read-only mode",
format, FORMAT_WRITE); format, FORMAT_WRITE);
} }
...@@ -316,7 +303,7 @@ public class MVStore { ...@@ -316,7 +303,7 @@ public class MVStore {
if (rootChunkStart > 0) { if (rootChunkStart > 0) {
readMeta(); readMeta();
} }
} }
long rollback = DataUtils.parseLong(meta.get("rollbackOnOpen"), -1); long rollback = DataUtils.parseLong(meta.get("rollbackOnOpen"), -1);
if (rollback != -1) { if (rollback != -1) {
rollbackTo(rollback); rollbackTo(rollback);
...@@ -682,12 +669,14 @@ public class MVStore { ...@@ -682,12 +669,14 @@ public class MVStore {
if (shrinkIfPossible) { if (shrinkIfPossible) {
shrinkFileIfPossible(0); shrinkFileIfPossible(0);
} }
// release memory early - this is important when called
// because of out of memory
cache.clear();
for (MVMap<?, ?> m : New.arrayList(maps.values())) { for (MVMap<?, ?> m : New.arrayList(maps.values())) {
m.close(); m.close();
} }
meta = null; meta = null;
chunks.clear(); chunks.clear();
cache.clear();
maps.clear(); maps.clear();
try { try {
fileStore.close(); fileStore.close();
...@@ -1074,7 +1063,7 @@ public class MVStore { ...@@ -1074,7 +1063,7 @@ public class MVStore {
/** /**
* Get the position of the last used byte. * Get the position of the last used byte.
* *
* @return the position * @return the position
*/ */
private long getEndPosition() { private long getEndPosition() {
...@@ -1498,7 +1487,7 @@ public class MVStore { ...@@ -1498,7 +1487,7 @@ public class MVStore {
* depending on the operating system and hardware. * depending on the operating system and hardware.
* <p> * <p>
* This setting is not persisted. * This setting is not persisted.
* *
* @param ms how many milliseconds to retain old chunks (0 to overwrite them * @param ms how many milliseconds to retain old chunks (0 to overwrite them
* as early as possible) * as early as possible)
*/ */
...@@ -1518,7 +1507,7 @@ public class MVStore { ...@@ -1518,7 +1507,7 @@ public class MVStore {
/** /**
* Get the oldest version to retain in memory. * Get the oldest version to retain in memory.
* *
* @return the version * @return the version
*/ */
public long getRetainVersion() { public long getRetainVersion() {
...@@ -1533,7 +1522,7 @@ public class MVStore { ...@@ -1533,7 +1522,7 @@ public class MVStore {
/** /**
* Get the oldest version to retain in memory, which is the manually set * Get the oldest version to retain in memory, which is the manually set
* retain version, or the current store version (whatever is older). * retain version, or the current store version (whatever is older).
* *
* @return the version * @return the version
*/ */
long getRetainOrStoreVersion() { long getRetainOrStoreVersion() {
...@@ -1791,7 +1780,7 @@ public class MVStore { ...@@ -1791,7 +1780,7 @@ public class MVStore {
/** /**
* Get the file store. * Get the file store.
* *
* @return the file store * @return the file store
*/ */
public FileStore getFileStore() { public FileStore getFileStore() {
...@@ -1884,9 +1873,9 @@ public class MVStore { ...@@ -1884,9 +1873,9 @@ public class MVStore {
* *
* @param mb the cache size in MB. * @param mb the cache size in MB.
*/ */
public void setCacheSize(long mb) { public void setCacheSize(int mb) {
if (cache != null) { if (cache != null) {
cache.setMaxMemory(mb * 1024 * 1024); cache.setMaxMemory((long) mb * 1024 * 1024);
} }
} }
...@@ -2099,10 +2088,10 @@ public class MVStore { ...@@ -2099,10 +2088,10 @@ public class MVStore {
Thread.UncaughtExceptionHandler exceptionHandler) { Thread.UncaughtExceptionHandler exceptionHandler) {
return set("backgroundExceptionHandler", exceptionHandler); return set("backgroundExceptionHandler", exceptionHandler);
} }
/** /**
* Use the provided file store instead of the default one. * Use the provided file store instead of the default one.
* *
* @param store the file store * @param store the file store
* @return this * @return this
*/ */
......
...@@ -16,24 +16,24 @@ import java.util.TreeMap; ...@@ -16,24 +16,24 @@ import java.util.TreeMap;
* memory. * memory.
*/ */
public class OffHeapStore extends FileStore { public class OffHeapStore extends FileStore {
private final TreeMap<Long, ByteBuffer> memory = new TreeMap<Long, ByteBuffer>(); private final TreeMap<Long, ByteBuffer> memory = new TreeMap<Long, ByteBuffer>();
@Override @Override
public void open(String fileName, boolean readOnly, char[] encryptionKey) { public void open(String fileName, boolean readOnly, char[] encryptionKey) {
// nothing to do // nothing to do
} }
@Override @Override
public String toString() { public String toString() {
return memory.toString(); return memory.toString();
} }
@Override @Override
public ByteBuffer readFully(long pos, int len) { public ByteBuffer readFully(long pos, int len) {
Entry<Long, ByteBuffer> memEntry = memory.floorEntry(pos); Entry<Long, ByteBuffer> memEntry = memory.floorEntry(pos);
if (memEntry == null) { if (memEntry == null) {
throw DataUtils.newIllegalStateException(DataUtils.ERROR_READING_FAILED, throw DataUtils.newIllegalStateException(DataUtils.ERROR_READING_FAILED,
"Could not read from position {0}", pos); "Could not read from position {0}", pos);
} }
readCount++; readCount++;
...@@ -44,20 +44,20 @@ public class OffHeapStore extends FileStore { ...@@ -44,20 +44,20 @@ public class OffHeapStore extends FileStore {
read.limit(len + offset); read.limit(len + offset);
return read.slice(); return read.slice();
} }
@Override @Override
public void free(long pos, int length) { public void free(long pos, int length) {
freeSpace.free(pos, length); freeSpace.free(pos, length);
ByteBuffer buff = memory.remove(pos); ByteBuffer buff = memory.remove(pos);
if (buff == null) { if (buff == null) {
throw DataUtils.newIllegalStateException(DataUtils.ERROR_READING_FAILED, throw DataUtils.newIllegalStateException(DataUtils.ERROR_READING_FAILED,
"Could not find entry at position {0}", pos); "Could not find entry at position {0}", pos);
} else if (buff.remaining() != length) { } else if (buff.remaining() != length) {
throw DataUtils.newIllegalStateException(DataUtils.ERROR_READING_FAILED, throw DataUtils.newIllegalStateException(DataUtils.ERROR_READING_FAILED,
"Partial remove is not supported at position {0}", pos); "Partial remove is not supported at position {0}", pos);
} }
} }
@Override @Override
public void writeFully(long pos, ByteBuffer src) { public void writeFully(long pos, ByteBuffer src) {
fileSize = Math.max(fileSize, pos + src.remaining()); fileSize = Math.max(fileSize, pos + src.remaining());
...@@ -73,7 +73,7 @@ public class OffHeapStore extends FileStore { ...@@ -73,7 +73,7 @@ public class OffHeapStore extends FileStore {
int length = src.remaining(); int length = src.remaining();
if (prevPos == pos) { if (prevPos == pos) {
if (prevLength != length) { if (prevLength != length) {
throw DataUtils.newIllegalStateException(DataUtils.ERROR_READING_FAILED, throw DataUtils.newIllegalStateException(DataUtils.ERROR_READING_FAILED,
"Could not write to position {0}; partial overwrite is not supported", pos); "Could not write to position {0}; partial overwrite is not supported", pos);
} }
writeCount++; writeCount++;
...@@ -82,12 +82,12 @@ public class OffHeapStore extends FileStore { ...@@ -82,12 +82,12 @@ public class OffHeapStore extends FileStore {
return; return;
} }
if (prevPos + prevLength > pos) { if (prevPos + prevLength > pos) {
throw DataUtils.newIllegalStateException(DataUtils.ERROR_READING_FAILED, throw DataUtils.newIllegalStateException(DataUtils.ERROR_READING_FAILED,
"Could not write to position {0}; partial overwrite is not supported", pos); "Could not write to position {0}; partial overwrite is not supported", pos);
} }
writeNewEntry(pos, src); writeNewEntry(pos, src);
} }
private void writeNewEntry(long pos, ByteBuffer src) { private void writeNewEntry(long pos, ByteBuffer src) {
writeCount++; writeCount++;
int length = src.remaining(); int length = src.remaining();
...@@ -112,27 +112,27 @@ public class OffHeapStore extends FileStore { ...@@ -112,27 +112,27 @@ public class OffHeapStore extends FileStore {
} }
ByteBuffer buff = memory.get(pos); ByteBuffer buff = memory.get(pos);
if (buff.capacity() > size) { if (buff.capacity() > size) {
throw DataUtils.newIllegalStateException(DataUtils.ERROR_READING_FAILED, throw DataUtils.newIllegalStateException(DataUtils.ERROR_READING_FAILED,
"Could not truncate to {0}; partial truncate is not supported", pos); "Could not truncate to {0}; partial truncate is not supported", pos);
} }
it.remove(); it.remove();
} }
} }
@Override @Override
public void close() { public void close() {
truncate(0); truncate(0);
freeSpace.clear(); freeSpace.clear();
} }
@Override @Override
public void sync() { public void sync() {
// nothing to do // nothing to do
} }
@Override @Override
public int getDefaultRetentionTime() { public int getDefaultRetentionTime() {
return 0; return 0;
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论