Skip to content

Commit

Permalink
Tighten up some names in the page cache warmer.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed Mar 20, 2018
1 parent 814ff1c commit a787b02
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Expand Up @@ -164,12 +164,12 @@ private long reheat( PagedFile file, Profile[] existingProfiles ) throws IOExcep


// The file contents checks out. Let's load it in. // The file contents checks out. Let's load it in.
long pagesLoaded = 0; long pagesLoaded = 0;
try ( InputStream inputStream = savedProfile.get().read( fs ); try ( InputStream input = savedProfile.get().read( fs );
PageLoader loader = pageLoaderFactory.getLoader( file ) ) PageLoader loader = pageLoaderFactory.getLoader( file ) )
{ {
long pageId = 0; long pageId = 0;
int b; int b;
while ( (b = inputStream.read()) != -1 ) while ( (b = input.read()) != -1 )
{ {
for ( int i = 0; i < 8; i++ ) for ( int i = 0; i < 8; i++ )
{ {
Expand All @@ -195,12 +195,12 @@ private long reheat( PagedFile file, Profile[] existingProfiles ) throws IOExcep
private boolean verifyChecksum( Profile profile ) private boolean verifyChecksum( Profile profile )
{ {
// Successfully reading through and closing the compressed file implies verifying the gzip checksum. // Successfully reading through and closing the compressed file implies verifying the gzip checksum.
try ( InputStream inputStream = profile.read( fs ) ) try ( InputStream input = profile.read( fs ) )
{ {
int b; int b;
do do
{ {
b = inputStream.read(); b = input.read();
} }
while ( b != -1 ); while ( b != -1 );
} }
Expand Down Expand Up @@ -254,7 +254,7 @@ private long profile( PagedFile file, Profile[] existingProfiles ) throws IOExce
.map( Profile::next ) .map( Profile::next )
.orElse( Profile.first( file.file() ) ); .orElse( Profile.first( file.file() ) );


try ( OutputStream outputStream = nextProfile.write( fs ); try ( OutputStream output = nextProfile.write( fs );
PageCursor cursor = file.io( 0, PF_SHARED_READ_LOCK | PF_NO_FAULT ) ) PageCursor cursor = file.io( 0, PF_SHARED_READ_LOCK | PF_NO_FAULT ) )
{ {
int stepper = 0; int stepper = 0;
Expand All @@ -273,19 +273,19 @@ private long profile( PagedFile file, Profile[] existingProfiles ) throws IOExce
stepper++; stepper++;
if ( stepper == 8 ) if ( stepper == 8 )
{ {
outputStream.write( b ); output.write( b );
b = 0; b = 0;
stepper = 0; stepper = 0;
} }
} }
outputStream.write( b ); output.write( b );
outputStream.flush(); output.flush();
} }


// Delete previous profile files. // Delete previous profile files.
filterRelevant( existingProfiles, file ) filterRelevant( existingProfiles, file )
.filter( profile -> !refCounts.contains( profile ) ) .filter( profile -> !refCounts.contains( profile ) )
.forEach( p -> p.delete( fs ) ); .forEach( profile -> profile.delete( fs ) );


return pagesInMemory; return pagesInMemory;
} }
Expand Down
Expand Up @@ -26,31 +26,31 @@


class ProfileRefCounts class ProfileRefCounts
{ {
private final Map<Profile,MutableInt> fileBag; private final Map<Profile,MutableInt> bag;


public ProfileRefCounts() public ProfileRefCounts()
{ {
fileBag = new HashMap<>(); bag = new HashMap<>();
} }


synchronized void incrementRefCounts( Profile[] profiles ) synchronized void incrementRefCounts( Profile[] profiles )
{ {
for ( Profile profile : profiles ) for ( Profile profile : profiles )
{ {
fileBag.computeIfAbsent( profile, p -> new MutableInt() ).increment(); bag.computeIfAbsent( profile, p -> new MutableInt() ).increment();
} }
} }


synchronized void decrementRefCounts( Profile[] profiles ) synchronized void decrementRefCounts( Profile[] profiles )
{ {
for ( Profile profile : profiles ) for ( Profile profile : profiles )
{ {
fileBag.computeIfPresent( profile, (p,i) -> i.decrementAndGet() == 0 ? null : i ); bag.computeIfPresent( profile, ( p, i) -> i.decrementAndGet() == 0 ? null : i );
} }
} }


synchronized boolean contains( Profile profile ) synchronized boolean contains( Profile profile )
{ {
return fileBag.containsKey( profile ); return bag.containsKey( profile );
} }
} }

0 comments on commit a787b02

Please sign in to comment.