*/
public class ExtendedTransaction implements TransactionStatu {
- private native int nativepwrite(byte buff[], long offset, int size, FileDescriptor fd);
+ private static native int nativepwrite(byte buff[], long offset, int size, FileDescriptor fd);
{
ABORTED, ACTIVE, COMMITTED
};
private boolean writesmerged = true;
+ private Vector heldlengthlocks;
//private Vector<ReentrantLock> heldoffsetlocks;
private Vector heldoffsetlocks;
//private Vector<ReentrantLock> heldblocklocks;
private ContentionManager contentionmanager;
private volatile Status status;
private int id;
+
+
+ public ReentrantLock[] toholoffsetlocks;
+ public int offsetcount = 0;
+
+ public Lock[] toholdblocklocks;
+ public int blockcount = 0;
public ExtendedTransaction() {
// super();
// id = Integer.valueOf(Thread.currentThread().getName().substring(7));
+ heldlengthlocks = new Vector();
heldblocklocks = new Vector();
heldoffsetlocks = new Vector();
AccessedFiles = new HashMap();
this.memorystate = memorystate;
}
- private int invokeNativepwrite(byte buff[], long offset, int size, RandomAccessFile file) {
+ public static int invokeNativepwrite(byte buff[], long offset, int size, RandomAccessFile file) {
try {
return nativepwrite(buff, offset, buff.length, file.getFD());
} catch (IOException ex) {
public void addFile(TransactionalFile tf, long offsetnumber/*, TransactionLocalFileAttributes tmp*/) {
- TransactionLocalFileAttributes tmp = new TransactionLocalFileAttributes(offsetnumber/*, tf.getInodestate().commitedfilesize.get()*/);
+ TransactionLocalFileAttributes tmp = new TransactionLocalFileAttributes(offsetnumber, tf.getInodestate().commitedfilesize.getLength());
Vector dummy;
if (AccessedFiles.containsKey(tf.getInode())) {
public boolean lockOffsets() { /// Locking offsets for File Descriptors
-
+ // toholoffsetlocks = new ReentrantLock[30];
+
TreeMap hm = getSortedFileAccessMap(AccessedFiles);
Iterator iter = hm.keySet().iterator();
-
+ offsetcount = 0;
while (iter.hasNext() && (this.getStatus() == Status.ACTIVE)) {
INode key = (INode) iter.next();
Vector vec = (Vector) AccessedFiles.get(key);
+
+ /* if (vec.size() == 1){
+ TransactionalFile tf = ((TransactionalFile)vec.firstElement());
+ tf.offsetlock.lock();
+ // toholoffsetlocks[offsetcount] = tf.offsetlock;
+ // offsetcount++;
+ heldoffsetlocks.add(tf.offsetlock);
+ continue;
+ }*/
+
Collections.sort(vec);
Iterator it = vec.iterator();
- while (it.hasNext() && this.getStatus() == Status.ACTIVE) {
- TransactionalFile value = (TransactionalFile) it.next();
- value.offsetlock.lock();
+ while (it.hasNext() /*&& this.getStatus() == Status.ACTIVE*/) {
+ TransactionalFile value = (TransactionalFile) it.next();
+ value.offsetlock.lock();
+ // toholoffsetlocks[offsetcount] = value.offsetlock;
+ // offsetcount++;
heldoffsetlocks.add(value.offsetlock);
+
+ if (((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(value)).lenght_read){
+ if (!(value.getInodestate().commitedfilesize.lengthlock.isHeldByCurrentThread())){
+ value.getInodestate().commitedfilesize.lengthlock.lock();
+ heldlengthlocks.add(value.getInodestate().commitedfilesize.lengthlock);
+ }
+ }
break;
}
}
if (this.getStatus() != Status.ACTIVE) {
+ // for (int j=0; j<offsetcount; j++){
+ // heldoffsetlocks.add(toholoffsetlocks[j]);
+ // }
return false;
}
return true;
}
+
+
+
public boolean lockBlock(BlockDataStructure block, BlockAccessModesEnum mode/*, GlobalINodeState adapter, BlockAccessModesEnum mode, int expvalue, INode inode, TransactionLocalFileAttributes tf*/) {
}
lock.lock();
+ // toholdblocklocks[blockcount] = lock;
+ // blockcount++;
heldblocklocks.add(lock);
return true;
if (this.status != Status.ACTIVE) {
throw new AbortedException();
}
- boolean ok = true;
+ boolean offsetsok = true;
if (!lockOffsets()) {
throw new AbortedException();
}
+
+ // boolean lengthslock = true;
+ // if (!lockOffsets()) {
+ // throw new AbortedException();
+ // }
///////////////////////////
Iterator iter = hm.keySet().iterator();
WriteOperations value;
Vector vec = new Vector();
- while (iter.hasNext() && (this.getStatus() == Status.ACTIVE) && ok) {
+ while (iter.hasNext() && (this.getStatus() == Status.ACTIVE) && offsetsok) {
INode key = (INode) iter.next();
vec = (Vector) hm.get(key);
Collections.sort(vec);
}
+ //toholdblocklocks = new Lock[100];
Iterator it = this.getAccessedBlocks().keySet().iterator();
BlockDataStructure[] blocks = new BlockDataStructure[100];
- if (this.getStatus() == Status.ACTIVE)
+ //if (this.getStatus() == Status.ACTIVE)
while (it.hasNext() /*&& (this.getStatus() == Status.ACTIVE)*/) {
INode inode = (INode) it.next();
GlobalINodeState inodestate = TransactionalFileWrapperFactory.getTateransactionalFileINodeState(inode);
}
if (this.getStatus() != Status.ACTIVE) {
-
+ // for (int i=0; i<blockcount; i++)
+ // heldblocklocks.add(toholdblocklocks[i]);
throw new AbortedException();
}
abortAllReaders();
Iterator it;
WriteOperations writeop;
Vector vec;
- while (iter.hasNext() && (this.getStatus() == Status.ACTIVE)) {
+ while (iter.hasNext()) {
INode key = (INode) iter.next();
vec = (Vector) hm.get(key);
while (k.hasNext()) {
TransactionalFile trf = (TransactionalFile) (k.next());
trf.getCommitedoffset().setOffsetnumber(((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(trf)).getLocaloffset());
+ if (((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(trf)).getInitiallocallength() != ((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(trf)).getLocalsize()){
+ try {
+ if (!(trf.getInodestate().commitedfilesize.lengthlock.isHeldByCurrentThread()))
+ trf.getInodestate().commitedfilesize.lengthlock.lock();
+
+ Iterator it2 = trf.getInodestate().commitedfilesize.getLengthReaders().iterator();
+ if (((TransactionLocalFileAttributes)getGlobaltoLocalMappings().get(trf)).getInitiallocallength() != ((TransactionLocalFileAttributes)getGlobaltoLocalMappings().get(trf)).getLocalsize())
+ {
+ while (it2.hasNext()) {
+ ExtendedTransaction tr = (ExtendedTransaction) it2.next();
+ if (tr != this) {
+ tr.abort();
+ }
+ }
+ trf.getInodestate().commitedfilesize.getLengthReaders().clear();
+ }
+ trf.getInodestate().commitedfilesize.setLength(trf.file.length());
+
+ if (trf.getInodestate().commitedfilesize.lengthlock.isHeldByCurrentThread()){
+ heldlengthlocks.remove(trf.getInodestate().commitedfilesize.lengthlock);
+ trf.getInodestate().commitedfilesize.lengthlock.unlock();
+ }
+
+ } catch (IOException ex) {
+ Logger.getLogger(ExtendedTransaction.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ if (((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(trf)).lenght_read){
+ trf.getInodestate().commitedfilesize.getLengthReaders().remove(this);
+ heldlengthlocks.remove(trf.getInodestate().commitedfilesize.lengthlock);
+ trf.getInodestate().commitedfilesize.lengthlock.unlock();
+ }
}
+
+
+ /* for (int i =0; i<blockcount; i++){
+ toholdblocklocks[i].unlock();
+ }
+ for (int i =0; i<offsetcount; i++){
+ toholoffsetlocks[i].unlock();
+ }*/
}
public void unlockAllLocks() {
Lock lock = (Lock) it.next();
lock.unlock();
}
- // heldblocklocks.clear();
+ heldblocklocks.clear();
it = heldoffsetlocks.iterator();
while (it.hasNext()) {
ReentrantLock lock = (ReentrantLock) it.next();
lock.unlock();
}
- // heldoffsetlocks.clear();
+ heldoffsetlocks.clear();
+
+ it = heldlengthlocks.iterator();
+ while (it.hasNext()) {
+ ReentrantLock lock = (ReentrantLock) it.next();
+ lock.unlock();
+ }
+ heldlengthlocks.clear();
}
public void abortAllReaders() {
}
}
value.getCommitedoffset().getOffsetReaders().clear();
+
+
+
}
TreeMap vec2;
}
}
+
+
public void addPropertyChangeListener(PropertyChangeListener listener) {
this.changes.addPropertyChangeListener("status", listener);
public Vector getHeldoffsetlocks() {
return heldoffsetlocks;
}
+
+ public Vector getHeldlengthlocks() {
+ return heldlengthlocks;
+ }
public void setHeldoffsetlocks(Vector heldoffsetlocks) {
this.heldoffsetlocks = heldoffsetlocks;