You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2010/01/24 13:33:28 UTC
svn commit: r902552 - in
/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman: BlockIo.java
BlockView.java RecordFile.java RecordHeader.java
Author: akarasulu
Date: Sun Jan 24 12:33:27 2010
New Revision: 902552
URL: http://svn.apache.org/viewvc?rev=902552&view=rev
Log:
changes ...
o formating
o cleaned up bad code constructs like if statements without brackets
o spelling
o started using autoboxing of primitive types to get rid of useless clutter
o added generics to remove casts in some of the data structures used in
the RecordFile like inUse, free, inTxn, the dirty hashes
o more later ...
Modified:
directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockIo.java
directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockView.java
directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/RecordFile.java
directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/RecordHeader.java
Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockIo.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockIo.java?rev=902552&r1=902551&r2=902552&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockIo.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockIo.java Sun Jan 24 12:33:27 2010
@@ -44,14 +44,13 @@
*
* $Id: BlockIo.java,v 1.2 2002/08/06 05:18:36 boisvert Exp $
*/
-
package jdbm.recman;
+
import java.io.*;
import org.apache.directory.server.i18n.I18n;
-import org.apache.directory.server.i18n.I18n;
/**
* This class wraps a page-sized byte array and provides methods
@@ -62,8 +61,8 @@
* @see java.io.DataInput
* @see java.io.DataOutput
*/
-public final class BlockIo implements java.io.Externalizable {
-
+public final class BlockIo implements java.io.Externalizable
+{
public final static long serialVersionUID = 2L;
private long blockId;
@@ -73,171 +72,220 @@
private transient boolean dirty = false;
private transient int transactionCount = 0;
+
/**
* Default constructor for serialization
*/
- public BlockIo() {
+ public BlockIo()
+ {
// empty
}
+
/**
- * Constructs a new BlockIo instance working on the indicated
- * buffer.
+ * Constructs a new BlockIo instance working on the indicated buffer.
*/
- BlockIo(long blockId, byte[] data) {
- // removeme for production version
- if (blockId > 10000000000L)
+ BlockIo( long blockId, byte[] data )
+ {
+ // remove me for production version
+ if ( blockId > 10000000000L )
+ {
throw new Error( I18n.err( I18n.ERR_539, blockId ) );
+ }
+
this.blockId = blockId;
this.data = data;
}
+
/**
* Returns the underlying array
*/
- byte[] getData() {
+ byte[] getData()
+ {
return data;
}
+
/**
* Sets the block number. Should only be called by RecordFile.
*/
- void setBlockId(long id) {
- if (isInTransaction())
+ void setBlockId( long id )
+ {
+ if ( isInTransaction() )
+ {
throw new Error( I18n.err( I18n.ERR_540 ) );
- // removeme for production version
+ }
+
+ // remove me for production version
if (id > 10000000000L)
+ {
throw new Error( I18n.err( I18n.ERR_539, id ) );
+ }
+
blockId = id;
}
+
/**
* Returns the block number.
*/
- long getBlockId() {
+ long getBlockId()
+ {
return blockId;
}
+
/**
* Returns the current view of the block.
*/
- public BlockView getView() {
+ public BlockView getView()
+ {
return view;
}
+
/**
* Sets the current view of the block.
*/
- public void setView(BlockView view) {
+ public void setView( BlockView view )
+ {
this.view = view;
}
+
/**
* Sets the dirty flag
*/
- void setDirty() {
+ void setDirty()
+ {
dirty = true;
}
+
/**
* Clears the dirty flag
*/
- void setClean() {
+ void setClean()
+ {
dirty = false;
}
+
/**
* Returns true if the dirty flag is set.
*/
- boolean isDirty() {
+ boolean isDirty()
+ {
return dirty;
}
+
/**
- * Returns true if the block is still dirty with respect to the
+ * Returns true if the block is still dirty with respect to the
* transaction log.
*/
- boolean isInTransaction() {
+ boolean isInTransaction()
+ {
return transactionCount != 0;
}
+
/**
* Increments transaction count for this block, to signal that this
* block is in the log but not yet in the data file. The method also
* takes a snapshot so that the data may be modified in new transactions.
*/
- synchronized void incrementTransactionCount() {
+ synchronized void incrementTransactionCount()
+ {
transactionCount++;
- // @fixme(alex)
+
+ // @fix me ( alex )
setClean();
}
+
/**
* Decrements transaction count for this block, to signal that this
* block has been written from the log to the data file.
*/
- synchronized void decrementTransactionCount() {
+ synchronized void decrementTransactionCount()
+ {
transactionCount--;
- if (transactionCount < 0)
+ if ( transactionCount < 0 )
+ {
throw new Error( I18n.err( I18n.ERR_541, getBlockId() ) );
-
+ }
}
+
/**
* Reads a byte from the indicated position
*/
- public byte readByte(int pos) {
+ public byte readByte( int pos )
+ {
return data[pos];
}
+
/**
* Writes a byte to the indicated position
*/
- public void writeByte(int pos, byte value) {
+ public void writeByte( int pos, byte value )
+ {
data[pos] = value;
setDirty();
}
+
/**
* Reads a short from the indicated position
*/
- public short readShort(int pos) {
- return (short)
- (((short) (data[pos+0] & 0xff) << 8) |
- ((short) (data[pos+1] & 0xff) << 0));
+ public short readShort( int pos )
+ {
+ return ( short )
+ ( ( ( short ) ( data[pos+0] & 0xff ) << 8 ) |
+ ( ( short ) ( data[pos+1] & 0xff ) << 0 ) );
}
+
/**
* Writes a short to the indicated position
*/
- public void writeShort(int pos, short value) {
- data[pos+0] = (byte)(0xff & (value >> 8));
- data[pos+1] = (byte)(0xff & (value >> 0));
+ public void writeShort( int pos, short value )
+ {
+ data[pos+0] = ( byte ) ( 0xff & ( value >> 8 ) );
+ data[pos+1] = ( byte ) ( 0xff & ( value >> 0 ) );
setDirty();
}
+
/**
* Reads an int from the indicated position
*/
- public int readInt(int pos) {
+ public int readInt( int pos )
+ {
return
- (((int)(data[pos+0] & 0xff) << 24) |
- ((int)(data[pos+1] & 0xff) << 16) |
- ((int)(data[pos+2] & 0xff) << 8) |
- ((int)(data[pos+3] & 0xff) << 0));
+ ( ( ( int ) ( data[pos+0] & 0xff ) << 24) |
+ ( ( int ) ( data[pos+1] & 0xff ) << 16) |
+ ( ( int ) ( data[pos+2] & 0xff ) << 8) |
+ ( ( int ) ( data[pos+3] & 0xff ) << 0 ) );
}
+
/**
* Writes an int to the indicated position
*/
- public void writeInt(int pos, int value) {
- data[pos+0] = (byte)(0xff & (value >> 24));
- data[pos+1] = (byte)(0xff & (value >> 16));
- data[pos+2] = (byte)(0xff & (value >> 8));
- data[pos+3] = (byte)(0xff & (value >> 0));
+ public void writeInt( int pos, int value )
+ {
+ data[pos+0] = ( byte ) ( 0xff & ( value >> 24 ) );
+ data[pos+1] = ( byte ) ( 0xff & ( value >> 16 ) );
+ data[pos+2] = ( byte ) ( 0xff & ( value >> 8 ) );
+ data[pos+3] = ( byte ) ( 0xff & ( value >> 0 ) );
setDirty();
}
+
/**
* Reads a long from the indicated position
*/
@@ -246,27 +294,28 @@
// Contributed by Erwin Bolwidt <ej...@klomp.org>
// Gives about 15% performance improvement
return
- ( (long)( ((data[pos+0] & 0xff) << 24) |
- ((data[pos+1] & 0xff) << 16) |
- ((data[pos+2] & 0xff) << 8) |
- ((data[pos+3] & 0xff) ) ) << 32 ) |
- ( (long)( ((data[pos+4] & 0xff) << 24) |
- ((data[pos+5] & 0xff) << 16) |
- ((data[pos+6] & 0xff) << 8) |
- ((data[pos+7] & 0xff) ) ) & 0xffffffff );
+ ( ( long )( ( ( data[pos+0] & 0xff ) << 24 ) |
+ ( ( data[pos+1] & 0xff ) << 16 ) |
+ ( ( data[pos+2] & 0xff ) << 8 ) |
+ ( ( data[pos+3] & 0xff ) ) ) << 32 ) |
+ ( ( long )( ( ( data[pos+4] & 0xff ) << 24 ) |
+ ( ( data[pos+5] & 0xff ) << 16 ) |
+ ( ( data[pos+6] & 0xff ) << 8 ) |
+ ( ( data[pos+7] & 0xff ) ) ) & 0xffffffff );
/* Original version by Alex Boisvert. Might be faster on 64-bit JVMs.
return
- (((long)(data[pos+0] & 0xff) << 56) |
- ((long)(data[pos+1] & 0xff) << 48) |
- ((long)(data[pos+2] & 0xff) << 40) |
- ((long)(data[pos+3] & 0xff) << 32) |
- ((long)(data[pos+4] & 0xff) << 24) |
- ((long)(data[pos+5] & 0xff) << 16) |
- ((long)(data[pos+6] & 0xff) << 8) |
- ((long)(data[pos+7] & 0xff) << 0));
+ ( ( ( long ) ( data[pos+0] & 0xff ) << 56 ) |
+ ( ( long ) ( data[pos+1] & 0xff ) << 48 ) |
+ ( ( long ) ( data[pos+2] & 0xff ) << 40 ) |
+ ( ( long ) ( data[pos+3] & 0xff ) << 32 ) |
+ ( ( long ) ( data[pos+4] & 0xff ) << 24 ) |
+ ( ( long ) ( data[pos+5] & 0xff ) << 16 ) |
+ ( ( long ) ( data[pos+6] & 0xff ) << 8 ) |
+ ( ( long ) ( data[pos+7] & 0xff ) << 0 ) );
*/
}
+
/**
* Writes a long to the indicated position
*/
@@ -282,29 +331,35 @@
setDirty();
}
+
// overrides java.lang.Object
-
- public String toString() {
- return "BlockIO("
- + blockId + ","
- + dirty + ","
- + view + ")";
+
+ public String toString()
+ {
+ return "BlockIO ( "
+ + blockId + ", "
+ + dirty + ", "
+ + view + " )";
}
+
// implement externalizable interface
- public void readExternal(ObjectInput in)
- throws IOException, ClassNotFoundException {
+
+ public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
+ {
blockId = in.readLong();
int length = in.readInt();
data = new byte[length];
in.readFully(data);
}
+
// implement externalizable interface
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeLong(blockId);
- out.writeInt(data.length);
- out.write(data);
- }
+ public void writeExternal( ObjectOutput out ) throws IOException
+ {
+ out.writeLong( blockId );
+ out.writeInt( data.length );
+ out.write( data );
+ }
}
Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockView.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockView.java?rev=902552&r1=902551&r2=902552&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockView.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockView.java Sun Jan 24 12:33:27 2010
@@ -44,14 +44,15 @@
*
* $Id: BlockView.java,v 1.2 2005/06/25 23:12:32 doomdark Exp $
*/
-
package jdbm.recman;
+
/**
* This is a marker interface that is implemented by classes that
* interpret blocks of data by pretending to be an overlay.
*
* @see BlockIo#setView
*/
-public interface BlockView {
+public interface BlockView
+{
}
Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/RecordFile.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/RecordFile.java?rev=902552&r1=902551&r2=902552&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/RecordFile.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/RecordFile.java Sun Jan 24 12:33:27 2010
@@ -44,14 +44,15 @@
*
* $Id: RecordFile.java,v 1.6 2005/06/25 23:12:32 doomdark Exp $
*/
-
package jdbm.recman;
+
import java.io.*;
import java.util.*;
import org.apache.directory.server.i18n.I18n;
+
/**
* This class represents a random access file as a set of fixed size
* records. Each record has a physical record number, and records are
@@ -60,16 +61,17 @@
* The set of dirty records on the in-use list constitutes a transaction.
* Later on, we will send these records to some recovery thingy.
*/
-public final class RecordFile {
+public final class RecordFile
+{
final TransactionManager txnMgr;
// Todo: reorganize in hashes and fifos as necessary.
// free -> inUse -> dirty -> inTxn -> free
// free is a cache, thus a FIFO. The rest are hashes.
- private final LinkedList free = new LinkedList();
- private final HashMap inUse = new HashMap();
- private final HashMap dirty = new HashMap();
- private final HashMap inTxn = new HashMap();
+ private final LinkedList<BlockIo> free = new LinkedList<BlockIo>();
+ private final HashMap<Long,BlockIo> inUse = new HashMap<Long,BlockIo>();
+ private final HashMap<Long,BlockIo> dirty = new HashMap<Long,BlockIo>();
+ private final HashMap<Long,BlockIo> inTxn = new HashMap<Long,BlockIo>();
// transactions disabled?
private boolean transactionsDisabled = false;
@@ -86,6 +88,7 @@
private RandomAccessFile file;
private final String fileName;
+
/**
* Creates a new object on the indicated filename. The file is
* opened in read/write mode.
@@ -95,27 +98,33 @@
* @throws IOException whenever the creation of the underlying
* RandomAccessFile throws it.
*/
- RecordFile(String fileName) throws IOException {
+ RecordFile ( String fileName ) throws IOException
+ {
this.fileName = fileName;
file = new RandomAccessFile(fileName + extension, "rw");
- txnMgr = new TransactionManager(this);
+ txnMgr = new TransactionManager( this );
}
+
/**
* Returns the file name.
*/
- String getFileName() {
+ String getFileName()
+ {
return fileName;
}
+
/**
* Disables transactions: doesn't sync and doesn't use the
* transaction manager.
*/
- void disableTransactions() {
+ void disableTransactions()
+ {
transactionsDisabled = true;
}
+
/**
* Gets a block from the file. The returned byte array is
* the in-memory copy of the record, and thus can be written
@@ -124,46 +133,57 @@
*
* @param blockid The record number to retrieve.
*/
- BlockIo get(long blockid) throws IOException {
- Long key = new Long(blockid);
-
+ BlockIo get( long blockid ) throws IOException
+ {
// try in transaction list, dirty list, free list
- BlockIo node = (BlockIo) inTxn.get(key);
- if (node != null) {
- inTxn.remove(key);
- inUse.put(key, node);
+
+ BlockIo node = inTxn.get( blockid );
+ if ( node != null )
+ {
+ inTxn.remove( blockid );
+ inUse.put( blockid, node );
return node;
}
- node = (BlockIo) dirty.get(key);
- if (node != null) {
- dirty.remove(key);
- inUse.put(key, node);
+
+ node = dirty.get( blockid );
+ if ( node != null )
+ {
+ dirty.remove( blockid );
+ inUse.put( blockid, node );
return node;
}
- for (Iterator i = free.iterator(); i.hasNext(); ) {
- BlockIo cur = (BlockIo) i.next();
- if (cur.getBlockId() == blockid) {
+
+ for ( Iterator<BlockIo> i = free.iterator(); i.hasNext(); )
+ {
+ BlockIo cur = i.next();
+ if ( cur.getBlockId() == blockid )
+ {
node = cur;
i.remove();
- inUse.put(key, node);
+ inUse.put( blockid, node );
return node;
}
}
// sanity check: can't be on in use list
- if (inUse.get(key) != null) {
+ if ( inUse.get( blockid ) != null )
+ {
throw new Error( I18n.err( I18n.ERR_554, blockid ) );
}
// get a new node and read it from the file
- node = getNewNode(blockid);
+ node = getNewNode( blockid );
long offset = blockid * BLOCK_SIZE;
- if (file.length() > 0 && offset <= file.length()) {
- read(file, offset, node.getData(), BLOCK_SIZE);
- } else {
- System.arraycopy(cleanData, 0, node.getData(), 0, BLOCK_SIZE);
+ if ( file.length() > 0 && offset <= file.length() )
+ {
+ read( file, offset, node.getData(), BLOCK_SIZE );
+ }
+ else
+ {
+ System.arraycopy( cleanData, 0, node.getData(), 0, BLOCK_SIZE );
}
- inUse.put(key, node);
+
+ inUse.put( blockid, node );
node.setClean();
return node;
}
@@ -175,135 +195,176 @@
* @param blockid The record number to release.
* @param isDirty If true, the block was modified since the get().
*/
- void release(long blockid, boolean isDirty)
- throws IOException {
- BlockIo node = (BlockIo) inUse.get(new Long(blockid));
- if (node == null)
+ void release( long blockid, boolean isDirty ) throws IOException
+ {
+ BlockIo node = inUse.get( blockid );
+
+ if ( node == null )
+ {
throw new IOException( I18n.err( I18n.ERR_555, blockid ) );
- if (!node.isDirty() && isDirty)
+ }
+
+ if ( ! node.isDirty() && isDirty )
+ {
node.setDirty();
- release(node);
+ }
+
+ release( node );
}
+
/**
* Releases a block.
*
* @param block The block to release.
*/
- void release(BlockIo block) {
- Long key = new Long(block.getBlockId());
- inUse.remove(key);
- if (block.isDirty()) {
+ void release( BlockIo block )
+ {
+ inUse.remove( block.getBlockId() );
+
+ if ( block.isDirty() )
+ {
// System.out.println( "Dirty: " + key + block );
- dirty.put(key, block);
- } else {
- if (!transactionsDisabled && block.isInTransaction()) {
- inTxn.put(key, block);
- } else {
- free.add(block);
+ dirty.put( block.getBlockId(), block );
+ }
+ else
+ {
+ if ( ! transactionsDisabled && block.isInTransaction() )
+ {
+ inTxn.put( block.getBlockId(), block );
+ }
+ else
+ {
+ free.add( block );
}
}
}
+
/**
* Discards a block (will not write the block even if it's dirty)
*
* @param block The block to discard.
*/
- void discard(BlockIo block) {
- Long key = new Long(block.getBlockId());
- inUse.remove(key);
+ void discard( BlockIo block )
+ {
+ inUse.remove( block.getBlockId() );
// note: block not added to free list on purpose, because
// it's considered invalid
}
+
/**
- * Commits the current transaction by flushing all dirty buffers
- * to disk.
+ * Commits the current transaction by flushing all dirty buffers to disk.
*/
- void commit() throws IOException {
+ void commit() throws IOException
+ {
// debugging...
- if (!inUse.isEmpty() && inUse.size() > 1) {
- showList(inUse.values().iterator());
+ if ( ! inUse.isEmpty() && inUse.size() > 1 )
+ {
+ showList( inUse.values().iterator() );
throw new Error( I18n.err( I18n.ERR_556, inUse.size() ) );
}
// System.out.println("committing...");
- if ( dirty.size() == 0 ) {
+ if ( dirty.size() == 0 )
+ {
// if no dirty blocks, skip commit process
return;
}
- if (!transactionsDisabled) {
+
+ if ( ! transactionsDisabled )
+ {
txnMgr.start();
}
- for (Iterator i = dirty.values().iterator(); i.hasNext(); ) {
- BlockIo node = (BlockIo) i.next();
+
+ for ( Iterator<BlockIo> i = dirty.values().iterator(); i.hasNext(); )
+ {
+ BlockIo node = ( BlockIo ) i.next();
i.remove();
+
// System.out.println("node " + node + " map size now " + dirty.size());
- if (transactionsDisabled) {
+ if ( transactionsDisabled )
+ {
long offset = node.getBlockId() * BLOCK_SIZE;
- file.seek(offset);
- file.write(node.getData());
+ file.seek( offset );
+ file.write( node.getData() );
node.setClean();
- free.add(node);
+ free.add( node );
}
- else {
- txnMgr.add(node);
- inTxn.put(new Long(node.getBlockId()), node);
+ else
+ {
+ txnMgr.add( node );
+ inTxn.put( node.getBlockId(), node );
}
}
- if (!transactionsDisabled) {
+
+ if ( ! transactionsDisabled )
+ {
txnMgr.commit();
}
}
+
/**
* Rollback the current transaction by discarding all dirty buffers
*/
- void rollback() throws IOException {
+ void rollback() throws IOException
+ {
// debugging...
- if (!inUse.isEmpty()) {
- showList(inUse.values().iterator());
+ if ( ! inUse.isEmpty() )
+ {
+ showList( inUse.values().iterator() );
throw new Error( I18n.err( I18n.ERR_557, inUse.size() ) );
}
+
// System.out.println("rollback...");
dirty.clear();
txnMgr.synchronizeLogFromDisk();
- if (!inTxn.isEmpty()) {
- showList(inTxn.values().iterator());
+ if ( ! inTxn.isEmpty() )
+ {
+ showList( inTxn.values().iterator() );
throw new Error( I18n.err( I18n.ERR_558, inTxn.size() ) );
};
}
+
/**
* Commits and closes file.
*/
- void close() throws IOException {
- if (!dirty.isEmpty()) {
+ void close() throws IOException
+ {
+ if ( ! dirty.isEmpty() )
+ {
commit();
}
+
txnMgr.shutdown();
- if (!inTxn.isEmpty()) {
- showList(inTxn.values().iterator());
+ if ( ! inTxn.isEmpty() )
+ {
+ showList( inTxn.values().iterator() );
throw new Error( I18n.err( I18n.ERR_559 ) );
}
// these actually ain't that bad in a production release
- if (!dirty.isEmpty()) {
- System.out.println("ERROR: dirty blocks at close time");
- showList(dirty.values().iterator());
+ if ( ! dirty.isEmpty() )
+ {
+ System.out.println( "ERROR: dirty blocks at close time" );
+ showList( dirty.values().iterator() );
throw new Error( I18n.err( I18n.ERR_560 ) );
}
- if (!inUse.isEmpty()) {
- System.out.println("ERROR: inUse blocks at close time");
- showList(inUse.values().iterator());
+
+ if ( ! inUse.isEmpty() )
+ {
+ System.out.println( "ERROR: inUse blocks at close time" );
+ showList( inUse.values().iterator() );
throw new Error( I18n.err( I18n.ERR_561 ) );
}
@@ -318,73 +379,87 @@
* Force closing the file and underlying transaction manager.
* Used for testing purposed only.
*/
- void forceClose() throws IOException {
+ void forceClose() throws IOException
+ {
txnMgr.forceClose();
file.close();
}
+
/**
* Prints contents of a list
*/
- private void showList(Iterator i) {
+ private void showList( Iterator<BlockIo> i )
+ {
int cnt = 0;
- while (i.hasNext()) {
- System.out.println("elem " + cnt + ": " + i.next());
+ while ( i.hasNext() )
+ {
+ System.out.println( "elem " + cnt + ": " + i.next() );
cnt++;
}
}
/**
- * Returns a new node. The node is retrieved (and removed)
- * from the released list or created new.
+ * Returns a new node. The node is retrieved (and removed) from the
+ * released list or created new.
*/
- private BlockIo getNewNode(long blockid)
- throws IOException {
-
+ private BlockIo getNewNode( long blockid ) throws IOException
+ {
BlockIo retval = null;
- if (!free.isEmpty()) {
- retval = (BlockIo) free.removeFirst();
- }
- if (retval == null)
- retval = new BlockIo(0, new byte[BLOCK_SIZE]);
+ if ( ! free.isEmpty() )
+ {
+ retval = ( BlockIo ) free.removeFirst();
+ }
+
+ if ( retval == null )
+ {
+ retval = new BlockIo( 0, new byte[BLOCK_SIZE] );
+ }
+
retval.setBlockId(blockid);
- retval.setView(null);
+ retval.setView( null );
return retval;
}
+
/**
- * Synchs a node to disk. This is called by the transaction manager's
+ * Synchronizes a node to disk. This is called by the transaction manager's
* synchronization code.
*/
- void synch(BlockIo node) throws IOException {
+ void synch( BlockIo node ) throws IOException
+ {
byte[] data = node.getData();
- if (data != null) {
+ if ( data != null )
+ {
long offset = node.getBlockId() * BLOCK_SIZE;
- file.seek(offset);
- file.write(data);
+ file.seek( offset );
+ file.write( data );
}
}
+
/**
* Releases a node from the transaction list, if it was sitting
* there.
*
* @param recycle true if block data can be reused
*/
- void releaseFromTransaction(BlockIo node, boolean recycle)
- throws IOException {
- Long key = new Long(node.getBlockId());
- if ((inTxn.remove(key) != null) && recycle) {
- free.add(node);
+ void releaseFromTransaction( BlockIo node, boolean recycle ) throws IOException
+ {
+ if ( (inTxn.remove( node.getBlockId() ) != null ) && recycle )
+ {
+ free.add( node );
}
}
+
/**
* Synchronizes the file.
*/
- void sync() throws IOException {
+ void sync() throws IOException
+ {
file.getFD().sync();
}
@@ -392,20 +467,21 @@
/**
* Utility method: Read a block from a RandomAccessFile
*/
- private static void read(RandomAccessFile file, long offset,
- byte[] buffer, int nBytes) throws IOException {
- file.seek(offset);
+ private static void read( RandomAccessFile file, long offset, byte[] buffer, int nBytes) throws IOException
+ {
+ file.seek( offset );
int remaining = nBytes;
int pos = 0;
- while (remaining > 0) {
- int read = file.read(buffer, pos, remaining);
- if (read == -1) {
- System.arraycopy(cleanData, 0, buffer, pos, remaining);
+ while ( remaining > 0 )
+ {
+ int read = file.read( buffer, pos, remaining );
+ if ( read == -1 )
+ {
+ System.arraycopy( cleanData, 0, buffer, pos, remaining );
break;
}
remaining -= read;
pos += read;
}
}
-
-}
+}
\ No newline at end of file
Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/RecordHeader.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/RecordHeader.java?rev=902552&r1=902551&r2=902552&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/RecordHeader.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/RecordHeader.java Sun Jan 24 12:33:27 2010
@@ -51,7 +51,7 @@
/**
* The data that comes at the start of a record of data. It stores
- * both the current size and the avaliable size for the record - the latter
+ * both the current size and the available size for the record - the latter
* can be bigger than the former, which allows the record to grow without
* needing to be moved and which allows the system to put small records
* in larger free spots.