public R createNode(Nd nd, long address, short nodeType) throws IndexException { ITypeFactory<? extends R> typeFactory = this.types.get(nodeType); if (typeFactory == null) { throw new IndexException("Index corruption detected. Unknown node type: " + nodeType + " at address " //$NON-NLS-1$//$NON-NLS-2$ + address); } return typeFactory.create(nd, address); }
public R createNode(Nd nd, long address, short nodeType) throws IndexException { ITypeFactory<? extends R> typeFactory = this.types.get(nodeType); if (typeFactory == null) { throw new IndexException("Index corruption detected. Unknown node type: " + nodeType + " at address " //$NON-NLS-1$//$NON-NLS-2$ + address); } return typeFactory.create(nd, address); }
private void databaseCorruptionDetected() throws IndexException { String msg = "Corrupted database: " + this.fLocation.getName(); //$NON-NLS-1$ throw new IndexException(new DBStatus(msg)); }
@SuppressWarnings("unchecked") public final int getSize(Nd nd, Object toMeasure) { byte key = getKeyFor(toMeasure); @SuppressWarnings("rawtypes") TagHandler handler = this.readers[key]; if (handler == null) { throw new IndexException("Attempted to get size of object " + toMeasure.toString() + " with unknown key " //$NON-NLS-1$//$NON-NLS-2$ + key); } return handler.getSize(nd, toMeasure, this); } }
@SuppressWarnings("unchecked") public final int getSize(Nd nd, Object toMeasure) { byte key = getKeyFor(toMeasure); @SuppressWarnings("rawtypes") TagHandler handler = this.readers[key]; if (handler == null) { throw new IndexException("Attempted to get size of object " + toMeasure.toString() + " with unknown key " //$NON-NLS-1$//$NON-NLS-2$ + key); } return handler.getSize(nd, toMeasure, this); } }
private void databaseCorruptionDetected() throws IndexException { String msg = "Corrupted database: " + this.fLocation.getName(); //$NON-NLS-1$ throw new IndexException(new DBStatus(msg)); }
private boolean markFileIncomplete() throws IndexException { boolean wasInterrupted = false; if (!this.fIsMarkedIncomplete) { this.fIsMarkedIncomplete= true; try { final ByteBuffer buf= ByteBuffer.wrap(new byte[4]); wasInterrupted = performUninterruptableWrite(() -> this.fFile.getChannel().write(buf, 0)); this.bytesWritten += 4; } catch (IOException e) { throw new IndexException(new DBStatus(e)); } } return wasInterrupted; }
private boolean markFileIncomplete() throws IndexException { boolean wasInterrupted = false; if (!this.fIsMarkedIncomplete) { this.fIsMarkedIncomplete= true; try { final ByteBuffer buf= ByteBuffer.wrap(new byte[4]); wasInterrupted = performUninterruptableWrite(() -> this.fFile.getChannel().write(buf, 0)); this.bytesWritten += 4; } catch (IOException e) { throw new IndexException(new DBStatus(e)); } } return wasInterrupted; }
void read() throws IndexException { try { final ByteBuffer buf= ByteBuffer.wrap(this.fBuffer); this.fDatabase.read(buf, (long) this.fSequenceNumber * Database.CHUNK_SIZE); } catch (IOException e) { throw new IndexException(new DBStatus(e)); } }
void read() throws IndexException { try { final ByteBuffer buf= ByteBuffer.wrap(this.fBuffer); this.fDatabase.read(buf, (long) this.fSequenceNumber * Database.CHUNK_SIZE); } catch (IOException e) { throw new IndexException(new DBStatus(e)); } }
void clear(final long offset, final int length) { makeDirty(); int idx = recPtrToIndex(offset); final int end = idx + length; if (end > this.fBuffer.length) { throw new IndexException("Attempting to clear beyond end of chunk. Chunk = " + this.fSequenceNumber //$NON-NLS-1$ + ", offset = " + offset + ", length = " + length); //$NON-NLS-1$//$NON-NLS-2$ } for (; idx < end; idx++) { this.fBuffer[idx] = 0; } recordWrite(offset, length); }
public void recordFree(short poolId, long size) { PoolStats toRecord = getPoolStats(poolId); if (toRecord.numAllocations <= 0 || toRecord.totalSize < size) { throw new IndexException("Attempted to free more memory from pool " + poolId + " than was ever allocated"); //$NON-NLS-1$//$NON-NLS-2$ } toRecord.setAllocations(this.db, toRecord.numAllocations - 1); toRecord.setTotalSize(this.db, toRecord.totalSize - size); } }
/** * Uninterruptable. Returns true iff an attempt was made to interrupt the flush with * {@link Thread#interrupt()}. */ boolean flush() throws IndexException { if (Database.DEBUG_PAGE_CACHE) { System.out.println( "CHUNK " + this.fSequenceNumber + ": flushing - instance " + System.identityHashCode(this)); //$NON-NLS-1$//$NON-NLS-2$ } boolean wasCanceled = false; try { final ByteBuffer buf= ByteBuffer.wrap(this.fBuffer); wasCanceled = this.fDatabase.write(buf, (long) this.fSequenceNumber * Database.CHUNK_SIZE); } catch (IOException e) { throw new IndexException(new DBStatus(e)); } this.fDirty = false; this.fDatabase.chunkCleaned(this); return wasCanceled; }
public void recordFree(short poolId, long size) { PoolStats toRecord = getPoolStats(poolId); if (toRecord.numAllocations <= 0 || toRecord.totalSize < size) { throw new IndexException("Attempted to free more memory from pool " + poolId + " than was ever allocated"); //$NON-NLS-1$//$NON-NLS-2$ } toRecord.setAllocations(this.db, toRecord.numAllocations - 1); toRecord.setTotalSize(this.db, toRecord.totalSize - size); } }
/** * Uninterruptable. Returns true iff an attempt was made to interrupt the flush with * {@link Thread#interrupt()}. */ boolean flush() throws IndexException { if (Database.DEBUG_PAGE_CACHE) { System.out.println( "CHUNK " + this.fSequenceNumber + ": flushing - instance " + System.identityHashCode(this)); //$NON-NLS-1$//$NON-NLS-2$ } boolean wasCanceled = false; try { final ByteBuffer buf= ByteBuffer.wrap(this.fBuffer); wasCanceled = this.fDatabase.write(buf, (long) this.fSequenceNumber * Database.CHUNK_SIZE); } catch (IOException e) { throw new IndexException(new DBStatus(e)); } this.fDirty = false; this.fDatabase.chunkCleaned(this); return wasCanceled; }
void clear(final long offset, final int length) { makeDirty(); int idx = recPtrToIndex(offset); final int end = idx + length; if (end > this.fBuffer.length) { throw new IndexException("Attempting to clear beyond end of chunk. Chunk = " + this.fSequenceNumber //$NON-NLS-1$ + ", offset = " + offset + ", length = " + length); //$NON-NLS-1$//$NON-NLS-2$ } for (; idx < end; idx++) { this.fBuffer[idx] = 0; } recordWrite(offset, length); }
/** * Closes the database. * <p> * The behavior of any further calls to the Database is undefined * @throws IndexException */ public void close() throws IndexException { assert this.fExclusiveLock; flush(); removeChunksFromCache(); this.log.clear(); // Chunks have been removed from the cache, so we are fine. this.fHeaderChunk.clear(0, CHUNK_SIZE); this.memoryUsage.refresh(); this.fHeaderChunk.fDirty= false; this.dirtyChunkSet.clear(); this.fChunks= new Chunk[] { null }; this.fChunksUsed = this.fChunks.length; try { this.fFile.close(); } catch (IOException e) { throw new IndexException(new DBStatus(e)); } }
/** * Closes the database. * <p> * The behavior of any further calls to the Database is undefined * @throws IndexException */ public void close() throws IndexException { assert this.fExclusiveLock; flush(); removeChunksFromCache(); this.log.clear(); // Chunks have been removed from the cache, so we are fine. this.fHeaderChunk.clear(0, CHUNK_SIZE); this.memoryUsage.refresh(); this.fHeaderChunk.fDirty= false; this.dirtyChunkSet.clear(); this.fChunks= new Chunk[] { null }; this.fChunksUsed = this.fChunks.length; try { this.fFile.close(); } catch (IOException e) { throw new IndexException(new DBStatus(e)); } }
/** * Returns a newly constructed {@link IndexException} containing the given message and all the addresses collected * by this object. */ public IndexException build(String description) { IndexException toThrow = new IndexException(description); if (this.db.getLog().enabled()) { toThrow.setTime(this.db.getLog().getWriteCount()); } attachTo(toThrow); return toThrow; }
/** * Returns a newly constructed {@link IndexException} containing the given message and all the addresses collected * by this object. */ public IndexException build(String description) { IndexException toThrow = new IndexException(description); if (this.db.getLog().enabled()) { toThrow.setTime(this.db.getLog().getWriteCount()); } attachTo(toThrow); return toThrow; }