Skip to content

Commit

Permalink
Various cleanups for CommonAbstractStore
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed Mar 2, 2016
1 parent 9008afb commit b321eb8
Showing 1 changed file with 12 additions and 34 deletions.
Expand Up @@ -31,7 +31,6 @@
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.helpers.collection.Visitor;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.io.pagecache.PageCacheOpenOptions;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.io.pagecache.PagedFile;
import org.neo4j.kernel.configuration.Config;
Expand Down Expand Up @@ -160,6 +159,7 @@ public String getTypeDescriptor()
protected void checkStorage( boolean createIfNotExists )
{
int pageSize = pageCache.pageSize();
//noinspection EmptyTryBlock
try ( PagedFile ignore = pageCache.map( storageFileName, pageSize, ANY_PAGE_SIZE ) )
{
}
Expand Down Expand Up @@ -335,31 +335,6 @@ private void loadIdGenerator()
}
}

protected int getHeaderRecord() throws IOException
{
int headerRecord = 0;
try ( PagedFile pagedFile = pageCache.map( getStorageFileName(), pageCache.pageSize() ) )
{
try ( PageCursor pageCursor = pagedFile.io( 0, PF_SHARED_READ_LOCK ) )
{
if ( pageCursor.next() )
{
do
{
headerRecord = pageCursor.getInt();
}
while ( pageCursor.shouldRetry() );
}
}
}
if ( headerRecord <= 0 )
{
throw new InvalidRecordException( "Illegal block size: " +
headerRecord + " in " + getStorageFileName() );
}
return headerRecord;
}

public boolean isInUse( long id )
{
long pageId = pageIdForRecord( id );
Expand Down Expand Up @@ -545,9 +520,10 @@ public long nextId()
*/
public void freeId( long id )
{
if ( idGenerator != null )
IdGenerator generator = this.idGenerator;
if ( generator != null )
{
idGenerator.freeId( id );
generator.freeId( id );
}
// else we're deleting records as part of applying transactions during recovery, and that's fine
}
Expand All @@ -573,13 +549,15 @@ public void setHighId( long highId )
{
// This method might get called during recovery, where we don't have a reliable id generator yet,
// so ignore these calls and let rebuildIdGenerators() figure out the high id after recovery.
if ( idGenerator != null )
IdGenerator generator = this.idGenerator;
if ( generator != null )
{
synchronized ( idGenerator )
//noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized ( generator )
{
if ( highId > idGenerator.getHighId() )
if ( highId > generator.getHighId() )
{
idGenerator.setHighId( highId );
generator.setHighId( highId );
}
}
}
Expand Down Expand Up @@ -750,7 +728,7 @@ protected void assertNotClosed()
* Requesting an operation from after this method has been invoked is
* illegal and an exception will be thrown.
* <p>
* This method will start by invoking the {@link #closeStorage} method
* This method will start by invoking the {@link #closeStoreFile()} method
* giving the implementing store way to do anything that it needs to do
* before the pagedFile is closed.
*/
Expand Down Expand Up @@ -860,7 +838,7 @@ public void logIdUsage( Logger logger )
* {@link #logVersions(Logger)}
* For a good samaritan to pick up later.
*/
public void visitStore( Visitor<CommonAbstractStore,RuntimeException> visitor )
public void visitStore( Visitor<CommonAbstractStore<RECORD>,RuntimeException> visitor )
{
visitor.visit( this );
}
Expand Down

0 comments on commit b321eb8

Please sign in to comment.