@@ -25,10 +25,7 @@ this software and associated documentation files (the "Software"), to deal in
2525package su .interference .core ;
2626
2727import su .interference .exception .*;
28- import su .interference .persistent .Table ;
29- import su .interference .persistent .FrameData ;
30- import su .interference .persistent .Session ;
31- import su .interference .persistent .UndoChunk ;
28+ import su .interference .persistent .*;
3229import su .interference .serialize .ByteString ;
3330
3431import java .util .*;
@@ -127,6 +124,42 @@ public IndexFrame(byte[] b, int file, long pointer, Map<Long, Long> imap, Map<Lo
127124 this .b = null ; //throw bytes to GC
128125 }
129126
127+ @ Override
128+ public synchronized void rollbackTransaction (Transaction tran , ArrayList <FrameData > ubs , Session s ) throws Exception {
129+ data .check ();
130+ final Map <Integer , DataChunk > ucmap = new HashMap ();
131+
132+ if (ubs !=null ) {
133+ for (FrameData ub : ubs ) {
134+ for (Chunk c : ub .getDataFrame ().getChunks ()) {
135+ final UndoChunk uc = (UndoChunk ) c .getEntity ();
136+ final int ucfile = uc .getDataChunk ().getHeader ().getRowID ().getFileId ();
137+ final long frameptr = uc .getDataChunk ().getHeader ().getRowID ().getFramePointer ();
138+ if (uc .getTransId () == tran .getTransId () && ucfile == this .getFile () && frameptr == this .getPointer ()) {
139+ ucmap .put (uc .getPtr (), uc .getDataChunk ());
140+ }
141+ }
142+ }
143+ }
144+
145+ //rollback modified index records
146+ for (Chunk c : data .getChunks ()) {
147+ if (c .getHeader ().getTran ().getTransId () == tran .getTransId ()) {
148+ final DataChunk dc = ucmap .get (c .getHeader ().getPtr ());
149+ final DataChunk dc_ = ((IndexChunk ) c .getEntity ()).getDataChunk ().getUndoChunk ().getDataChunk ();
150+ ((DataChunk ) c ).setUndoChunk (null );
151+ ((DataChunk ) c ).cleanUpIcs ();
152+ ((IndexChunk )c .getEntity ()).setDataChunk (dc_ );
153+ ((IndexChunk )c .getEntity ()).setFramePtrRowId (dc_ .getHeader ().getRowID ());
154+ ((DataChunk )c ).getHeader ().setFramePtr (dc_ .getHeader ().getRowID ());
155+ }
156+ }
157+
158+ final LLT llt = LLT .getLLT ();
159+ llt .add (this );
160+ llt .commit ();
161+ }
162+
130163 public void cleanICEntities () {
131164 for (Chunk c : this .data .getChunks ()) {
132165 final Object e = ((DataChunk ) c ).getExistingEntity ();
@@ -136,11 +169,12 @@ public void cleanICEntities() {
136169 }
137170 }
138171
139- public synchronized IndexFrame add (DataChunk e , Table t , Session s , LLT llt ) throws Exception {
172+ public synchronized FrameData add (DataChunk e , Table t , Session s , LLT llt ) throws Exception {
140173 if (this .isFill (e )) {
141174
142175 final int nfileId = t .getIndexFileId (this .getFrameData ());
143- final IndexFrame res = t .createNewFrame (this .getFrameData (), null , nfileId , this .getType (), 0 , false , false , false , s , llt ).getIndexFrame ();
176+ final FrameData res_ = t .createNewFrame (this .getFrameData (), null , nfileId , this .getType (), 0 , false , false , false , s , llt );
177+ final IndexFrame res = res_ .getIndexFrame ();
144178 //paranoid fix
145179 llt .add (res );
146180 llt .add (this );
@@ -182,7 +216,7 @@ public synchronized IndexFrame add (DataChunk e, Table t, Session s, LLT llt) th
182216 for (int i =0 ; i <this .data .size (); i ++) {
183217 if (!norpt ) {
184218 if (pkey !=null ) {
185- if ((( DataChunk ) this .data .get (i ) ).getDcs ().compareTo (pkey )==0 ) {
219+ if (this .data .get (i ).getDcs ().compareTo (pkey )==0 ) {
186220 keyrpt = true ;
187221 }
188222 } else {
@@ -192,15 +226,15 @@ public synchronized IndexFrame add (DataChunk e, Table t, Session s, LLT llt) th
192226 if (i ==this .data .size ()-1 ) {
193227 keyrpt = false ;
194228 }
195- if (this .getFrameSize ()-resamt >this .data .get (i ).getBytesAmount ()&&(keyrpt ||(( DataChunk ) this .data .get (i ) ).getDcs ().compareTo (max2 )<0 )) {
229+ if (this .getFrameSize ()-resamt >this .data .get (i ).getBytesAmount ()&&(keyrpt ||this .data .get (i ).getDcs ().compareTo (max2 )<0 )) {
196230 res .insertChunk (this .data .get (i ), s , false , true , llt );
197231 resamt = resamt + this .data .get (i ).getBytesAmount ();
198232 res .setHasMV (1 );
199233 } else {
200234 norpt = true ;
201235 nlist .add ((DataChunk )this .data .get (i ));
202236 }
203- pkey = (( DataChunk ) this .data .get (i ) ).getDcs ();
237+ pkey = this .data .get (i ).getDcs ();
204238 keyrpt = false ;
205239 }
206240 this .data .clear ();
@@ -209,7 +243,7 @@ public synchronized IndexFrame add (DataChunk e, Table t, Session s, LLT llt) th
209243 }
210244 }
211245 }
212- return res ;
246+ return res_ ;
213247 } else {
214248 this .insertChunk (e , s , false , llt );
215249 return null ;
0 commit comments