@ -195,7 +195,7 @@ public final class DfsBlockCache {
blockSizeShift = Integer . numberOfTrailingZeros ( blockSize ) ;
blockSizeShift = Integer . numberOfTrailingZeros ( blockSize ) ;
clockLock = new ReentrantLock ( true /* fair */ ) ;
clockLock = new ReentrantLock ( true /* fair */ ) ;
clockHand = new Ref < > ( new DfsPack Key ( ) , - 1 , 0 , null ) ;
clockHand = new Ref < > ( new DfsStream Key ( ) , - 1 , 0 , null ) ;
clockHand . next = clockHand ;
clockHand . next = clockHand ;
packCache = new ConcurrentHashMap < > (
packCache = new ConcurrentHashMap < > (
@ -260,7 +260,7 @@ public final class DfsBlockCache {
return packFiles ;
return packFiles ;
}
}
DfsPackFile getOrCreate ( DfsPackDescription dsc , DfsPack Key key ) {
DfsPackFile getOrCreate ( DfsPackDescription dsc , DfsStream Key key ) {
// TODO This table grows without bound. It needs to clean up
// TODO This table grows without bound. It needs to clean up
// entries that aren't in cache anymore, and aren't being used
// entries that aren't in cache anymore, and aren't being used
// by a live DfsObjDatabase reference.
// by a live DfsObjDatabase reference.
@ -277,7 +277,7 @@ public final class DfsBlockCache {
return v ; // another thread
return v ; // another thread
} else {
} else {
return new DfsPackFile (
return new DfsPackFile (
this , dsc , key ! = null ? key : new DfsPack Key ( ) ) ;
this , dsc , key ! = null ? key : new DfsStream Key ( ) ) ;
}
}
} ) ;
} ) ;
}
}
@ -320,7 +320,7 @@ public final class DfsBlockCache {
final long requestedPosition = position ;
final long requestedPosition = position ;
position = pack . alignToBlock ( position ) ;
position = pack . alignToBlock ( position ) ;
DfsPack Key key = pack . key ;
DfsStream Key key = pack . key ;
int slot = slot ( key , position ) ;
int slot = slot ( key , position ) ;
HashEntry e1 = table . get ( slot ) ;
HashEntry e1 = table . get ( slot ) ;
DfsBlock v = scan ( e1 , key , position ) ;
DfsBlock v = scan ( e1 , key , position ) ;
@ -442,10 +442,10 @@ public final class DfsBlockCache {
}
}
void put ( DfsBlock v ) {
void put ( DfsBlock v ) {
put ( v . pack , v . start , v . size ( ) , v ) ;
put ( v . stream , v . start , v . size ( ) , v ) ;
}
}
< T > Ref < T > put ( DfsPack Key key , long pos , int size , T v ) {
< T > Ref < T > put ( DfsStream Key key , long pos , int size , T v ) {
int slot = slot ( key , pos ) ;
int slot = slot ( key , pos ) ;
HashEntry e1 = table . get ( slot ) ;
HashEntry e1 = table . get ( slot ) ;
Ref < T > ref = scanRef ( e1 , key , pos ) ;
Ref < T > ref = scanRef ( e1 , key , pos ) ;
@ -481,12 +481,12 @@ public final class DfsBlockCache {
return ref ;
return ref ;
}
}
boolean contains ( DfsPack Key key , long position ) {
boolean contains ( DfsStream Key key , long position ) {
return scan ( table . get ( slot ( key , position ) ) , key , position ) ! = null ;
return scan ( table . get ( slot ( key , position ) ) , key , position ) ! = null ;
}
}
@SuppressWarnings ( "unchecked" )
@SuppressWarnings ( "unchecked" )
< T > T get ( DfsPack Key key , long position ) {
< T > T get ( DfsStream Key key , long position ) {
T val = ( T ) scan ( table . get ( slot ( key , position ) ) , key , position ) ;
T val = ( T ) scan ( table . get ( slot ( key , position ) ) , key , position ) ;
if ( val = = null )
if ( val = = null )
statMiss . incrementAndGet ( ) ;
statMiss . incrementAndGet ( ) ;
@ -495,13 +495,13 @@ public final class DfsBlockCache {
return val ;
return val ;
}
}
private < T > T scan ( HashEntry n , DfsPack Key pack , long position ) {
private < T > T scan ( HashEntry n , DfsStream Key pack , long position ) {
Ref < T > r = scanRef ( n , pack , position ) ;
Ref < T > r = scanRef ( n , pack , position ) ;
return r ! = null ? r . get ( ) : null ;
return r ! = null ? r . get ( ) : null ;
}
}
@SuppressWarnings ( "unchecked" )
@SuppressWarnings ( "unchecked" )
private < T > Ref < T > scanRef ( HashEntry n , DfsPack Key pack , long position ) {
private < T > Ref < T > scanRef ( HashEntry n , DfsStream Key pack , long position ) {
for ( ; n ! = null ; n = n . next ) {
for ( ; n ! = null ; n = n . next ) {
Ref < T > r = n . ref ;
Ref < T > r = n . ref ;
if ( r . pack = = pack & & r . position = = position )
if ( r . pack = = pack & & r . position = = position )
@ -514,11 +514,11 @@ public final class DfsBlockCache {
packCache . remove ( pack . getPackDescription ( ) ) ;
packCache . remove ( pack . getPackDescription ( ) ) ;
}
}
private int slot ( DfsPack Key pack , long position ) {
private int slot ( DfsStream Key pack , long position ) {
return ( hash ( pack . hash , position ) > > > 1 ) % tableSize ;
return ( hash ( pack . hash , position ) > > > 1 ) % tableSize ;
}
}
private ReentrantLock lockFor ( DfsPack Key pack , long position ) {
private ReentrantLock lockFor ( DfsStream Key pack , long position ) {
return loadLocks [ ( hash ( pack . hash , position ) > > > 1 ) % loadLocks . length ] ;
return loadLocks [ ( hash ( pack . hash , position ) > > > 1 ) % loadLocks . length ] ;
}
}
@ -545,14 +545,14 @@ public final class DfsBlockCache {
}
}
static final class Ref < T > {
static final class Ref < T > {
final DfsPack Key pack ;
final DfsStream Key pack ;
final long position ;
final long position ;
final int size ;
final int size ;
volatile T value ;
volatile T value ;
Ref next ;
Ref next ;
volatile boolean hot ;
volatile boolean hot ;
Ref ( DfsPack Key pack , long position , int size , T v ) {
Ref ( DfsStream Key pack , long position , int size , T v ) {
this . pack = pack ;
this . pack = pack ;
this . position = position ;
this . position = position ;
this . size = size ;
this . size = size ;