@ -58,7 +58,7 @@ public class HeapReader {
//public final static long keepFreeMem = 20 * 1024 * 1024;
private final static ConcurrentLog log = new ConcurrentLog ( " HeapReader ") ;
private final static ConcurrentLog log = new ConcurrentLog ( " KELONDRO ") ;
// input values
protected int keylength ; // the length of the primary key
@ -107,10 +107,10 @@ public class HeapReader {
}
}
if ( ! ok ) {
log . warn ( " verification of idx file for " + heapFile . toString ( ) + " failed, re-building index" ) ;
log . warn ( " HeapReader: verification of idx file for " + heapFile . toString ( ) + " failed, re-building index" ) ;
initIndexReadFromHeap ( ) ;
} else {
log . info ( " using a dump of the index of " + heapFile . toString ( ) + "." ) ;
log . info ( " HeapReader: using a dump of the index of " + heapFile . toString ( ) + "." ) ;
}
} else {
// if we did not have a dump, create a new index
@ -161,7 +161,7 @@ public class HeapReader {
// if this is successful, return true; otherwise false
String fingerprint = fingerprintFileHash ( this . heapFile ) ;
if ( fingerprint = = null ) {
log . severe ( " cannot generate a fingerprint for " + this . heapFile + ": null" ) ;
log . severe ( " HeapReader: cannot generate a fingerprint for " + this . heapFile + ": null" ) ;
return false ;
}
this . fingerprintFileIdx = HeapWriter . fingerprintIndexFile ( this . heapFile , fingerprint ) ;
@ -188,7 +188,7 @@ public class HeapReader {
// check saturation
if ( this . index instanceof RowHandleMap ) {
int [ ] saturation = ( ( RowHandleMap ) this . index ) . saturation ( ) ; // {<the maximum length of consecutive equal-beginning bytes in the key>, <the minimum number of leading zeros in the second column>}
log . info ( " saturation of " + this . fingerprintFileIdx . getName ( ) + ": keylength = " + saturation [ 0 ] + ", vallength = " + saturation [ 1 ] + ", size = " + this . index . size ( ) +
log . info ( " HeapReader: saturation of " + this . fingerprintFileIdx . getName ( ) + ": keylength = " + saturation [ 0 ] + ", vallength = " + saturation [ 1 ] + ", size = " + this . index . size ( ) +
", maximum saving for index-compression = " + ( saturation [ 0 ] * this . index . size ( ) / 1024 / 1024 ) + " MB" +
", exact saving for value-compression = " + ( saturation [ 1 ] * this . index . size ( ) / 1024 / 1024 ) + " MB" ) ;
}
@ -249,7 +249,7 @@ public class HeapReader {
private void initIndexReadFromHeap ( ) throws IOException {
// this initializes the this.index object by reading positions from the heap file
log . info ( " generating index for " + this . heapFile . toString ( ) + ", " + ( this . file . length ( ) / 1024 / 1024 ) + " MB. Please wait." ) ;
log . info ( " HeapReader: generating index for " + this . heapFile . toString ( ) + ", " + ( this . file . length ( ) / 1024 / 1024 ) + " MB. Please wait." ) ;
this . free = new Gap ( ) ;
RowHandleMap . initDataConsumer indexready = RowHandleMap . asynchronusInitializer ( this . name ( ) + ".initializer" , this . keylength , this . ordering , 8 , Math . max ( 10 , ( int ) ( Runtime . getRuntime ( ) . freeMemory ( ) / ( 10 * 1024 * 1024 ) ) ) ) ;
@ -268,7 +268,7 @@ public class HeapReader {
//assert reclen > 0 : " reclen == 0 at seek pos " + seek;
if ( reclen = = 0 ) {
// very bad file inconsistency
log . severe ( " reclen == 0 at seek pos " + seek + " in file " + this . heapFile ) ;
log . severe ( " HeapReader: reclen == 0 at seek pos " + seek + " in file " + this . heapFile ) ;
this . file . setLength ( seek ) ; // delete everything else at the remaining of the file :-(
break loop ;
}
@ -295,7 +295,7 @@ public class HeapReader {
this . file . seek ( seek + 4 ) ;
Arrays . fill ( key , ( byte ) 0 ) ;
this . file . write ( key ) ; // mark the place as empty record
log . warn ( " BLOB " + this . heapFile . getName ( ) + ": skiped not wellformed key " + UTF8 . String ( key ) + " at seek pos " + seek ) ;
log . warn ( " HeapReader: BLOB " + this . heapFile . getName ( ) + ": skiped not wellformed key " + UTF8 . String ( key ) + " at seek pos " + seek ) ;
}
}
// new seek position
@ -312,7 +312,7 @@ public class HeapReader {
} catch ( final ExecutionException e ) {
ConcurrentLog . logException ( e ) ;
}
log . info ( " finished index generation for " + this . heapFile . toString ( ) + ", " + this . index . size ( ) + " entries, " + this . free . size ( ) + " gaps." ) ;
log . info ( " HeapReader: finished index generation for " + this . heapFile . toString ( ) + ", " + this . index . size ( ) + " entries, " + this . free . size ( ) + " gaps." ) ;
}
private void mergeFreeEntries ( ) throws IOException {
@ -340,7 +340,7 @@ public class HeapReader {
lastFree = nextFree ;
}
}
log . info ( " BLOB " + this . heapFile . toString ( ) + ": merged " + merged + " free records" ) ;
log . info ( " HeapReader: BLOB " + this . heapFile . toString ( ) + ": merged " + merged + " free records" ) ;
if ( merged > 0 ) deleteFingerprint ( ) ;
}
}
@ -360,7 +360,7 @@ public class HeapReader {
public int size ( ) {
assert ( this . index ! = null ) : "index == null; closeDate=" + this . closeDate + ", now=" + new Date ( ) ;
if ( this . index = = null ) {
log . severe ( " this.index == null in size(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
log . severe ( " HeapReader: this.index == null in size(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
return 0 ;
}
return ( this . index = = null ) ? 0 : this . index . size ( ) ;
@ -369,7 +369,7 @@ public class HeapReader {
public boolean isEmpty ( ) {
assert ( this . index ! = null ) : "index == null; closeDate=" + this . closeDate + ", now=" + new Date ( ) ;
if ( this . index = = null ) {
log . severe ( " this.index == null in isEmpty(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
log . severe ( " HeapReader: this.index == null in isEmpty(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
return true ;
}
return this . index . isEmpty ( ) ;
@ -383,7 +383,7 @@ public class HeapReader {
public boolean containsKey ( byte [ ] key ) {
assert ( this . index ! = null ) : "index == null; closeDate=" + this . closeDate + ", now=" + new Date ( ) ;
if ( this . index = = null ) {
log . severe ( " this.index == null in containsKey(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
log . severe ( " HeapReader: this.index == null in containsKey(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
return false ;
}
key = normalizeKey ( key ) ;
@ -408,7 +408,7 @@ public class HeapReader {
protected synchronized byte [ ] firstKey ( ) throws IOException {
assert ( this . index ! = null ) : "index == null; closeDate=" + this . closeDate + ", now=" + new Date ( ) ;
if ( this . index = = null ) {
log . severe ( " this.index == null in firstKey(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
log . severe ( " HeapReader: this.index == null in firstKey(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
return null ;
}
synchronized ( this . index ) {
@ -426,7 +426,7 @@ public class HeapReader {
protected byte [ ] first ( ) throws IOException , SpaceExceededException {
assert ( this . index ! = null ) : "index == null; closeDate=" + this . closeDate + ", now=" + new Date ( ) ;
if ( this . index = = null ) {
log . severe ( " this.index == null in first(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
log . severe ( " HeapReader: this.index == null in first(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
return null ;
}
synchronized ( this . index ) {
@ -446,7 +446,7 @@ public class HeapReader {
protected byte [ ] lastKey ( ) throws IOException {
assert ( this . index ! = null ) : "index == null; closeDate=" + this . closeDate + ", now=" + new Date ( ) ;
if ( this . index = = null ) {
log . severe ( " this.index == null in lastKey(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
log . severe ( " HeapReader: this.index == null in lastKey(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
return null ;
}
if ( this . index = = null ) return null ;
@ -465,7 +465,7 @@ public class HeapReader {
protected byte [ ] last ( ) throws IOException , SpaceExceededException {
assert ( this . index ! = null ) : "index == null; closeDate=" + this . closeDate + ", now=" + new Date ( ) ;
if ( this . index = = null ) {
log . severe ( " this.index == null in last(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
log . severe ( " HeapReader: this.index == null in last(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
return null ;
}
synchronized ( this . index ) {
@ -484,7 +484,7 @@ public class HeapReader {
public byte [ ] get ( byte [ ] key ) throws IOException , SpaceExceededException {
assert ( this . index ! = null ) : "index == null; closeDate=" + this . closeDate + ", now=" + new Date ( ) ;
if ( this . index = = null ) {
log . severe ( " this.index == null in get(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
log . severe ( " HeapReader: this.index == null in get(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
return null ;
}
key = normalizeKey ( key ) ;
@ -499,7 +499,7 @@ public class HeapReader {
final int len = this . file . readInt ( ) - this . keylength ;
if ( len < 0 ) {
// database file may be corrupted and should be deleted :-((
log . severe ( " file " + this . file . file ( ) + " corrupted at " + pos + ": negative len. len = " + len + ", pk.len = " + this . keylength ) ;
log . severe ( " HeapReader: file " + this . file . file ( ) + " corrupted at " + pos + ": negative len. len = " + len + ", pk.len = " + this . keylength ) ;
// to get lazy over that problem (who wants to tell the user to stop operation and delete the file???) we work on like the entry does not exist
this . index . remove ( key ) ;
return null ;
@ -519,7 +519,7 @@ public class HeapReader {
this . file . readFully ( keyf , 0 , keyf . length ) ;
if ( ! this . ordering . equal ( key , keyf ) ) {
// verification of the indexed access failed. we must re-read the index
log . severe ( " indexed verification access failed for " + this . heapFile . toString ( ) ) ;
log . severe ( " HeapReader: indexed verification access failed for " + this . heapFile . toString ( ) ) ;
// this is a severe operation, it should never happen.
// remove entry from index because keeping that element in the index would not make sense
this . index . remove ( key ) ;
@ -581,7 +581,7 @@ public class HeapReader {
public long length ( byte [ ] key ) throws IOException {
assert ( this . index ! = null ) : "index == null; closeDate=" + this . closeDate + ", now=" + new Date ( ) ;
if ( this . index = = null ) {
log . severe ( " this.index == null in length(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
log . severe ( " HeapReader: this.index == null in length(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
return 0 ;
}
key = normalizeKey ( key ) ;
@ -617,17 +617,17 @@ public class HeapReader {
try {
String fingerprint = fingerprintFileHash ( this . heapFile ) ;
if ( fingerprint = = null ) {
log . severe ( " cannot write a dump for " + this . heapFile . getName ( ) + ": fingerprint is null" ) ;
log . severe ( " HeapReader: cannot write a dump for " + this . heapFile . getName ( ) + ": fingerprint is null" ) ;
} else {
File newFingerprintFileGap = HeapWriter . fingerprintGapFile ( this . heapFile , fingerprint ) ;
if ( this . fingerprintFileGap ! = null & &
this . fingerprintFileGap . getName ( ) . equals ( newFingerprintFileGap . getName ( ) ) & &
this . fingerprintFileGap . exists ( ) ) {
log . info ( " using existing gap dump instead of writing a new one: " + this . fingerprintFileGap . getName ( ) ) ;
log . info ( " HeapReader: using existing gap dump instead of writing a new one: " + this . fingerprintFileGap . getName ( ) ) ;
} else {
long start = System . currentTimeMillis ( ) ;
this . free . dump ( newFingerprintFileGap ) ;
log . info ( " wrote a dump for the " + this . free . size ( ) + " gap entries of " + this . heapFile . getName ( ) + " in " + ( System . currentTimeMillis ( ) - start ) + " milliseconds." ) ;
log . info ( " HeapReader: wrote a dump for the " + this . free . size ( ) + " gap entries of " + this . heapFile . getName ( ) + " in " + ( System . currentTimeMillis ( ) - start ) + " milliseconds." ) ;
}
}
this . free . clear ( ) ;
@ -637,11 +637,11 @@ public class HeapReader {
if ( this . fingerprintFileIdx ! = null & &
this . fingerprintFileIdx . getName ( ) . equals ( newFingerprintFileIdx . getName ( ) ) & &
this . fingerprintFileIdx . exists ( ) ) {
log . info ( " using existing idx dump instead of writing a new one: " + this . fingerprintFileIdx . getName ( ) ) ;
log . info ( " HeapReader: using existing idx dump instead of writing a new one: " + this . fingerprintFileIdx . getName ( ) ) ;
} else {
long start = System . currentTimeMillis ( ) ;
this . index . dump ( newFingerprintFileIdx ) ;
log . info ( " wrote a dump for the " + this . index . size ( ) + " index entries of " + this . heapFile . getName ( ) + " in " + ( System . currentTimeMillis ( ) - start ) + " milliseconds." ) ;
log . info ( " HeapReader: wrote a dump for the " + this . index . size ( ) + " index entries of " + this . heapFile . getName ( ) + " in " + ( System . currentTimeMillis ( ) - start ) + " milliseconds." ) ;
}
}
this . index . close ( ) ;
@ -656,7 +656,9 @@ public class HeapReader {
this . index = null ;
this . closeDate = new Date ( ) ;
} catch ( Throwable e ) { ConcurrentLog . logException ( e ) ; }
log . info ( "close HeapFile " + this . heapFile . getName ( ) + "; trace: " + ConcurrentLog . stackTrace ( ) ) ;
log . info ( "HeapReader: close HeapFile " + this . heapFile . getName ( ) ) ;
log . fine ( "trace: " + ConcurrentLog . stackTrace ( ) ) ;
}
}
@ -681,7 +683,7 @@ public class HeapReader {
* /
public CloneableIterator < byte [ ] > keys ( final boolean up , final boolean rotating ) throws IOException {
if ( this . index = = null ) {
log . severe ( " this.index == null in keys(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
log . severe ( " HeapReader: this.index == null in keys(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
return null ;
}
synchronized ( this . index ) {
@ -699,7 +701,7 @@ public class HeapReader {
public CloneableIterator < byte [ ] > keys ( final boolean up , final byte [ ] firstKey ) throws IOException {
assert ( this . index ! = null ) : "index == null; closeDate=" + this . closeDate + ", now=" + new Date ( ) ;
if ( this . index = = null ) {
log . severe ( " this.index == null in keys(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
log . severe ( " HeapReader: this.index == null in keys(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
return null ;
}
synchronized ( this . index ) {
@ -710,7 +712,7 @@ public class HeapReader {
public long length ( ) {
assert ( this . index ! = null ) : "index == null; closeDate=" + this . closeDate + ", now=" + new Date ( ) ;
if ( this . index = = null ) {
log . severe ( " this.index == null in length(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
log . severe ( " HeapReader: this.index == null in length(); closeDate=" + this . closeDate + ", now=" + new Date ( ) + this . heapFile = = null ? "" : ( " file = " + this . heapFile . toString ( ) ) ) ;
return 0 ;
}
synchronized ( this . index ) {
@ -780,7 +782,7 @@ public class HeapReader {
// read some more bytes to consume the empty record
if ( len > 1 ) {
if ( len - 1 ! = this . is . skipBytes ( len - 1 ) ) { // all that is remaining
log . warn ( " problem skiping " + + len + " bytes in " + this . blobFile . getName ( ) ) ;
log . warn ( " HeapReader: problem skiping " + + len + " bytes in " + this . blobFile . getName ( ) ) ;
try { this . is . close ( ) ; } catch ( final IOException e ) { }
return null ;
}
@ -811,7 +813,7 @@ public class HeapReader {
// the allocation of memory for the payload may fail
// this is bad because we must interrupt the iteration here but the
// process that uses the iteration may think that the iteraton has just been completed
log . severe ( " out of memory in LookAheadIterator.next0 for file " + this . blobFile . toString ( ) , ee ) ;
log . severe ( " HeapReader: out of memory in LookAheadIterator.next0 for file " + this . blobFile . toString ( ) , ee ) ;
try { this . is . close ( ) ; } catch ( final IOException e ) { }
return null ;
}