@ -89,6 +89,7 @@ import org.eclipse.jgit.util.LongList;
* /
public final class DfsPackFile extends BlockBasedFile {
private static final int REC_SIZE = Constants . OBJECT_ID_LENGTH + 8 ;
private static final long REF_POSITION = 0 ;
/ * *
* Lock for initialization of { @link # index } and { @link # corruptObjects } .
@ -194,45 +195,10 @@ public final class DfsPackFile extends BlockBasedFile {
try {
DfsStreamKey idxKey = desc . getStreamKey ( INDEX ) ;
DfsBlockCache . Ref < PackIndex > idxref = cache . getOrLoadRef ( idxKey ,
( ) - > {
try {
ctx . stats . readIdx + + ;
long start = System . nanoTime ( ) ;
try ( ReadableChannel rc = ctx . db . openFile ( desc ,
INDEX ) ) {
InputStream in = Channels
. newInputStream ( rc ) ;
int wantSize = 8192 ;
int bs = rc . blockSize ( ) ;
if ( 0 < bs & & bs < wantSize ) {
bs = ( wantSize / bs ) * bs ;
} else if ( bs < = 0 ) {
bs = wantSize ;
}
PackIndex idx = PackIndex . read (
new BufferedInputStream ( in , bs ) ) ;
int sz = ( int ) Math . min (
idx . getObjectCount ( ) * REC_SIZE ,
Integer . MAX_VALUE ) ;
ctx . stats . readIdxBytes + = rc . position ( ) ;
index = idx ;
return new DfsBlockCache . Ref < > ( idxKey , 0 ,
sz , idx ) ;
} finally {
ctx . stats . readIdxMicros + = elapsedMicros (
start ) ;
}
} catch ( EOFException e ) {
throw new IOException ( MessageFormat . format (
DfsText . get ( ) . shortReadOfIndex ,
desc . getFileName ( INDEX ) ) , e ) ;
} catch ( IOException e ) {
throw new IOException ( MessageFormat . format (
DfsText . get ( ) . cannotReadIndex ,
desc . getFileName ( INDEX ) ) , e ) ;
}
} ) ;
DfsBlockCache . Ref < PackIndex > idxref = cache . getOrLoadRef (
idxKey ,
REF_POSITION ,
( ) - > loadPackIndex ( ctx , idxKey ) ) ;
PackIndex idx = idxref . get ( ) ;
if ( index = = null & & idx ! = null ) {
index = idx ;
@ -267,44 +233,10 @@ public final class DfsPackFile extends BlockBasedFile {
PackIndex idx = idx ( ctx ) ;
PackReverseIndex revidx = getReverseIdx ( ctx ) ;
DfsStreamKey bitmapKey = desc . getStreamKey ( BITMAP_INDEX ) ;
DfsBlockCache . Ref < PackBitmapIndex > idxref = cache
. getOrLoadRef ( bitmapKey , ( ) - > {
ctx . stats . readBitmap + + ;
long start = System . nanoTime ( ) ;
try ( ReadableChannel rc = ctx . db . openFile ( desc ,
BITMAP_INDEX ) ) {
long size ;
PackBitmapIndex bmidx ;
try {
InputStream in = Channels . newInputStream ( rc ) ;
int wantSize = 8192 ;
int bs = rc . blockSize ( ) ;
if ( 0 < bs & & bs < wantSize ) {
bs = ( wantSize / bs ) * bs ;
} else if ( bs < = 0 ) {
bs = wantSize ;
}
in = new BufferedInputStream ( in , bs ) ;
bmidx = PackBitmapIndex . read ( in , idx , revidx ) ;
} finally {
size = rc . position ( ) ;
ctx . stats . readIdxBytes + = size ;
ctx . stats . readIdxMicros + = elapsedMicros ( start ) ;
}
int sz = ( int ) Math . min ( size , Integer . MAX_VALUE ) ;
bitmapIndex = bmidx ;
return new DfsBlockCache . Ref < > ( bitmapKey , 0 , sz ,
bmidx ) ;
} catch ( EOFException e ) {
throw new IOException ( MessageFormat . format (
DfsText . get ( ) . shortReadOfIndex ,
desc . getFileName ( BITMAP_INDEX ) ) , e ) ;
} catch ( IOException e ) {
throw new IOException ( MessageFormat . format (
DfsText . get ( ) . cannotReadIndex ,
desc . getFileName ( BITMAP_INDEX ) ) , e ) ;
}
} ) ;
DfsBlockCache . Ref < PackBitmapIndex > idxref = cache . getOrLoadRef (
bitmapKey ,
REF_POSITION ,
( ) - > loadBitmapIndex ( ctx , bitmapKey , idx , revidx ) ) ;
PackBitmapIndex bmidx = idxref . get ( ) ;
if ( bitmapIndex = = null & & bmidx ! = null ) {
bitmapIndex = bmidx ;
@ -326,14 +258,10 @@ public final class DfsPackFile extends BlockBasedFile {
PackIndex idx = idx ( ctx ) ;
DfsStreamKey revKey = new DfsStreamKey . ForReverseIndex (
desc . getStreamKey ( INDEX ) ) ;
DfsBlockCache . Ref < PackReverseIndex > revref = cache
. getOrLoadRef ( revKey , ( ) - > {
PackReverseIndex revidx = new PackReverseIndex ( idx ) ;
int sz = ( int ) Math . min ( idx . getObjectCount ( ) * 8 ,
Integer . MAX_VALUE ) ;
reverseIndex = revidx ;
return new DfsBlockCache . Ref < > ( revKey , 0 , sz , revidx ) ;
} ) ;
DfsBlockCache . Ref < PackReverseIndex > revref = cache . getOrLoadRef (
revKey ,
REF_POSITION ,
( ) - > loadReverseIdx ( ctx , revKey , idx ) ) ;
PackReverseIndex revidx = revref . get ( ) ;
if ( reverseIndex = = null & & revidx ! = null ) {
reverseIndex = revidx ;
@ -1091,4 +1019,91 @@ public final class DfsPackFile extends BlockBasedFile {
list . add ( offset ) ;
}
}
private DfsBlockCache . Ref < PackIndex > loadPackIndex (
DfsReader ctx , DfsStreamKey idxKey ) throws IOException {
try {
ctx . stats . readIdx + + ;
long start = System . nanoTime ( ) ;
try ( ReadableChannel rc = ctx . db . openFile ( desc , INDEX ) ) {
InputStream in = Channels . newInputStream ( rc ) ;
int wantSize = 8192 ;
int bs = rc . blockSize ( ) ;
if ( 0 < bs & & bs < wantSize ) {
bs = ( wantSize / bs ) * bs ;
} else if ( bs < = 0 ) {
bs = wantSize ;
}
PackIndex idx = PackIndex . read ( new BufferedInputStream ( in , bs ) ) ;
ctx . stats . readIdxBytes + = rc . position ( ) ;
index = idx ;
return new DfsBlockCache . Ref < > (
idxKey ,
REF_POSITION ,
idx . getObjectCount ( ) * REC_SIZE ,
idx ) ;
} finally {
ctx . stats . readIdxMicros + = elapsedMicros ( start ) ;
}
} catch ( EOFException e ) {
throw new IOException ( MessageFormat . format (
DfsText . get ( ) . shortReadOfIndex ,
desc . getFileName ( INDEX ) ) , e ) ;
} catch ( IOException e ) {
throw new IOException ( MessageFormat . format (
DfsText . get ( ) . cannotReadIndex ,
desc . getFileName ( INDEX ) ) , e ) ;
}
}
private DfsBlockCache . Ref < PackReverseIndex > loadReverseIdx (
DfsReader ctx , DfsStreamKey revKey , PackIndex idx ) {
PackReverseIndex revidx = new PackReverseIndex ( idx ) ;
reverseIndex = revidx ;
return new DfsBlockCache . Ref < > (
revKey ,
REF_POSITION ,
idx . getObjectCount ( ) * 8 ,
revidx ) ;
}
private DfsBlockCache . Ref < PackBitmapIndex > loadBitmapIndex (
DfsReader ctx ,
DfsStreamKey bitmapKey ,
PackIndex idx ,
PackReverseIndex revidx ) throws IOException {
ctx . stats . readBitmap + + ;
long start = System . nanoTime ( ) ;
try ( ReadableChannel rc = ctx . db . openFile ( desc , BITMAP_INDEX ) ) {
long size ;
PackBitmapIndex bmidx ;
try {
InputStream in = Channels . newInputStream ( rc ) ;
int wantSize = 8192 ;
int bs = rc . blockSize ( ) ;
if ( 0 < bs & & bs < wantSize ) {
bs = ( wantSize / bs ) * bs ;
} else if ( bs < = 0 ) {
bs = wantSize ;
}
in = new BufferedInputStream ( in , bs ) ;
bmidx = PackBitmapIndex . read ( in , idx , revidx ) ;
} finally {
size = rc . position ( ) ;
ctx . stats . readIdxBytes + = size ;
ctx . stats . readIdxMicros + = elapsedMicros ( start ) ;
}
bitmapIndex = bmidx ;
return new DfsBlockCache . Ref < > (
bitmapKey , REF_POSITION , size , bmidx ) ;
} catch ( EOFException e ) {
throw new IOException ( MessageFormat . format (
DfsText . get ( ) . shortReadOfIndex ,
desc . getFileName ( BITMAP_INDEX ) ) , e ) ;
} catch ( IOException e ) {
throw new IOException ( MessageFormat . format (
DfsText . get ( ) . cannotReadIndex ,
desc . getFileName ( BITMAP_INDEX ) ) , e ) ;
}
}
}