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/02/24 15:29:13 UTC
svn commit: r915802 - in
/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman:
FreeLogicalRowIdPage.java FreePhysicalRowIdPage.java
FreePhysicalRowIdPageManager.java PageCursor.java PageManager.java
PhysicalRowIdManager.java
Author: akarasulu
Date: Wed Feb 24 14:29:12 2010
New Revision: 915802
URL: http://svn.apache.org/viewvc?rev=915802&view=rev
Log:
more formatting
Modified:
directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreeLogicalRowIdPage.java
directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPage.java
directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPageManager.java
directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageCursor.java
directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageManager.java
directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PhysicalRowIdManager.java
Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreeLogicalRowIdPage.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreeLogicalRowIdPage.java?rev=915802&r1=915801&r2=915802&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreeLogicalRowIdPage.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreeLogicalRowIdPage.java Wed Feb 24 14:29:12 2010
@@ -57,33 +57,39 @@
{
// offsets
private static final short O_COUNT = PageHeader.SIZE; // short count
- static final short O_FREE = (short)(O_COUNT + Magic.SZ_SHORT);
- static final short ELEMS_PER_PAGE = ( short )
- ( ( RecordFile.BLOCK_SIZE - O_FREE ) / PhysicalRowId.SIZE );
+ static final short O_FREE = O_COUNT + Magic.SZ_SHORT;
+ static final short ELEMS_PER_PAGE = ( RecordFile.BLOCK_SIZE - O_FREE ) / PhysicalRowId.SIZE;
// slots we returned.
final PhysicalRowId[] slots = new PhysicalRowId[ELEMS_PER_PAGE];
+
/**
- * Constructs a data page view from the indicated block.
+ * Constructs a data page view from the indicated block.
*/
- FreeLogicalRowIdPage(BlockIo block) {
- super(block);
+ FreeLogicalRowIdPage( BlockIo block )
+ {
+ super( block );
}
+
/**
- * Factory method to create or return a data page for the
- * indicated block.
+ * Factory method to create or return a data page for the indicated block.
*/
- static FreeLogicalRowIdPage getFreeLogicalRowIdPageView(BlockIo block) {
-
+ static FreeLogicalRowIdPage getFreeLogicalRowIdPageView( BlockIo block )
+ {
BlockView view = block.getView();
- if (view != null && view instanceof FreeLogicalRowIdPage)
- return (FreeLogicalRowIdPage) view;
+ if ( view != null && view instanceof FreeLogicalRowIdPage )
+ {
+ return ( FreeLogicalRowIdPage ) view;
+ }
else
+ {
return new FreeLogicalRowIdPage(block);
+ }
}
+
/** Returns the number of free rowids */
short getCount() {
return block.readShort(O_COUNT);
Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPage.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPage.java?rev=915802&r1=915801&r2=915802&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPage.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPage.java Wed Feb 24 14:29:12 2010
@@ -55,8 +55,7 @@
// offsets
private static final short O_COUNT = PageHeader.SIZE; // short count
static final short O_FREE = O_COUNT + Magic.SZ_SHORT;
- static final short ELEMS_PER_PAGE = ( RecordFile.BLOCK_SIZE - O_FREE )
- / FreePhysicalRowId.SIZE;
+ static final short ELEMS_PER_PAGE = ( RecordFile.BLOCK_SIZE - O_FREE ) / FreePhysicalRowId.SIZE;
// slots we returned.
FreePhysicalRowId[] slots = new FreePhysicalRowId[ELEMS_PER_PAGE];
@@ -174,9 +173,9 @@
*/
int getFirstLargerThan( int size )
{
- for (int i = 0; i < ELEMS_PER_PAGE; i++)
+ for ( int i = 0; i < ELEMS_PER_PAGE; i++ )
{
- if ( isAllocated(i) && get(i).getSize() >= size )
+ if ( isAllocated( i ) && get( i ).getSize() >= size )
{
return i;
}
Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPageManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPageManager.java?rev=915802&r1=915801&r2=915802&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPageManager.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPageManager.java Wed Feb 24 14:29:12 2010
@@ -44,109 +44,118 @@
*
* $Id: FreePhysicalRowIdPageManager.java,v 1.2 2001/11/17 16:14:25 boisvert Exp $
*/
-
package jdbm.recman;
+
import java.io.IOException;
+
/**
- * This class manages free physical rowid pages and provides methods
- * to free and allocate physical rowids on a high level.
+ * This class manages free physical rowid pages and provides methods to free
+ * and allocate physical rowids at a high level.
*/
final class FreePhysicalRowIdPageManager
{
// our record file
- protected RecordFile _file;
+ protected RecordFile file;
// our page manager
- protected PageManager _pageman;
+ protected PageManager pageman;
+
/**
- * Creates a new instance using the indicated record file and
- * page manager.
+ * Creates a new instance using the indicated record file and page manager.
*/
- FreePhysicalRowIdPageManager( RecordFile file, PageManager pageman )
- throws IOException
+ FreePhysicalRowIdPageManager( RecordFile file, PageManager pageman ) throws IOException
{
- _file = file;
- _pageman = pageman;
+ this.file = file;
+ this.pageman = pageman;
}
/**
- * Returns a free physical rowid of the indicated size, or
- * null if nothing was found.
+ * Returns a free physical rowid of the indicated size, or null if nothing
+ * was found.
*/
- Location get( int size )
- throws IOException
+ Location get( int size ) throws IOException
{
- // Loop through the free physical rowid list until we find
- // a rowid that's large enough.
+ // Loop through the free physical rowid list until we find a rowid
+ // that's large enough.
Location retval = null;
- PageCursor curs = new PageCursor( _pageman, Magic.FREEPHYSIDS_PAGE );
+ PageCursor curs = new PageCursor( pageman, Magic.FREEPHYSIDS_PAGE );
- while (curs.next() != 0) {
+ while ( curs.next() != 0 )
+ {
FreePhysicalRowIdPage fp = FreePhysicalRowIdPage
- .getFreePhysicalRowIdPageView( _file.get( curs.getCurrent() ) );
+ .getFreePhysicalRowIdPageView( file.get( curs.getCurrent() ) );
int slot = fp.getFirstLargerThan( size );
- if ( slot != -1 ) {
+
+ if ( slot != -1 )
+ {
// got one!
retval = new Location( fp.get( slot ) );
- int slotsize = fp.get( slot ).getSize();
fp.free( slot );
- if ( fp.getCount() == 0 ) {
+ if ( fp.getCount() == 0 )
+ {
// page became empty - free it
- _file.release( curs.getCurrent(), false );
- _pageman.free( Magic.FREEPHYSIDS_PAGE, curs.getCurrent() );
- } else {
- _file.release( curs.getCurrent(), true );
+ file.release( curs.getCurrent(), false );
+ pageman.free( Magic.FREEPHYSIDS_PAGE, curs.getCurrent() );
+ }
+ else
+ {
+ file.release( curs.getCurrent(), true );
}
return retval;
- } else {
+ }
+ else
+ {
// no luck, go to next page
- _file.release( curs.getCurrent(), false );
+ file.release( curs.getCurrent(), false );
}
-
}
return null;
}
+
/**
- * Puts the indicated rowid on the free list
+ * Puts the indicated rowid on the free list.
*/
- void put(Location rowid, int size)
- throws IOException {
+ void put( Location rowid, int size ) throws IOException
+ {
+ FreePhysicalRowId free = null;
+ PageCursor curs = new PageCursor( pageman, Magic.FREEPHYSIDS_PAGE );
+ long freePage = 0;
+
+ while ( curs.next() != 0 )
+ {
+ freePage = curs.getCurrent();
+ BlockIo curBlock = file.get( freePage );
+ FreePhysicalRowIdPage fp = FreePhysicalRowIdPage.getFreePhysicalRowIdPageView( curBlock );
+ int slot = fp.getFirstFree();
+
+ if ( slot != -1 )
+ {
+ free = fp.alloc( slot );
+ break;
+ }
+
+ file.release( curBlock );
+ }
+
+ if ( free == null )
+ {
+ // No more space on the free list, add a page.
+ freePage = pageman.allocate( Magic.FREEPHYSIDS_PAGE );
+ BlockIo curBlock = file.get( freePage );
+ FreePhysicalRowIdPage fp = FreePhysicalRowIdPage.getFreePhysicalRowIdPageView( curBlock );
+ free = fp.alloc( 0 );
+ }
- FreePhysicalRowId free = null;
- PageCursor curs = new PageCursor(_pageman, Magic.FREEPHYSIDS_PAGE);
- long freePage = 0;
- while (curs.next() != 0) {
- freePage = curs.getCurrent();
- BlockIo curBlock = _file.get(freePage);
- FreePhysicalRowIdPage fp = FreePhysicalRowIdPage
- .getFreePhysicalRowIdPageView(curBlock);
- int slot = fp.getFirstFree();
- if (slot != -1) {
- free = fp.alloc(slot);
- break;
- }
-
- _file.release(curBlock);
- }
- if (free == null) {
- // No more space on the free list, add a page.
- freePage = _pageman.allocate(Magic.FREEPHYSIDS_PAGE);
- BlockIo curBlock = _file.get(freePage);
- FreePhysicalRowIdPage fp =
- FreePhysicalRowIdPage.getFreePhysicalRowIdPageView(curBlock);
- free = fp.alloc(0);
- }
-
- free.setBlock(rowid.getBlock());
- free.setOffset(rowid.getOffset());
- free.setSize(size);
- _file.release(freePage, true);
+ free.setBlock( rowid.getBlock() );
+ free.setOffset( rowid.getOffset() );
+ free.setSize( size );
+ file.release( freePage, true );
}
}
Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageCursor.java?rev=915802&r1=915801&r2=915802&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageCursor.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageCursor.java Wed Feb 24 14:29:12 2010
@@ -44,60 +44,76 @@
*
* $Id: PageCursor.java,v 1.1 2000/05/06 00:00:31 boisvert Exp $
*/
-
package jdbm.recman;
+
import java.io.IOException;
+
/**
- * This class provides a cursor that can follow lists of pages
- * bi-directionally.
+ * This class provides a cursor that can follow lists of pages bi-directionally.
*/
-final class PageCursor {
+final class PageCursor
+{
PageManager pageman;
long current;
short type;
+
/**
- * Constructs a page cursor that starts at the indicated block.
+ * Constructs a page cursor that starts at the indicated block.
*/
- PageCursor(PageManager pageman, long current) {
+ PageCursor( PageManager pageman, long current )
+ {
this.pageman = pageman;
this.current = current;
}
+
/**
- * Constructs a page cursor that starts at the first block
- * of the indicated list.
+ * Constructs a page cursor that starts at the first block of the
+ * indicated list.
*/
- PageCursor(PageManager pageman, short type) throws IOException {
+ PageCursor( PageManager pageman, short type ) throws IOException
+ {
this.pageman = pageman;
this.type = type;
}
+
/**
- * Returns the current value of the cursor.
+ * Returns the current value of the cursor.
*/
- long getCurrent() throws IOException {
+ long getCurrent() throws IOException
+ {
return current;
}
+
/**
- * Returns the next value of the cursor
+ * Returns the next value of the cursor.
*/
- long next() throws IOException {
- if (current == 0)
- current = pageman.getFirst(type);
+ long next() throws IOException
+ {
+ if ( current == 0 )
+ {
+ current = pageman.getFirst( type );
+ }
else
- current = pageman.getNext(current);
+ {
+ current = pageman.getNext( current );
+ }
+
return current;
}
+
/**
- * Returns the previous value of the cursor
+ * Returns the previous value of the cursor
*/
- long prev() throws IOException {
- current = pageman.getPrev(current);
+ long prev() throws IOException
+ {
+ current = pageman.getPrev( current );
return current;
}
}
Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageManager.java?rev=915802&r1=915801&r2=915802&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageManager.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageManager.java Wed Feb 24 14:29:12 2010
@@ -178,7 +178,7 @@
throw new Error( I18n.err( I18n.ERR_549 ) );
}
- if (recid == 0)
+ if ( recid == 0 )
{
throw new Error( I18n.err( I18n.ERR_550 ) );
}
@@ -276,7 +276,7 @@
/**
* Commit all pending (in-memory) data by flushing the page manager.
- * This forces a flush of all outstanding blocks (this it's an implicit
+ * This forces a flush of all outstanding blocks (this is an implicit
* {@link RecordFile#commit} as well).
*/
void commit() throws IOException
@@ -292,8 +292,10 @@
/**
- * Flushes the page manager. This forces a flush of all outstanding
- * blocks (this it's an implicit {@link RecordFile#commit} as well).
+ * Flushes the page manager. This forces a flush of all outstanding
+ * blocks (this is an implicit {@link RecordFile#commit} as well).
+ *
+ * @TODO completely wrong description of method
*/
void rollback() throws IOException
{
@@ -315,8 +317,8 @@
/**
- * Closes the page manager. This flushes the page manager and releases
- * the lock on the header.
+ * Closes the page manager. This flushes the page manager and releases
+ * the lock on the header.
*/
void close() throws IOException
{
@@ -335,4 +337,4 @@
{
return header;
}
-}
+}
\ No newline at end of file
Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PhysicalRowIdManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PhysicalRowIdManager.java?rev=915802&r1=915801&r2=915802&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PhysicalRowIdManager.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PhysicalRowIdManager.java Wed Feb 24 14:29:12 2010
@@ -44,17 +44,17 @@
*
* $Id: PhysicalRowIdManager.java,v 1.3 2003/03/21 03:00:09 boisvert Exp $
*/
-
package jdbm.recman;
+
import java.io.IOException;
+
/**
- * This class manages physical row ids, and their data.
+ * This class manages physical row ids, and their data.
*/
final class PhysicalRowIdManager
{
-
// The file we're talking to and the associated page manager.
private RecordFile file;
private PageManager pageman;
@@ -284,7 +284,6 @@
{
// get the rowid, and write a zero current size into it.
BlockIo curBlock = file.get( id.getBlock() );
- DataPage curPage = DataPage.getDataPageView( curBlock );
RecordHeader hdr = new RecordHeader( curBlock, id.getOffset() );
hdr.setCurrentSize( 0 );
file.release( id.getBlock(), true );