e804d736288d587a319aec935b035511b59080e9
[IRC.git] / Robust / Transactions / TransactionalIO / src / TransactionalIO / core / ExtendedTransaction.java
1 /*
2  * To change this template, choose Tools | Templates
3  * and open the template in the editor.
4  */
5 package TransactionalIO.core;
6
7 import TransactionalIO.exceptions.AbortedException;
8
9
10 import TransactionalIO.interfaces.BlockAccessModesEnum;
11 import TransactionalIO.interfaces.ContentionManager;
12 import TransactionalIO.interfaces.TransactionStatu;
13 //import dstm2.file.managers.BaseManager;
14
15
16
17 import java.io.FileDescriptor;
18 import java.io.IOException;
19 import java.io.RandomAccessFile;
20 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.Iterator;
23 import java.util.Map;
24 import java.util.TreeMap;
25 import java.util.Vector;
26 import java.util.concurrent.locks.Lock;
27 import java.util.concurrent.locks.ReentrantLock;
28
29 import java.util.concurrent.locks.ReentrantReadWriteLock;
30 import java.util.logging.Level;
31 import java.util.logging.Logger;
32
33 /**
34  *
35  * @author navid
36  */
37 public class ExtendedTransaction implements TransactionStatu {
38
39     private static native int nativepwrite(byte buff[], long offset, int size, FileDescriptor fd);
40     public TransactionStatu memorystate;
41     public int starttime;
42     public int endtime;
43     public int numberofwrites;
44     public int numberofreads;
45     private TreeMap sortedAccesedFiles;
46
47     public enum Status {
48
49         ABORTED, ACTIVE, COMMITTED
50     };
51     private boolean writesmerged = true;
52     //private Vector heldlengthlocks;
53     //private Vector<ReentrantLock> heldoffsetlocks;    
54     // private Vector heldoffsetlocks;
55     //private Vector<ReentrantLock> heldblocklocks;    
56     //private Vector heldblocklocks;
57     //private HashMap<INode, Vector<TransactionalFile>> AccessedFiles;
58     private HashMap AccessedFiles;
59     //private HashMap<INode, HashMap<Integer, BlockAccessModesEnum> > accessedBlocks;
60     private HashMap accessedBlocks;
61     //private HashMap<TransactionalFile, TransactionLocalFileAttributes> LocaltoGlobalMappings;
62     private HashMap GlobaltoLocalMappings;
63     public HashMap merge_for_writes_done;
64     private HashMap writeBuffer;
65     private volatile Status status;
66     //public ReentrantReadWriteLock[] toholoffsetlocks;
67     public MYLock[] toholoffsetlocks;
68     public int offsetcount = 0;
69     //public Lock[] toholdblocklocks;
70     public MYReadWriteLock[] toholdblocklocks;
71     public int blockcount = 0;
72
73     public ExtendedTransaction() {
74         //  super();
75         // id = Integer.valueOf(Thread.currentThread().getName().substring(7));
76         //toholoffsetlocks = new ReentrantReadWriteLock[20];
77         toholoffsetlocks = new MYLock[20];
78         toholdblocklocks = new MYReadWriteLock[20];
79         //  for (int i=0; i<20; i++)
80         //      toholoffsetlocks[i] = new ReentrantLock();
81 //        heldlengthlocks = new Vector();
82 //        heldblocklocks = new Vector();
83         //  heldoffsetlocks = new Vector();
84         AccessedFiles = new HashMap();
85         GlobaltoLocalMappings = new HashMap/*<TransactionalFile, TransactionLocalFileAttributes >*/();
86         writeBuffer = new HashMap();
87         status = Status.ACTIVE;
88         accessedBlocks = new HashMap();
89         merge_for_writes_done = new HashMap();
90         writesmerged = true;
91     //   setContentionmanager(new BaseManager());
92     //    beginTransaction();
93
94     }
95
96     public ExtendedTransaction(TransactionStatu memorystate) {
97         this();
98
99         this.memorystate = memorystate;
100     }
101
102     public static int invokeNativepwrite(byte buff[], long offset, int size, RandomAccessFile file) {
103         try {
104             return nativepwrite(buff, offset, buff.length, file.getFD());
105         } catch (IOException ex) {
106
107             Logger.getLogger(TransactionalFile.class.getName()).log(Level.SEVERE, null, ex);
108             return -1;
109         }
110
111     }
112
113     public void abort() {
114         synchronized (this) {
115             this.status = Status.ABORTED;
116             if (this.memorystate != null && !(this.memorystate).isAborted()) {
117                 this.memorystate.abortThisSystem();
118             }
119         }
120     }
121
122     public Status getStatus() {
123         return status;
124     }
125
126     public boolean isActive() {
127         return this.getStatus() == Status.ACTIVE;
128     }
129
130     public boolean isAborted() {
131         return this.getStatus() == Status.ABORTED;
132     }
133
134     public HashMap getWriteBuffer() {
135         return writeBuffer;
136     }
137
138     public HashMap getAccessedFiles() {
139         return AccessedFiles;
140     }
141
142     public boolean isWritesmerged() {
143         return writesmerged;
144     }
145
146     public void setWritesmerged(boolean writesmerged) {
147         this.writesmerged = writesmerged;
148     }
149
150     public HashMap getGlobaltoLocalMappings() {
151         return GlobaltoLocalMappings;
152     }
153
154     public HashMap getAccessedBlocks() {
155         return accessedBlocks;
156     }
157
158     public ContentionManager getBlockContentionManager() {
159         return ManagerRepository.getBlockcm();
160     }
161
162     public ContentionManager getOffsetContentionManager() {
163         return ManagerRepository.getOffsetcm();
164     }
165
166     public TreeMap getSortedFileAccessMap(HashMap hmap) {
167         /*TreeMap sortedMap = new TreeMap(hmap);
168         return sortedMap;*/
169         sortedAccesedFiles = new TreeMap(hmap);
170         return sortedAccesedFiles;
171         //return new TreeMap(hmap);
172     }
173
174     public void addFile(TransactionalFile tf, long offsetnumber/*, TransactionLocalFileAttributes tmp*/) {
175         //tf.getInodestate().commitedfilesize.lengthlock.lock();
176         //TransactionLocalFileAttributes tmp = new TransactionLocalFileAttributes(offsetnumber, tf.getInodestate().commitedfilesize.getLength());
177         TransactionLocalFileAttributes tmp = new TransactionLocalFileAttributes(offsetnumber, 0);
178         //tf.getInodestate().commitedfilesize.lengthlock.unlock();
179         Vector dummy;
180
181         if (AccessedFiles.containsKey(tf.getInode())) {
182             dummy = (Vector) AccessedFiles.get(tf.getInode());
183         } else {
184             dummy = new Vector();
185             AccessedFiles.put(tf.getInode(), dummy);
186         }
187         dummy.add(tf);
188         GlobaltoLocalMappings.put(tf, tmp);
189         merge_for_writes_done.put(tf.getInode(), Boolean.TRUE);
190     }
191
192     public boolean lockOffsets() {   /// Locking offsets for File Descriptors
193
194
195
196         TreeMap<INode, Vector<TransactionalFile>> hm = getSortedFileAccessMap(AccessedFiles);
197         //for (Map.Entry<INode>Vector<TransactionalFile>> entry : hm.entrySet())  {
198             
199         //}
200     //    entry.getKey().someMethod(entry.getValue());  
201         Iterator iter = hm.keySet().iterator();
202         offsetcount = 0;
203         for (Map.Entry<INode,Vector<TransactionalFile>> entry : hm.entrySet())  {
204         // for (int j=0; j< hm.size(); j++){
205         //while (iter.hasNext()/* && (this.getStatus() == Status.ACTIVE)*/) {
206           //  INode key = (INode) iter.next();
207             //Vector vec = (Vector) AccessedFiles.get(key);
208             INode key = entry.getKey();
209             Vector vec = entry.getValue();
210             Collections.sort(vec);
211             for (int i = 0; i < vec.size(); i++) {
212                 //Iterator it = vec.iterator();
213                 //while (it.hasNext() /*&& this.getStatus() == Status.ACTIVE*/) {
214                 //TransactionalFile value = (TransactionalFile) it.next();
215                 TransactionalFile value = (TransactionalFile) vec.get(i);
216                 //System.out.println(Thread.currentThread() + " offset " + value);
217                /* if (toholoffsetlocks[offsetcount] == null)
218                 toholoffsetlocks[offsetcount] = new ReentrantReadWriteLock();
219                 toholoffsetlocks[offsetcount] = value.offsetlock;*/
220                 toholoffsetlocks[offsetcount] = value.myoffsetlock;
221                 offsetcount++;
222                 
223                 value.myoffsetlock.acquire(this);
224                 //value.offsetlock.writeLock().lock();
225
226                 //heldoffsetlocks.add(value.offsetlock);
227
228                 
229                 //should be uncommented
230                 /*if (((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(value)).lenght_read) {
231                     if (!(value.getInodestate().commitedfilesize.lengthlock.isHeldByCurrentThread())) {
232                         value.getInodestate().commitedfilesize.lengthlock.lock();
233                         heldlengthlocks.add(value.getInodestate().commitedfilesize.lengthlock);
234                     }
235                 }*/
236             // break;
237             }
238         }
239
240         if (this.getStatus() != Status.ACTIVE) {
241             //      for (int i=0; i<offsetcount; i++){
242             //          heldoffsetlocks.add(toholoffsetlocks[i]);
243             //      }
244             //      offsetcount = 0;
245             return false;
246         }
247         return true;
248     }
249
250     public boolean lockBlock(BlockDataStructure block, BlockAccessModesEnum mode/*, GlobalINodeState adapter, BlockAccessModesEnum mode, int expvalue, INode inode, TransactionLocalFileAttributes tf*/) {
251
252         //Lock lock;
253         if (mode == BlockAccessModesEnum.READ) {
254           
255                 //lock =block.getLock().readLock();
256                 block.getLock().readLock();
257           
258         } else {
259          
260                 //lock = block.getLock().writeLock();
261                 block.getLock().writeLock();
262             
263         }
264
265         //lock.lock();
266
267         if (toholdblocklocks[blockcount] == null) {
268             //if (mode == BlockAccessModesEnum.READ) {
269             //    toholdblocklocks[blockcount] = new ReentrantReadWriteLock().readLock();
270             //}
271             // else 
272             //toholdblocklocks[blockcount] = new ReentrantReadWriteLock().writeLock();
273             toholdblocklocks[blockcount] = new MYReadWriteLock();
274         }
275         //toholdblocklocks[blockcount] = lock;
276         toholdblocklocks[blockcount] = block.getLock();
277         blockcount++;
278         //heldblocklocks.add(lock);
279         return true;
280
281     }
282
283     public void prepareCommit() {
284         if (this.status != Status.ACTIVE) {
285             throw new AbortedException();
286         }
287         if (!lockOffsets()) {
288             throw new AbortedException();
289         }
290
291         //  boolean lengthslock = true;
292         //   if (!lockOffsets()) {
293         //       throw new AbortedException();
294         //   }
295
296
297         ///////////////////////////
298
299
300         Map hm = getWriteBuffer();
301
302         Iterator iter = hm.keySet().iterator();
303         WriteOperations value;
304         Vector vec = new Vector();
305         while (iter.hasNext() && (this.getStatus() == Status.ACTIVE)) {
306             INode key = (INode) iter.next();
307             vec = (Vector) hm.get(key);
308             //if (!(isWritesmerged()))
309                 Collections.sort(vec);
310             //Iterator it = vec.iterator();
311             for (int j = 0; j < vec.size(); j++) {
312                 //while (it.hasNext()) {
313                 value = (WriteOperations) vec.get(j);
314                 //value = (WriteOperations) it.next();
315                 if (value.isUnknownoffset()) {
316                     long start;
317                     long end;
318                     start = value.getRange().getStart() - value.getBelongingto().getCopylocaloffset() + value.getOwnertransactionalFile().getCommitedoffset().getOffsetnumber();
319                     end = value.getRange().getEnd() - value.getBelongingto().getCopylocaloffset() + value.getOwnertransactionalFile().getCommitedoffset().getOffsetnumber();
320                     if (value.getBelongingto().isUnknown_inital_offset_for_write()) {
321                         value.getBelongingto().setLocaloffset(value.getBelongingto().getLocaloffset() - value.getBelongingto().getCopylocaloffset() + value.getOwnertransactionalFile().getCommitedoffset().getOffsetnumber());
322                         value.getBelongingto().setUnknown_inital_offset_for_write(false);
323                     }
324
325                     int startblock = FileBlockManager.getCurrentFragmentIndexofTheFile(start);
326                     int targetblock = FileBlockManager.getTargetFragmentIndexofTheFile(start, value.getRange().getEnd() - value.getRange().getStart());
327
328                     TreeMap sset;
329                     if (this.getAccessedBlocks().get(key) != null) {
330                         sset = (TreeMap) this.getAccessedBlocks().get(key);
331                     } else {
332                         sset = new TreeMap();
333                         this.getAccessedBlocks().put(key, sset);
334                     }
335
336
337                     for (int i = startblock; i <= targetblock; i++) {
338                         if (sset.containsKey(Integer.valueOf(i))) {
339                             if (sset.get(Integer.valueOf(i)) != BlockAccessModesEnum.WRITE) {
340                                 sset.put(Integer.valueOf(i), BlockAccessModesEnum.READ_WRITE);
341                             }
342                         } else {
343                             sset.put(Integer.valueOf(i), BlockAccessModesEnum.WRITE);
344                         }
345                     }
346
347                     value.getRange().setStart(start);
348                     value.getRange().setEnd(end);
349                 }
350             }
351
352         }
353        
354         //toholdblocklocks = new Lock[100];
355
356         Iterator it = this.getAccessedBlocks().keySet().iterator();
357         while (it.hasNext() /*&& (this.getStatus() == Status.ACTIVE)*/) {
358             INode inode = (INode) it.next();
359             GlobalINodeState inodestate = TransactionalFileWrapperFactory.getTateransactionalFileINodeState(inode);
360             TreeMap vec2 = (TreeMap) this.getAccessedBlocks().get(inode);
361             Iterator iter2 = vec2.keySet().iterator();
362             while (iter2.hasNext()/* && this.getStatus() == Status.ACTIVE*/) {
363                 Integer num = (Integer) iter2.next();
364
365                 BlockDataStructure blockobj = inodestate.getBlockDataStructure(num);
366
367                 this.lockBlock(blockobj, (BlockAccessModesEnum) vec2.get(num));
368
369
370             }
371         }
372
373
374         if (this.getStatus() != Status.ACTIVE) {
375             //    for (int i=0; i<blockcount; i++)
376             //        heldblocklocks.add(toholdblocklocks[i]); 
377             throw new AbortedException();
378         }
379         
380         
381
382        
383         abortAllReaders();
384
385     }
386
387     public void commitOffset() {
388         Iterator k = GlobaltoLocalMappings.keySet().iterator();
389         while (k.hasNext()) {
390             TransactionalFile trf = (TransactionalFile) (k.next());
391             trf.getCommitedoffset().setOffsetnumber(((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(trf)).getLocaloffset());
392             
393             
394             //should be uncommented
395            /* if (((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(trf)).getInitiallocallength() != ((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(trf)).getLocalsize()) {
396                 try {
397                     if (!(trf.getInodestate().commitedfilesize.lengthlock.isHeldByCurrentThread())) {
398                         trf.getInodestate().commitedfilesize.lengthlock.lock();
399                     }
400                     //Iterator it2 = trf.getInodestate().commitedfilesize.getLengthReaders().iterator();
401
402
403                     //  if (((TransactionLocalFileAttributes) getGlobaltoLocalMappings().get(trf)).getInitiallocallength() != ((TransactionLocalFileAttributes) getGlobaltoLocalMappings().get(trf)).getLocalsize()) {
404                     for (int adad = 0; adad < trf.getInodestate().commitedfilesize.getLengthReaders().size(); adad++) {
405                         //    while (it2.hasNext()) {
406                         ExtendedTransaction tr = (ExtendedTransaction) trf.getInodestate().commitedfilesize.getLengthReaders().get(adad);
407                         //ExtendedTransaction tr = (ExtendedTransaction) it2.next();
408                         if (tr != this) {
409                             tr.abort();
410                         }
411                     }
412                     trf.getInodestate().commitedfilesize.getLengthReaders().clear();
413                     // }
414                     trf.getInodestate().commitedfilesize.setLength(trf.file.length());
415
416                     if (trf.getInodestate().commitedfilesize.lengthlock.isHeldByCurrentThread()) {
417                         heldlengthlocks.remove(trf.getInodestate().commitedfilesize.lengthlock);
418                         trf.getInodestate().commitedfilesize.lengthlock.unlock();
419                     }
420                     if (((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(trf)).lenght_read) {
421                         trf.getInodestate().commitedfilesize.getLengthReaders().remove(this);
422                     //heldlengthlocks.remove(trf.getInodestate().commitedfilesize.lengthlock);
423                     //trf.getInodestate().commitedfilesize.lengthlock.unlock();
424                     }
425
426                 } catch (IOException ex) {
427                     Logger.getLogger(ExtendedTransaction.class.getName()).log(Level.SEVERE, null, ex);
428                 }
429             }*/
430         }
431         for (int i=0; i<offsetcount; i++)
432             toholoffsetlocks[i].release(this);
433         offsetcount =0 ;
434         
435         /*for (int i = 0; i < heldlengthlocks.size(); i++) {
436             ReentrantLock lock = (ReentrantLock) heldlengthlocks.get(i);
437             //ReentrantLock lock = (ReentrantLock) it.next();
438             lock.unlock();
439         }*/
440
441     }
442
443     public void commitChanges() {
444
445         Map hm = getWriteBuffer();
446         Iterator iter = hm.keySet().iterator();
447         //Iterator it;
448         WriteOperations writeop;
449         Vector vec;
450         while (iter.hasNext()) {
451             INode key = (INode) iter.next();
452
453             vec = (Vector) hm.get(key);
454             //Collections.sort(vec);
455             for (int j = 0; j < vec.size(); j++) {
456                 //it = vec.iterator();
457                 //while (it.hasNext()) {
458                 writeop = (WriteOperations) vec.get(j);
459                 //writeop = (WriteOperations) it.next();
460                 Byte[] data = new Byte[(int) (writeop.getRange().getEnd() - writeop.getRange().getStart())];
461                 byte[] bytedata = new byte[(int) (writeop.getRange().getEnd() - writeop.getRange().getStart())];
462                 data = (Byte[]) writeop.getData();
463
464                 for (int i = 0; i < data.length; i++) {
465                     bytedata[i] = data[i];
466                 }
467                 invokeNativepwrite(bytedata, writeop.getRange().getStart(), bytedata.length, writeop.getOwnertransactionalFile().file);
468             }
469         }
470
471   /*      Iterator k = GlobaltoLocalMappings.keySet().iterator();
472         while (k.hasNext()) {
473             TransactionalFile trf = (TransactionalFile) (k.next());
474             trf.getCommitedoffset().setOffsetnumber(((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(trf)).getLocaloffset());
475             if (((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(trf)).getInitiallocallength() != ((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(trf)).getLocalsize()) {
476                 try {
477                     if (!(trf.getInodestate().commitedfilesize.lengthlock.isHeldByCurrentThread())) {
478                         trf.getInodestate().commitedfilesize.lengthlock.lock();
479                     }
480                     //Iterator it2 = trf.getInodestate().commitedfilesize.getLengthReaders().iterator();
481
482
483                     //  if (((TransactionLocalFileAttributes) getGlobaltoLocalMappings().get(trf)).getInitiallocallength() != ((TransactionLocalFileAttributes) getGlobaltoLocalMappings().get(trf)).getLocalsize()) {
484                     for (int adad = 0; adad < trf.getInodestate().commitedfilesize.getLengthReaders().size(); adad++) {
485                         //    while (it2.hasNext()) {
486                         ExtendedTransaction tr = (ExtendedTransaction) trf.getInodestate().commitedfilesize.getLengthReaders().get(adad);
487                         //ExtendedTransaction tr = (ExtendedTransaction) it2.next();
488                         if (tr != this) {
489                             tr.abort();
490                         }
491                     }
492                     trf.getInodestate().commitedfilesize.getLengthReaders().clear();
493                     // }
494                     trf.getInodestate().commitedfilesize.setLength(trf.file.length());
495
496                     if (trf.getInodestate().commitedfilesize.lengthlock.isHeldByCurrentThread()) {
497                         heldlengthlocks.remove(trf.getInodestate().commitedfilesize.lengthlock);
498                         trf.getInodestate().commitedfilesize.lengthlock.unlock();
499                     }
500                     if (((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(trf)).lenght_read) {
501                         trf.getInodestate().commitedfilesize.getLengthReaders().remove(this);
502                     //heldlengthlocks.remove(trf.getInodestate().commitedfilesize.lengthlock);
503                     //trf.getInodestate().commitedfilesize.lengthlock.unlock();
504                     }
505
506                 } catch (IOException ex) {
507                     Logger.getLogger(ExtendedTransaction.class.getName()).log(Level.SEVERE, null, ex);
508                 }
509             }
510         }*/
511
512
513     /*  for (int i =0; i<blockcount; i++){
514     toholdblocklocks[i].unlock();
515     }
516     for (int i =0; i<offsetcount; i++){
517     toholoffsetlocks[i].unlock();
518     }*/
519     }
520
521     public void unlockAllLocks() {
522         //Iterator it = heldblocklocks.iterator();
523
524 //        for (int i=0; i<heldblocklocks.size(); i++){
525
526         //while (it.hasNext()) {
527
528         //Lock lock = (Lock) it.next();
529         //          Lock lock = (Lock) heldblocklocks.get(i);
530         //          lock.unlock();
531         //     }
532         // heldblocklocks.clear();
533         
534         for (int i = 0; i < blockcount; i++) {
535             toholdblocklocks[i].unlock();
536         }
537         blockcount = 0;
538
539         
540         if (this.getStatus() == Status.ABORTED){
541             for (int i = 0; i < offsetcount; i++) {
542                 //toholoffsetlocks[i].writeLock().unlock();
543                 toholoffsetlocks[i].release(this);
544             }
545             offsetcount = 0;
546
547
548         //it = heldoffsetlocks.iterator();
549 //        for (int i=0; i<heldoffsetlocks.size(); i++){
550         //while (it.hasNext()) {
551         //          ReentrantLock lock = (ReentrantLock) heldoffsetlocks.get(i);
552         //ReentrantLock lock = (ReentrantLock) it.next();
553         //          lock.unlock();
554 //        }
555         //  heldoffsetlocks.clear();
556
557         //it = heldlengthlocks.iterator();
558         //while (it.hasNext()) {
559
560            /* for (int i = 0; i < heldlengthlocks.size(); i++) {
561                 ReentrantLock lock = (ReentrantLock) heldlengthlocks.get(i);
562                 //ReentrantLock lock = (ReentrantLock) it.next();
563                 lock.unlock();
564             }*/
565         }
566     // heldlengthlocks.clear();
567     }
568
569     public void abortAllReaders() {
570         //TreeMap hm = getSortedFileAccessMap(AccessedFiles);
571         
572         //lock phase
573         Iterator iter = sortedAccesedFiles.keySet().iterator();
574         TransactionalFile value;
575         while (iter.hasNext()) {
576             INode key = (INode) iter.next();
577             Vector vec = (Vector) AccessedFiles.get(key);
578             for (int i = 0; i < vec.size(); i++) {
579                 //Iterator it = vec.iterator();
580                 //while (it.hasNext()) {
581
582                 //value = (TransactionalFile) it.next();
583                 value = (TransactionalFile) vec.get(i);
584                 //Iterator it2 = value.getCommitedoffset().getOffsetReaders().iterator(); // for visible readers strategy
585
586                 //while (it2.hasNext()) {
587                 for (int j = 0; j < value.getCommitedoffset().getOffsetReaders().size(); j++) {
588                     //ExtendedTransaction tr = (ExtendedTransaction) it2.next();
589                     ExtendedTransaction tr = (ExtendedTransaction) value.getCommitedoffset().getOffsetReaders().get(j);
590                     if (tr != this) {
591                         tr.abort();
592                     }
593                 }
594                 value.getCommitedoffset().getOffsetReaders().clear();
595
596
597
598             }
599
600             TreeMap vec2;
601             if (accessedBlocks.get(key) != null) {
602                 vec2 = (TreeMap) accessedBlocks.get(key);
603             } else {
604                 vec2 = new TreeMap();
605
606             }
607             GlobalINodeState inodestate = TransactionalFileWrapperFactory.getTateransactionalFileINodeState(key);
608             Iterator it2 = vec2.keySet().iterator();
609
610             while (it2.hasNext()) {
611
612                 Integer num = (Integer) it2.next();
613                 if (vec2.get(num) != BlockAccessModesEnum.READ) {
614                     BlockDataStructure blockobj = (BlockDataStructure) inodestate.getBlockDataStructure(num);
615                     //lockmap.get(num);
616                     //Iterator it4 = blockobj.getReaders().iterator(); // from here for visible readers strategy
617                     for (int i = 0; i < blockobj.getReaders().size(); i++) {
618
619                         //while (it4.hasNext()) {
620                         ExtendedTransaction tr = (ExtendedTransaction) blockobj.getReaders().get(i);
621                         //ExtendedTransaction tr = (ExtendedTransaction) it4.next();
622                         if (this != tr) {
623                             tr.abort();
624                         }
625                     }
626                     blockobj.getReaders().clear();
627                 }
628             }
629
630
631         }
632     }
633
634     public TransactionStatu getOtherSystem() {
635         return memorystate;
636     }
637
638     public void setOtherSystem(TransactionStatu othersystem) {
639         memorystate = othersystem;
640     }
641
642     //   public Vector getHeldblocklocks() {
643     //       return heldblocklocks;
644     //   }
645
646     //   public void setHeldblocklocks(Vector heldblocklocks) {
647     //       this.heldblocklocks = heldblocklocks;
648     //   }
649
650 //    public Vector getHeldoffsetlocks() {
651     //       return heldoffsetlocks;
652     //   }
653   //  public Vector getHeldlengthlocks() {
654    //     return heldlengthlocks;
655    // }
656
657     //   public void setHeldoffsetlocks(Vector heldoffsetlocks) {
658     //       this.heldoffsetlocks = heldoffsetlocks;
659     //   }
660     public void abortThisSystem() {
661         abort();
662     }
663
664     public boolean isCommitted() {
665         if (this.status == Status.COMMITTED) {
666             return true;
667         }
668         return false;
669
670     }
671 }
672 /*
673 public boolean lockBlock(BlockDataStructure block, Adapter adapter, BlockAccessModesEnum mode, int expvalue) { // from here for visible readers strategy
674 while (this.getStatus() == Status.ACTIVE) {
675 if (lock.tryLock()) {
676 Thread.onAbortOnce(new Runnable() {
677
678 public void run() {
679 lock.unlock();
680 }
681 });
682
683 heldblocklocks.add(lock);
684
685 synchronized (adapter) {
686 block.setOwner(this);
687 //        Iterator it =  block.getReaders().iterator(); 
688 //        while (it.hasNext())
689 //        {
690 //            ExtendedTransaction tr = (ExtendedTransaction) it.next();
691 //            tr.abort();
692 //       }
693 }
694
695 return true;
696 } else {
697 getBlockContentionManager().resolveConflict(this, block.getOwner());
698 }
699 }
700 return false;*/
701 /*
702 public boolean lockBlock(BlockDataStructure block, Adapter adapter, BlockAccessModesEnum mode, int expvalue) { // versioning strat
703 while (this.getStatus() == Status.ACTIVE) {
704 if (lock.tryLock()) {
705 Thread.onAbortOnce(new Runnable() {
706
707 public void run() {
708 lock.unlock();
709 }
710 });
711
712 heldblocklocks.add(lock);
713 if (mode != BlockAccessModesEnum.WRITE) {   egy
714 if (block.getVersion().get() != expvalue) {
715 unlockAllLocks();
716 return false;
717 }
718 }
719 synchronized (adapter) {
720 block.setOwner(this);
721 }
722
723 return true;
724 } else {
725 getContentionManager().resolveConflict(this, block.getOwner());
726 }
727 }
728 return false;
729 }*/
730 // }
731 //expvalue = ((Integer) value.getBlockversions().get(it)).intValue(); //for versioning strategy
732             /*if (!(value.isValidatelocaloffset())) {
733 if (((BlockAccessModesEnum) (value.getAccesedblocks().get(blockno))) != BlockAccessModesEnum.WRITE) { //versioning strategy
734
735 /if (blockobj.getVersion().get() == expvalue) {
736
737 ok = this.lock(blockobj, value.adapter, (BlockAccessModesEnum) (value.getAccesedblocks().get(blockno)), expvalue);
738 if (ok == false) {
739 //        unlockAllLocks();
740 break;
741 }
742 } else {
743 ok = false;
744 break;
745 }
746 } else {
747
748 ok = this.lock(blockobj, value.adapter, (BlockAccessModesEnum) (value.getAccesedblocks().get(blockno)), expvalue);
749 if (ok == false) {
750 break;
751 }
752 }
753 }
754
755
756 if (!(ok)) {
757 unlockAllLocks();
758 throw new AbortedException();
759 }*/
760    
761
762
763