public TransactionStatu memorystate;
public int starttime;
public int endtime;
- public TreeMap msg = new TreeMap();
public int numberofwrites;
public int numberofreads;
private TreeMap sortedAccesedFiles;
ABORTED, ACTIVE, COMMITTED
};
private boolean writesmerged = true;
- private Vector heldlengthlocks;
+ //private Vector heldlengthlocks;
//private Vector<ReentrantLock> heldoffsetlocks;
// private Vector heldoffsetlocks;
//private Vector<ReentrantLock> heldblocklocks;
//public ReentrantReadWriteLock[] toholoffsetlocks;
public MYLock[] toholoffsetlocks;
public int offsetcount = 0;
- public Lock[] toholdblocklocks;
+ //public Lock[] toholdblocklocks;
+ public MYReadWriteLock[] toholdblocklocks;
public int blockcount = 0;
public ExtendedTransaction() {
// id = Integer.valueOf(Thread.currentThread().getName().substring(7));
//toholoffsetlocks = new ReentrantReadWriteLock[20];
toholoffsetlocks = new MYLock[20];
- toholdblocklocks = new Lock[20];
+ toholdblocklocks = new MYReadWriteLock[20];
// for (int i=0; i<20; i++)
// toholoffsetlocks[i] = new ReentrantLock();
- heldlengthlocks = new Vector();
+// heldlengthlocks = new Vector();
// heldblocklocks = new Vector();
// heldoffsetlocks = new Vector();
AccessedFiles = new HashMap();
- TreeMap hm = getSortedFileAccessMap(AccessedFiles);
+ TreeMap<INode, Vector<TransactionalFile>> hm = getSortedFileAccessMap(AccessedFiles);
+ //for (Map.Entry<INode>Vector<TransactionalFile>> entry : hm.entrySet()) {
+
+ //}
+ // entry.getKey().someMethod(entry.getValue());
Iterator iter = hm.keySet().iterator();
offsetcount = 0;
-
+ for (Map.Entry<INode,Vector<TransactionalFile>> entry : hm.entrySet()) {
// for (int j=0; j< hm.size(); j++){
- while (iter.hasNext()/* && (this.getStatus() == Status.ACTIVE)*/) {
- INode key = (INode) iter.next();
- Vector vec = (Vector) AccessedFiles.get(key);
-
+ //while (iter.hasNext()/* && (this.getStatus() == Status.ACTIVE)*/) {
+ // INode key = (INode) iter.next();
+ //Vector vec = (Vector) AccessedFiles.get(key);
+ INode key = entry.getKey();
+ Vector vec = entry.getValue();
Collections.sort(vec);
for (int i = 0; i < vec.size(); i++) {
//Iterator it = vec.iterator();
public boolean lockBlock(BlockDataStructure block, BlockAccessModesEnum mode/*, GlobalINodeState adapter, BlockAccessModesEnum mode, int expvalue, INode inode, TransactionLocalFileAttributes tf*/) {
- Lock lock;
+ //Lock lock;
if (mode == BlockAccessModesEnum.READ) {
- lock = block.getLock().readLock();
+
+ //lock =block.getLock().readLock();
+ block.getLock().readLock();
+
} else {
- lock = block.getLock().writeLock();
+
+ //lock = block.getLock().writeLock();
+ block.getLock().writeLock();
+
}
- lock.lock();
+ //lock.lock();
if (toholdblocklocks[blockcount] == null) {
//if (mode == BlockAccessModesEnum.READ) {
// toholdblocklocks[blockcount] = new ReentrantReadWriteLock().readLock();
//}
// else
- toholdblocklocks[blockcount] = new ReentrantReadWriteLock().writeLock();
+ //toholdblocklocks[blockcount] = new ReentrantReadWriteLock().writeLock();
+ toholdblocklocks[blockcount] = new MYReadWriteLock();
}
- toholdblocklocks[blockcount] = lock;
+ //toholdblocklocks[blockcount] = lock;
+ toholdblocklocks[blockcount] = block.getLock();
blockcount++;
//heldblocklocks.add(lock);
return true;
while (iter.hasNext() && (this.getStatus() == Status.ACTIVE)) {
INode key = (INode) iter.next();
vec = (Vector) hm.get(key);
- Collections.sort(vec);
+ //if (!(isWritesmerged()))
+ Collections.sort(vec);
//Iterator it = vec.iterator();
for (int j = 0; j < vec.size(); j++) {
//while (it.hasNext()) {
// lock.unlock();
// }
// heldblocklocks.clear();
+
for (int i = 0; i < blockcount; i++) {
toholdblocklocks[i].unlock();
}
// public Vector getHeldoffsetlocks() {
// return heldoffsetlocks;
// }
- public Vector getHeldlengthlocks() {
- return heldlengthlocks;
- }
+ // public Vector getHeldlengthlocks() {
+ // return heldlengthlocks;
+ // }
// public void setHeldoffsetlocks(Vector heldoffsetlocks) {
// this.heldoffsetlocks = heldoffsetlocks;
block = this.inodestate.getBlockDataStructure((Integer) (occupiedblocks.get(k)));//(BlockDataStructure) tmp.adapter.lockmap.get(Integer.valueOf(k)));
- block.getLock().readLock().lock();
+ //block.getLock().readLock().lock();
+ block.getLock().readLock();
if (!(block.getReaders().contains(me))) {
block.getReaders().add(me);
}
for (int i = 0; i < k; i++) {
block = this.inodestate.getBlockDataStructure((Integer) (occupiedblocks.get(k)));
if (me.toholdblocklocks[me.blockcount] == null) {
- me.toholdblocklocks[me.blockcount] = new ReentrantReadWriteLock().readLock();
+ //me.toholdblocklocks[me.blockcount] = new ReentrantReadWriteLock().readLock();
+ me.toholdblocklocks[me.blockcount] = new MYReadWriteLock();
}
- me.toholdblocklocks[me.blockcount] = block.getLock().readLock();
+ //me.toholdblocklocks[me.blockcount] = block.getLock().readLock();
+ me.toholdblocklocks[me.blockcount] = block.getLock();
me.blockcount++;
//me.getHeldblocklocks().add(block.getLock().readLock());
}
for (k = 0; k < occupiedblocks.size(); k++) {
block = this.inodestate.getBlockDataStructure((Integer) (occupiedblocks.get(k)));
if (me.toholdblocklocks[me.blockcount] == null) {
- me.toholdblocklocks[me.blockcount] = new ReentrantReadWriteLock().readLock();
+ me.toholdblocklocks[me.blockcount] = new MYReadWriteLock();
+ //me.toholdblocklocks[me.blockcount] = new ReentrantReadWriteLock().readLock();
}
- me.toholdblocklocks[me.blockcount] = block.getLock().readLock();
+ me.toholdblocklocks[me.blockcount] = block.getLock();
+ //me.toholdblocklocks[me.blockcount] = block.getLock().readLock();
me.blockcount++;
//me.getHeldblocklocks().add(block.getLock().readLock());
}
}
for (k = 0; k < occupiedblocks.size(); k++) {
block = this.inodestate.getBlockDataStructure((Integer) (occupiedblocks.get(k)));
- block.getLock().readLock().unlock();
+ //block.getLock().readLock().unlock();
+ block.getLock().unlockRead();
}
// offsetlock.unlock();
tmp.setLocaloffset(tmp.getLocaloffset() + result);
for (k = st; k <= end /*&& me.getStatus() == Status.ACTIVE*/; k++) {
block = this.inodestate.getBlockDataStructure(Integer.valueOf(k));
- block.getLock().readLock().lock();
+ //block.getLock().readLock().lock();
+ block.getLock().readLock();
// locks[k-st] = block.getLock().readLock();
if (!(block.getReaders().contains(me))) {
//me.blockcount = k - st;
for (int i = st; i < k; i++) {
if (me.toholdblocklocks[me.blockcount] == null) {
- me.toholdblocklocks[me.blockcount] = new ReentrantReadWriteLock().readLock();
+ //me.toholdblocklocks[me.blockcount] = new ReentrantReadWriteLock().readLock();
+ me.toholdblocklocks[me.blockcount] = new MYReadWriteLock();
}
- me.toholdblocklocks[me.blockcount] = block.getLock().readLock();
+ //me.toholdblocklocks[me.blockcount] = block.getLock().readLock();
+ me.toholdblocklocks[me.blockcount] = block.getLock();
me.blockcount++;
// block = this.inodestate.getBlockDataStructure(Integer.valueOf(i));
//me.getHeldblocklocks().add(block.getLock().readLock());
block = this.inodestate.getBlockDataStructure(Integer.valueOf(i));
// me.toholdblocklocks[i-st] = this.inodestate.getBlockDataStructure(Integer.valueOf(i)).getLock().readLock();
if (me.toholdblocklocks[me.blockcount] == null) {
- me.toholdblocklocks[me.blockcount] = new ReentrantReadWriteLock().readLock();
+ //me.toholdblocklocks[me.blockcount] = new ReentrantReadWriteLock().readLock();
+ me.toholdblocklocks[me.blockcount] = new MYReadWriteLock();
}
- me.toholdblocklocks[me.blockcount] = block.getLock().readLock();
+ //me.toholdblocklocks[me.blockcount] = block.getLock().readLock();
+ me.toholdblocklocks[me.blockcount] = block.getLock();
me.blockcount++;
//me.getHeldblocklocks().add(block.getLock().readLock());
// me.toholdblocklocks[me.blockcount] = block.getLock().readLock();
//unlock the locks
for (k = st; k <= end; k++) {
block = this.inodestate.getBlockDataStructure(Integer.valueOf(k));
- block.getLock().readLock().unlock();
+ //block.getLock().readLock().unlock();
+ block.getLock().unlockRead();
//locks[k-st].unlock();
}
return size;
int startblock = FileBlockManager.getCurrentFragmentIndexofTheFile(committedoffset.getOffsetnumber());
int targetblock = FileBlockManager.getTargetFragmentIndexofTheFile(committedoffset.getOffsetnumber(), data.length);
-
- WriteLock[] blocksar;
- blocksar = new WriteLock[targetblock - startblock + 1];
+ //WriteLock[] blocksar;
+ //blocksar = new WriteLock[targetblock - startblock + 1];
+ MYReadWriteLock[] blocksar;
+ blocksar = new MYReadWriteLock[targetblock - startblock + 1];
for (int i = startblock; i <= targetblock; i++) {
BlockDataStructure block = this.inodestate.getBlockDataStructure(i);
- block.getLock().writeLock().lock();
- blocksar[i - startblock] = block.getLock().writeLock();
+ //block.getLock().writeLock().lock();
+ block.getLock().writeLock();
+ //blocksar[i - startblock] = block.getLock().writeLock();
+ blocksar[i - startblock] = block.getLock();
//heldlocks.add(block.getLock().writeLock());
}
} finally {
// unlockLocks(heldlocks);
for (int i = startblock; i <= targetblock; i++) {
- blocksar[i - startblock].unlock();
+ //blocksar[i - startblock].unlock();
+ blocksar[i - startblock].unlockWrite();
}
myoffsetlock.non_Transactional_Release();
//offsetlock.writeLock().unlock();
startblock = FileBlockManager.getCurrentFragmentIndexofTheFile(committedoffset.getOffsetnumber());
targetblock = FileBlockManager.getTargetFragmentIndexofTheFile(committedoffset.getOffsetnumber(), size);
- ReadLock[] blocksar;
- blocksar = new ReadLock[targetblock - startblock + 1];
+ //ReadLock[] blocksar;
+ //blocksar = new ReadLock[targetblock - startblock + 1];
+
+ MYReadWriteLock[] blocksar;
+ blocksar = new MYReadWriteLock[targetblock - startblock + 1];
for (int i = startblock; i <= targetblock; i++) {
BlockDataStructure block = this.inodestate.getBlockDataStructure(i);
- block.getLock().readLock().lock();
- blocksar[i - startblock] = block.getLock().readLock();
+ block.getLock().readLock();
+ blocksar[i - startblock] = block.getLock();
+ //block.getLock().readLock().lock();
+ //blocksar[i - startblock] = block.getLock().readLock();
}
size = invokeNativepread(b, committedoffset.getOffsetnumber(), b.length);
}
for (int i = startblock; i <= targetblock; i++) {
- blocksar[i - startblock].unlock();
+ //blocksar[i - startblock].unlock();
+ blocksar[i - startblock].unlockWrite();
}
//unlockLocks(heldlocks);