@@ -24,6 +24,8 @@ this software and associated documentation files (the "Software"), to deal in
2424
2525package su .interference .core ;
2626
27+ import org .slf4j .Logger ;
28+ import org .slf4j .LoggerFactory ;
2729import su .interference .exception .*;
2830import su .interference .persistent .*;
2931import su .interference .serialize .ByteString ;
@@ -36,22 +38,32 @@ this software and associated documentation files (the "Software"), to deal in
3638 */
3739
3840public class IndexFrame extends Frame {
41+ private final static Logger logger = LoggerFactory .getLogger (IndexFrame .class );
3942 private boolean sorted = false ;
43+ private final boolean terminate ;
4044 public static final int INDEX_FRAME_NODE = 2 ;
4145 public static final int INDEX_FRAME_LEAF = 1 ;
4246 public static final int INITIALIZE_DURING_CONSTRUCT = 1 ;
4347
4448 public IndexFrame (int file , long pointer , int size , int objectId , Table t ) throws InternalException {
4549 super (file , pointer , size , t );
50+ this .terminate = false ;
4651 }
4752
4853 public IndexFrame (FrameData bd , int frameType , Table t ) throws InternalException {
4954 super (bd , t );
5055 this .setType (frameType );
56+ this .terminate = false ;
57+ }
58+
59+ public IndexFrame () {
60+ super (0 , 0 , 0 , null );
61+ this .terminate = true ;
5162 }
5263
5364 public IndexFrame (int file , long pointer , int size , FrameData bd , Table t , Class c , List <FrameData > uframes ) throws Exception {
5465 super (null , file , pointer , size , bd , t , c );
66+ this .terminate = false ;
5567
5668 Map <Integer , UndoChunk > ucs = new HashMap <>();
5769 for (FrameData uframe : uframes ) {
@@ -97,6 +109,7 @@ public IndexFrame(int file, long pointer, int size, FrameData bd, Table t, Class
97109 public IndexFrame (byte [] b , int file , long pointer , Map <Long , Long > imap , Map <Long , Long > hmap , Table t ) {
98110 super (b , file , pointer , t );
99111 int ptr = FRAME_HEADER_SIZE ;
112+ this .terminate = false ;
100113
101114 final ByteString bs = new ByteString (this .b );
102115 while (ptr <this .b .length ) {
@@ -107,8 +120,9 @@ public IndexFrame(byte[] b, int file, long pointer, Map<Long, Long> imap, Map<Lo
107120 if (h .getFramePtr () > 0 ) { //IOT does not contains frameptr
108121 final long allocId = imap .get (h .getFramePtr ());
109122 final long bptr = hmap .get (allocId ) != null ? hmap .get (allocId ) : Instance .getInstance ().getFrameByAllocId (allocId ).getFrameId ();
110- h .getFramePtrRowId ().setFileId ((int ) bptr % 4096 );
111- h .getFramePtrRowId ().setFramePointer (bptr - (bptr % 4096 ));
123+ final long fbptr = bptr %4096 ;
124+ h .getFramePtrRowId ().setFileId ((int ) fbptr );
125+ h .getFramePtrRowId ().setFramePointer (bptr - fbptr );
112126 }
113127 final DataChunk dc = new DataChunk (bs .substring (ptr , ptr +INDEX_HEADER_SIZE +h .getLen ()), this .getFile (), this .getPointer (), INDEX_HEADER_SIZE , this .getDataObject (), this .getEntityClass ());
114128 dc .setHeader (h );
@@ -402,11 +416,16 @@ public synchronized ValueSet getMaxValue() throws InternalException {
402416 }
403417
404418 public HashMap <Long , Long > getAllocateMap () {
405- final HashMap <Long , Long > imap = new HashMap <Long , Long >();
419+ final HashMap <Long , Long > imap = new HashMap <>();
406420 for (Chunk c : data .getChunks ()) {
407421 if (c .getHeader ().getFramePtr () > 0 ) { //IOT does not contains frameptr
408- final long allocId = Instance .getInstance ().getFrameById (c .getHeader ().getFramePtr ()).getAllocId ();
409- imap .put (c .getHeader ().getFramePtr (), allocId );
422+ final FrameData bd = Instance .getInstance ().getFrameById (c .getHeader ().getFramePtr ());
423+ if (bd != null ) {
424+ final long allocId = bd .getAllocId ();
425+ imap .put (c .getHeader ().getFramePtr (), allocId );
426+ } else {
427+ logger .error ("getAllocaleMap found null data frame for frame id " + c .getHeader ().getFramePtr ());
428+ }
410429 }
411430 }
412431 return imap ;
@@ -461,4 +480,8 @@ public synchronized void setLcId(long lcId) {
461480 this .setRes05 ((int )lcF );
462481 this .setRes07 (lcId - lcF );
463482 }
483+
484+ public boolean isTerminate () {
485+ return terminate ;
486+ }
464487}
0 commit comments