- INode inode = (INode) it.next();
- GlobalINodeState inodestate = TransactionalFileWrapperFactory.getTateransactionalFileINodeState(inode);
- TreeMap vec2 = (TreeMap) this.getAccessedBlocks().get(inode);
- Iterator iter2 = vec2.keySet().iterator();
- while(iter2.hasNext()){
- Integer num = (Integer) iter2.next();
-
- //BlockDataStructure blockobj = (BlockDataStructure) inodestate.lockmap.get(num);
- BlockDataStructure blockobj;
- // if (((BlockAccessModesEnum)vec2.get(num)) == BlockAccessModesEnum.WRITE){
- blockobj = inodestate.getBlockDataStructure(num);
- // }
- // else
- // blockobj = (BlockDataStructure) inodestate.lockmap.get(num);
-
- ok = this.lockBlock(blockobj, (BlockAccessModesEnum)vec2.get(num));
- if (ok == false)
- break;
- /* synchronized(benchmark.lock){
- benchmark.msg += Thread.currentThread().getName() + " Locked the Block Number " + blockobj.getBlocknumber() +" for " + inode + "\n";
- }*/
- // this.msg.put(System.nanoTime(), Thread.currentThread().getName() + " Locked the Block Number " + blockobj.getBlocknumber() + " for file " + inode + "\n");
- }
- }
-
- if (this.getStatus() != Status.ACTIVE){
- // unlockAllLocks();
- // this.msg.put(System.nanoTime(), Thread.currentThread().getName() + " Aborted \n");
- /* synchronized(benchmark.lock){
- benchmark.msg += Thread.currentThread().getName() + " Aborted \n";
- }*/
- // Thread.currentThread().stop();
- throw new AbortedException();
- }
- abortAllReaders();
-
- // }
- //expvalue = ((Integer) value.getBlockversions().get(it)).intValue(); //for versioning strategy
- /*if (!(value.isValidatelocaloffset())) {
- if (((BlockAccessModesEnum) (value.getAccesedblocks().get(blockno))) != BlockAccessModesEnum.WRITE) { //versioning strategy
-
- /if (blockobj.getVersion().get() == expvalue) {
-
- ok = this.lock(blockobj, value.adapter, (BlockAccessModesEnum) (value.getAccesedblocks().get(blockno)), expvalue);
- if (ok == false) {
- // unlockAllLocks();
- break;
- }
- } else {
- ok = false;
- break;
- }
- } else {
-
- ok = this.lock(blockobj, value.adapter, (BlockAccessModesEnum) (value.getAccesedblocks().get(blockno)), expvalue);
- if (ok == false) {
- break;
- }
- }
- }
-
-
- if (!(ok)) {
- unlockAllLocks();
- throw new AbortedException();
- }*/
- }
-
- public void commitChanges(){
-
- // this.msg.put(System.nanoTime(), Thread.currentThread().getName() + " is committing \n");
-
-
-
- //synchronized(benchmark.lock){
- // System.out.println(Thread.currentThread().getName() + " is commiting");
- //}
-
-
- Map hm = getWriteBuffer();
- Iterator iter = hm.keySet().iterator();
- Iterator it;
- WriteOperations writeop;
- Vector vec;
- while (iter.hasNext() && (this.getStatus() == Status.ACTIVE)) {
- INode key = (INode) iter.next();
-
- vec = (Vector) hm.get(key);
- Collections.sort(vec);
- it = vec.iterator();
- while (it.hasNext()){
-
-
- //value = (WriteOperations) it.next();
- // writeop = (WriteOperations) writeBuffer.get(key);
- writeop = (WriteOperations) it.next();
- // System.out.println(writeop);
- Byte[] data = new Byte[(int) (writeop.getRange().getEnd() - writeop.getRange().getStart())];
- byte[] bytedata = new byte[(int) (writeop.getRange().getEnd() - writeop.getRange().getStart())];
- data = (Byte[]) writeop.getData();
-
- for (int i = 0; i < data.length; i++) {
- bytedata[i] = data[i];
- }
-
- // try {
- //
- // writeop.getOwnertransactionalFile().file.seek(writeop.getRange().getStart());
- // System.out.println(Thread.currentThread() + " range " + writeop.getRange().getStart());
- // writeop.getOwnertransactionalFile().file.write(bytedata);
- invokeNativepwrite(bytedata, writeop.getRange().getStart(), bytedata.length, writeop.getOwnertransactionalFile().file);
- // System.out.println(Thread.currentThread() + " " + bytedata);
-
- // } catch (IOException ex) {
- // Logger.getLogger(ExtendedTransaction.class.getName()).log(Level.SEVERE, null, ex);
- // }
- //
-