@@ -1099,6 +1099,38 @@ public void usedSpace (final FrameData bd, final int used, final boolean persist
10991099 }
11001100 }
11011101
1102+ protected synchronized void freeFrames (List <Long > flist , Session s , Transaction tran , String cause ) throws Exception {
1103+ for (Long frameId : flist ) {
1104+ final FrameData cb = Instance .getInstance ().getFrameById (frameId );
1105+ logger .info ("freeing frame " + cb .getFile () + " " + cb .getPtr () + " by " + cause + " of " + tran .getTransId ());
1106+ if (cb .getUsed () > 0 ) {
1107+ throw new InternalException ();
1108+ }
1109+ if (!this .checkLBS (cb )) { //LB can't deallocated!!! May be empty
1110+ //check for other transactions, which locked this frame
1111+ if (!cb .isFrameBusy ()) {
1112+ final FreeFrame fb = new FreeFrame (0 , cb .getFrameId (), cb .getSize ());
1113+ final FrameData pb = cb .getPrevFrameId () > 0 ? Instance .getInstance ().getFrameById (cb .getPrevFrameId ()) : null ;
1114+ final FrameData nb = Instance .getInstance ().getFrameById (cb .getNextFrameId ());
1115+ if (nb != null ) {
1116+ nb .setPrevFile (pb == null ? 0 : pb .getFile ());
1117+ nb .setPrevFrame (pb == null ? 0 : pb .getPtr ());
1118+ s .persist (nb ); //update
1119+ }
1120+ if (pb != null ) {
1121+ pb .setNextFile (nb .getFile ());
1122+ pb .setNextFrame (nb .getPtr ());
1123+ s .persist (pb ); //update
1124+ }
1125+ s .persist (fb ); //insert
1126+ s .delete (cb );
1127+ this .decFrameAmount ();
1128+ s .persist (this );
1129+ }
1130+ }
1131+ }
1132+ }
1133+
11021134 private WaitFrame getAvailableFrame (final Object o , final boolean fpart ) throws ClassNotFoundException , InstantiationException , InternalException , IllegalAccessException {
11031135 Metrics .get ("getAvailableFrame" ).start ();
11041136 final long st = System .currentTimeMillis ();
@@ -1157,6 +1189,7 @@ public synchronized DataChunk persist (final Object o, final Session s) throws E
11571189 }
11581190
11591191 protected DataChunk persist (final Object o , final Session s , final LLT extllt ) throws Exception {
1192+ final boolean ignoreNoLocal = false ;
11601193 final Class cc = o .getClass ();
11611194 boolean fpart = false ;
11621195
@@ -1307,10 +1340,16 @@ protected DataChunk persist (final Object o, final Session s, final LLT extllt)
13071340 return nc ;
13081341
13091342 } else {
1343+ final FrameData bd = Instance .getInstance ().getFrameById (dc .getHeader ().getRowID ().getFileId ()+dc .getHeader ().getRowID ().getFramePointer ());
1344+
1345+ if (!bd .getFrame ().isLocal ()) {
1346+ if (!ignoreNoLocal ) {
1347+ throw new CannotAccessToForeignRecord ();
1348+ }
1349+ }
13101350
13111351 final DataChunk udc = dc .lock (s , llt );
13121352 final int len = dc .getBytesAmount ();
1313- final FrameData bd = Instance .getInstance ().getFrameById (dc .getHeader ().getRowID ().getFileId () + dc .getHeader ().getRowID ().getFramePointer ());
13141353 final int newlen = bd .updateChunk (dc , o , s , llt );
13151354 final int diff = newlen - len - bd .getFrameFree ();
13161355
@@ -1383,25 +1422,28 @@ protected void delete (final Object o, final Session s, LLT extllt, boolean igno
13831422 }
13841423
13851424 final LLT llt = extllt ==null ?LLT .getLLT ():extllt ;
1386- final DataChunk dc = this .getChunkByEntity (o , s , llt );
1387- if (dc == null ) {
1388- throw new CannotAccessToDeletedRecord ();
1389- }
1390- if (dc .getHeader ().getState () == Header .RECORD_DELETED_STATE ) {
1391- throw new CannotAccessToDeletedRecord ();
1392- }
1393- final int len = dc .getBytesAmount ();
1394- final FrameData bd = Instance .getInstance ().getFrameById (dc .getHeader ().getRowID ().getFileId ()+dc .getHeader ().getRowID ().getFramePointer ());
1425+ try {
1426+ final DataChunk dc = this .getChunkByEntity (o , s , llt );
13951427
1396- if (!bd .getFrame ().isLocal ()) {
1397- if (!ignoreNoLocal ) {
1398- throw new CannotAccessToForeignRecord ();
1428+ if (dc == null ) {
1429+ throw new CannotAccessToDeletedRecord ();
13991430 }
1400- }
14011431
1402- DataChunk udc = null ;
1432+ if (dc .getHeader ().getState () == Header .RECORD_DELETED_STATE ) {
1433+ throw new CannotAccessToDeletedRecord ();
1434+ }
1435+
1436+ final int len = dc .getBytesAmount ();
1437+ final FrameData bd = Instance .getInstance ().getFrameById (dc .getHeader ().getRowID ().getFileId ()+dc .getHeader ().getRowID ().getFramePointer ());
1438+
1439+ if (!bd .getFrame ().isLocal ()) {
1440+ if (!ignoreNoLocal ) {
1441+ throw new CannotAccessToForeignRecord ();
1442+ }
1443+ }
1444+
1445+ DataChunk udc = null ;
14031446
1404- try {
14051447 if (!noTran ) { //save undo information
14061448 udc = dc .lock (s , llt );
14071449 }
@@ -1585,8 +1627,10 @@ public Boolean call() throws Exception {
15851627 if (stopped .get ()) {
15861628 return true ;
15871629 }
1588- for (Chunk c : b .getDataFrame ().getFrameChunks (s )) {
1589- q .put (c );
1630+ if (b .isValid ()) {
1631+ for (Chunk c : b .getDataFrame ().getFrameChunks (s )) {
1632+ q .put (c );
1633+ }
15901634 }
15911635 }
15921636 }
@@ -1717,6 +1761,7 @@ public Chunk cpoll(Session s) {
17171761 return null ;
17181762 }
17191763
1764+ @ Deprecated
17201765 protected ArrayList <FrameData > getStream (Map <Long , Long > retrieved , Session s ) throws Exception {
17211766 final ArrayList <FrameData > r = new ArrayList <>();
17221767 if (this .isIndex ()) { //index table
@@ -1729,8 +1774,10 @@ protected ArrayList<FrameData> getStream (Map<Long, Long> retrieved, Session s)
17291774 if (b .getObjectId () == 0 && b .getFrameId () == 0 ) {
17301775 cnue = false ;
17311776 } else {
1732- if (retrieved .get (b .getFrameId ()) == null ) {
1733- r .add (b );
1777+ if (b .isValid ()) {
1778+ if (retrieved .get (b .getFrameId ()) == null ) {
1779+ r .add (b );
1780+ }
17341781 }
17351782 }
17361783 }
@@ -1770,10 +1817,14 @@ public DataChunk getChunkByEntity (Object o, Session s, LLT llt) throws Exceptio
17701817 if (b .getObjectId () == 0 && b .getFrameId () == 0 ) {
17711818 cnue = false ;
17721819 } else {
1773- for (Chunk dc : b .getDataFrame ().getFrameChunks (s )) {
1774- if (Arrays .equals (id , ((DataChunk ) dc ).getSerializedId (s ))) {
1775- if (llt != null ) { llt .add (((DataChunk ) dc ).getFrameData ().getFrame ()); }
1776- return (DataChunk ) dc ;
1820+ if (b .isValid ()) {
1821+ for (Chunk dc : b .getDataFrame ().getFrameChunks (s )) {
1822+ if (Arrays .equals (id , ((DataChunk ) dc ).getSerializedId (s ))) {
1823+ if (llt != null ) {
1824+ llt .add (((DataChunk ) dc ).getFrameData ().getFrame ());
1825+ }
1826+ return (DataChunk ) dc ;
1827+ }
17771828 }
17781829 }
17791830 }
@@ -1803,10 +1854,14 @@ public DataChunk getChunkByEntity (Object o, Session s, LLT llt) throws Exceptio
18031854 if (b .getObjectId () == 0 && b .getFrameId () == 0 ) {
18041855 cnue = false ;
18051856 } else {
1806- for (Chunk dc : b .getDataFrame ().getFrameChunks (s )) {
1807- if (Arrays .equals (id , ((DataChunk ) dc ).getSerializedId (s ))) {
1808- if (llt != null ) { llt .add (((DataChunk ) dc ).getFrameData ().getFrame ()); }
1809- return (DataChunk ) dc ;
1857+ if (b .isValid ()) {
1858+ for (Chunk dc : b .getDataFrame ().getFrameChunks (s )) {
1859+ if (Arrays .equals (id , ((DataChunk ) dc ).getSerializedId (s ))) {
1860+ if (llt != null ) {
1861+ llt .add (((DataChunk ) dc ).getFrameData ().getFrame ());
1862+ }
1863+ return (DataChunk ) dc ;
1864+ }
18101865 }
18111866 }
18121867 }
@@ -1857,9 +1912,11 @@ public DataChunk getChunkById (long id, Session s) throws Exception {
18571912 if (b .getObjectId () == 0 && b .getFrameId () == 0 ) {
18581913 cnue = false ;
18591914 } else {
1860- for (Chunk c : b .getDataFrame ().getFrameChunks (s )) {
1861- if (Arrays .equals (iid , ((DataChunk ) c ).getSerializedId (s ))) {
1862- return (DataChunk ) c ;
1915+ if (b .isValid ()) {
1916+ for (Chunk c : b .getDataFrame ().getFrameChunks (s )) {
1917+ if (Arrays .equals (iid , ((DataChunk ) c ).getSerializedId (s ))) {
1918+ return (DataChunk ) c ;
1919+ }
18631920 }
18641921 }
18651922 }
0 commit comments