From 18cf859615c2a61032f62d07e32300e0f13debe5 Mon Sep 17 00:00:00 2001 From: navid Date: Tue, 10 Feb 2009 17:50:20 +0000 Subject: [PATCH] *** empty log message *** --- .../TransactionalIO/benchmarks/benchmark.java | 1 + .../TransactionalIO/benchmarks/thread1.java | 4 +- .../core/ExtendedTransaction.java | 2 +- .../dstm2/src/dstm2/SpecialLock.java | 33 ++++- .../src/dstm2/SpecialTransactionalFile.java | 134 ++++++++---------- .../Transactions/dstm2/src/dstm2/Thread.java | 20 ++- .../dstm2/src/dstm2/Transaction.java | 11 ++ .../src/dstm2/manager/BackoffManager.java | 2 + .../src/dstm2/manager/SpecialManager.java | 49 +++++-- 9 files changed, 154 insertions(+), 102 deletions(-) diff --git a/Robust/Transactions/TransactionalIO/src/TransactionalIO/benchmarks/benchmark.java b/Robust/Transactions/TransactionalIO/src/TransactionalIO/benchmarks/benchmark.java index 4a31551d..5d557d6d 100644 --- a/Robust/Transactions/TransactionalIO/src/TransactionalIO/benchmarks/benchmark.java +++ b/Robust/Transactions/TransactionalIO/src/TransactionalIO/benchmarks/benchmark.java @@ -196,6 +196,7 @@ public class benchmark { m.put(String.valueOf((char) (index + i)) + "random", new RandomAccessFile("/home/navid/" + String.valueOf((char) (index + i)) + ".text", "rw")); m.put(String.valueOf((char) (index + i)), new TransactionalFile("/home/navid/" + String.valueOf((char) (index + i)) + ".text", "rw")); m.put(String.valueOf((char) (index + i)), new TransactionalFile("/scratch/TransactionalIO/PureIOBenchmarkFiles/" + String.valueOf((char) (index + i)) + ".text", "rw")); + count++; } m.put("counterdstm2output", new RandomAccessFile("/scratch/TransactionalIO/WordCunterBenchmarkFiles/counter_benchmark_output.text", "rw")); diff --git a/Robust/Transactions/TransactionalIO/src/TransactionalIO/benchmarks/thread1.java b/Robust/Transactions/TransactionalIO/src/TransactionalIO/benchmarks/thread1.java index e2174af3..079dd122 100644 --- a/Robust/Transactions/TransactionalIO/src/TransactionalIO/benchmarks/thread1.java +++ b/Robust/Transactions/TransactionalIO/src/TransactionalIO/benchmarks/thread1.java @@ -55,8 +55,8 @@ public class thread1 implements TransactionalProgram{ public void execute() { try { - //TransactionalFile f1 = (TransactionalFile)benchmark.TransactionalFiles.get("0"); - TransactionalFile f1; + TransactionalFile f1 = (TransactionalFile)benchmark.TransactionalFiles.get("0"); + //TransactionalFile f1; if (tf != null) { f1 = tf; } else { diff --git a/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/ExtendedTransaction.java b/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/ExtendedTransaction.java index e804d736..26182aea 100644 --- a/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/ExtendedTransaction.java +++ b/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/ExtendedTransaction.java @@ -205,7 +205,7 @@ public class ExtendedTransaction implements TransactionStatu { //while (iter.hasNext()/* && (this.getStatus() == Status.ACTIVE)*/) { // INode key = (INode) iter.next(); //Vector vec = (Vector) AccessedFiles.get(key); - INode key = entry.getKey(); + //INode key = entry.getKey(); Vector vec = entry.getValue(); Collections.sort(vec); for (int i = 0; i < vec.size(); i++) { diff --git a/Robust/Transactions/dstm2/src/dstm2/SpecialLock.java b/Robust/Transactions/dstm2/src/dstm2/SpecialLock.java index db872b19..dd1338b6 100644 --- a/Robust/Transactions/dstm2/src/dstm2/SpecialLock.java +++ b/Robust/Transactions/dstm2/src/dstm2/SpecialLock.java @@ -7,27 +7,45 @@ package dstm2; import java.util.concurrent.locks.ReentrantLock; +import java.util.logging.Level; +import java.util.logging.Logger; /** * * @author navid */ -public class SpecialLock extends ReentrantLock{ +public class SpecialLock{ private static SpecialLock instance = null; private Transaction ownerTransaction = null; + private boolean locked = false; private SpecialLock() { } public synchronized void lock(Transaction tr){ - super.lock(); - setOwnerTransaction(tr); + try { + //System.out.println("trying to lock " + Thread.currentThread()); + //super.lock(); + while (locked) + wait(); + locked = true; + setOwnerTransaction(tr); + Thread.getTransaction().setIOTransaction(true); + // System.out.println(Thread.currentThread() + " locked the lock"); + } catch (InterruptedException ex) { + Logger.getLogger(SpecialLock.class.getName()).log(Level.SEVERE, null, ex); + } } public synchronized void unlock(Transaction tr){ - super.unlock(); + // System.out.println(Thread.currentThread() + " unlocking the lock"); + //super.unlock(); + locked = false; setOwnerTransaction(null); + Thread.getTransaction().setIOTransaction(false); + notifyAll(); + // System.out.println(Thread.currentThread() + " unlocked the lock"); } public synchronized void setOwnerTransaction(Transaction tr){ @@ -38,13 +56,16 @@ public class SpecialLock extends ReentrantLock{ return ownerTransaction; } - public synchronized static SpecialLock getSpecialLock(){ + public synchronized static SpecialLock getSpecialLock(){ if (instance == null){ + // System.out.println(Thread.currentThread() + " lock"); instance = new SpecialLock(); return instance; } - else + else{ + // System.out.println(Thread.currentThread() + " lock-ret"); return instance; + } } diff --git a/Robust/Transactions/dstm2/src/dstm2/SpecialTransactionalFile.java b/Robust/Transactions/dstm2/src/dstm2/SpecialTransactionalFile.java index 2a3e44bc..bb9b23d1 100644 --- a/Robust/Transactions/dstm2/src/dstm2/SpecialTransactionalFile.java +++ b/Robust/Transactions/dstm2/src/dstm2/SpecialTransactionalFile.java @@ -2,10 +2,9 @@ * To change this template, choose Tools | Templates * and open the template in the editor. */ - package dstm2; -import TransactionalIO.core.Wrapper; + import TransactionalIO.exceptions.AbortedException; import java.io.File; import java.io.FileNotFoundException; @@ -16,10 +15,10 @@ import java.io.RandomAccessFile; * * @author navid */ -public class SpecialTransactionalFile{ - - RandomAccessFile raFile; - +public class SpecialTransactionalFile { + + public RandomAccessFile raFile; + public SpecialTransactionalFile(File arg0, String arg1) throws FileNotFoundException { raFile = new RandomAccessFile(arg0, arg1); } @@ -28,199 +27,180 @@ public class SpecialTransactionalFile{ raFile = new RandomAccessFile(arg0, arg1); } - - private void checkConsisteny(){ - // System.out.println(Thread.currentThread()); + private void checkConsisteny() { + Transaction me = Thread.getTransaction(); + if (me == null) + return; + if (!me.isActive()) { - SpecialLock.getSpecialLock().unlock(me); - throw new AbortedException(); + + throw new AbortedException(); } - if (me != SpecialLock.getSpecialLock().getOwnerTransaction()){ - // System.out.println("trying to lock " + Thread.currentThread()); + + if (me != SpecialLock.getSpecialLock().getOwnerTransaction()) { + //if (!(me.isIOTransaction())){ SpecialLock.getSpecialLock().lock(me); - // System.out.println("locked " + Thread.currentThread()); } - + if (!me.isActive()) { - SpecialLock.getSpecialLock().unlock(me); - throw new AbortedException(); + throw new AbortedException(); } - + } - - + public void close() throws IOException { checkConsisteny(); raFile.close(); } - public long getFilePointer() throws IOException { checkConsisteny(); return raFile.getFilePointer(); } - public long length() throws IOException { checkConsisteny(); return raFile.length(); } - public int read() throws IOException { checkConsisteny(); return raFile.read(); } - public int read(byte[] arg0, int arg1, int arg2) throws IOException { checkConsisteny(); return raFile.read(arg0, arg1, arg2); } - public int read(byte[] arg0) throws IOException { checkConsisteny(); return raFile.read(arg0); } - public void seek(long arg0) throws IOException { checkConsisteny(); raFile.seek(arg0); } - public void setLength(long arg0) throws IOException { checkConsisteny(); raFile.setLength(arg0); } - public int skipBytes(int arg0) throws IOException { checkConsisteny(); return raFile.skipBytes(arg0); } - public void write(int arg0) throws IOException { checkConsisteny(); raFile.write(arg0); } - public void write(byte[] arg0) throws IOException { checkConsisteny(); raFile.write(arg0); } - public void write(byte[] arg0, int arg1, int arg2) throws IOException { checkConsisteny(); raFile.write(arg0, arg1, arg2); } - - public final void writeInt(int integer) throws IOException{ + + public final void writeInt(int integer) throws IOException { checkConsisteny(); raFile.writeInt(integer); } - - public final int readInt() throws IOException{ + + public final int readInt() throws IOException { checkConsisteny(); return raFile.readInt(); } - - public final void writeBoolean(boolean bool) throws IOException{ + + public final void writeBoolean(boolean bool) throws IOException { checkConsisteny(); raFile.writeBoolean(bool); } - - public final boolean readBoolean() throws IOException{ + + public final boolean readBoolean() throws IOException { checkConsisteny(); return raFile.readBoolean(); } - - public final void writeUTF(String val) throws IOException{ + + public final void writeUTF(String val) throws IOException { checkConsisteny(); raFile.writeUTF(val); } - - public final String readUTF() throws IOException{ + + public final String readUTF() throws IOException { checkConsisteny(); return raFile.readUTF(); } - - public final void writeShort(short val) throws IOException{ + + public final void writeShort(short val) throws IOException { checkConsisteny(); raFile.writeShort(val); } - - public final short readShort() throws IOException{ + + public final short readShort() throws IOException { checkConsisteny(); return raFile.readShort(); } - - public final void writeByte(byte arg0) throws IOException{ + + public final void writeByte(byte arg0) throws IOException { checkConsisteny(); raFile.writeByte(arg0); } - - public final byte readByte() throws IOException{ + + public final byte readByte() throws IOException { checkConsisteny(); return raFile.readByte(); } - - public final void writeChar(int val) throws IOException{ + + public final void writeChar(int val) throws IOException { checkConsisteny(); raFile.writeChar(val); } - - public final char readChar() throws IOException{ + + public final char readChar() throws IOException { checkConsisteny(); return raFile.readChar(); } - - public final void writeBytes(String val) throws IOException{ + + public final void writeBytes(String val) throws IOException { checkConsisteny(); raFile.writeBytes(val); } - - public final void writeLong(long val) throws IOException{ + + public final void writeLong(long val) throws IOException { checkConsisteny(); raFile.writeLong(val); } - - public final long readLong() throws IOException{ + + public final long readLong() throws IOException { checkConsisteny(); return raFile.readLong(); } - - public final void writeDouble(double arg0) throws IOException{ + + public final void writeDouble(double arg0) throws IOException { checkConsisteny(); raFile.writeDouble(arg0); } - - public final double readDouble() throws IOException{ + + public final double readDouble() throws IOException { checkConsisteny(); return raFile.readDouble(); } - - public final void writeFloat(float val) throws IOException{ + + public final void writeFloat(float val) throws IOException { checkConsisteny(); raFile.writeFloat(val); } - - public final float readFloat() throws IOException{ + + public final float readFloat() throws IOException { checkConsisteny(); return raFile.readFloat(); } - - - - - - - - } diff --git a/Robust/Transactions/dstm2/src/dstm2/Thread.java b/Robust/Transactions/dstm2/src/dstm2/Thread.java index f7da48d3..63f21935 100644 --- a/Robust/Transactions/dstm2/src/dstm2/Thread.java +++ b/Robust/Transactions/dstm2/src/dstm2/Thread.java @@ -251,13 +251,16 @@ public class Thread extends java.lang.Thread{ try { while (true) { threadState.beginTransaction(); + // System.out.println(Thread.currentThread() + " offically started the transaction"); /////For Integrating with IO////////// Wrapper.Initialize(Thread.getTransaction()); + //System.out.println(Thread.currentThread() + " starting"); // System.out.println(Thread.currentThread() + " even more offically started the transaction"); ////////////////////////////////////// try { result = xaction.call(); + // System.out.println(Thread.currentThread() + " starting2"); // System.out.println(Thread.currentThread() + " aborted in committing"); // } catch (AbortedException d) { /* synchronized(benchmark.lock){ @@ -281,13 +284,16 @@ public class Thread extends java.lang.Thread{ if (threadState.commitTransaction()) { threadState.committedMemRefs += threadState.transaction.memRefs; + + Wrapper.realseOffsets(); + Wrapper.commitIO(); flag = true; } } catch(AbortedException ex){ threadState.depth--; - // System.out.println(Thread.currentThread() + " aborted"); + //System.out.println(Thread.currentThread() + " aborted"); // Wrapper.getTransaction().unlockAllLocks(); } catch (Exception e) { @@ -298,14 +304,20 @@ public class Thread extends java.lang.Thread{ // System.out.println("here " + Thread.currentThread()); Wrapper.getTransaction().unlockAllLocks(); + if (Thread.getTransaction() == SpecialLock.getSpecialLock().getOwnerTransaction()){ - // System.out.println("herein " + Thread.currentThread()); + //if (Thread.getTransaction().isIOTransaction()){ + + // System.out.println("herein " + Thread.currentThread()); SpecialLock.getSpecialLock().unlock(Thread.getTransaction()); + // System.out.println("here"); - + /// } - if (flag == true) + if (flag == true){ + // System.out.println(Thread.currentThread() + " committed"); break; + } } // transaction aborted diff --git a/Robust/Transactions/dstm2/src/dstm2/Transaction.java b/Robust/Transactions/dstm2/src/dstm2/Transaction.java index 76205241..31cc2403 100644 --- a/Robust/Transactions/dstm2/src/dstm2/Transaction.java +++ b/Robust/Transactions/dstm2/src/dstm2/Transaction.java @@ -48,6 +48,9 @@ public class Transaction implements TransactionStatu{ private TransactionStatu othersystem; private boolean flag = true; + private boolean IOTransaction = false; + + /** * Possible transaction status **/ @@ -288,4 +291,12 @@ public class Transaction implements TransactionStatu{ public void abortThisSystem() { abort(); } + + public boolean isIOTransaction() { + return IOTransaction; + } + + public void setIOTransaction(boolean IOTransaction) { + this.IOTransaction = IOTransaction; + } } diff --git a/Robust/Transactions/dstm2/src/dstm2/manager/BackoffManager.java b/Robust/Transactions/dstm2/src/dstm2/manager/BackoffManager.java index 30f175ba..afa372cf 100644 --- a/Robust/Transactions/dstm2/src/dstm2/manager/BackoffManager.java +++ b/Robust/Transactions/dstm2/src/dstm2/manager/BackoffManager.java @@ -58,6 +58,7 @@ public class BackoffManager extends BaseManager { currentAttempt = 0; } public void resolveConflict(Transaction me, Transaction other) { + // if (currentAttempt <= MAX_RETRIES) { if (!other.isActive()) { return; @@ -78,6 +79,7 @@ public class BackoffManager extends BaseManager { } } public void resolveConflict(Transaction me, Collection others) { + if (currentAttempt <= MAX_RETRIES) { int logBackoff = currentAttempt - 2 + MIN_LOG_BACKOFF; if (logBackoff > MAX_LOG_BACKOFF) { diff --git a/Robust/Transactions/dstm2/src/dstm2/manager/SpecialManager.java b/Robust/Transactions/dstm2/src/dstm2/manager/SpecialManager.java index 6f50871a..21b711d9 100644 --- a/Robust/Transactions/dstm2/src/dstm2/manager/SpecialManager.java +++ b/Robust/Transactions/dstm2/src/dstm2/manager/SpecialManager.java @@ -2,33 +2,58 @@ * To change this template, choose Tools | Templates * and open the template in the editor. */ - package dstm2.manager; +import TransactionalIO.core.Wrapper; import dstm2.SpecialLock; import dstm2.Transaction; +import java.util.Collection; /** * * @author navid */ -public class SpecialManager extends PriorityManager{ - +public class SpecialManager extends BackoffManager { + + @Override public void resolveConflict(Transaction me, Transaction other) { - if (me == SpecialLock.getSpecialLock().getOwnerTransaction()) + + if (me == SpecialLock.getSpecialLock().getOwnerTransaction()) { other.abort(); - else if (other == SpecialLock.getSpecialLock().getOwnerTransaction()) + } else if (other == SpecialLock.getSpecialLock().getOwnerTransaction()) { me.abort(); - - else + } + else { super.resolveConflict(me, other); - } + } + } + + @Override + public void resolveConflict(Transaction me, Collection others) { + + if (me == SpecialLock.getSpecialLock().getOwnerTransaction()) { + for (Transaction other : others) { + if (other.isActive() && other != me) { + other.abort(); + } + } + return; + } + else for (Transaction other : others) { + if (other == SpecialLock.getSpecialLock().getOwnerTransaction()){ + me.abort(); + return; + } + } + + super.resolveConflict(me, others); + } - public long getPriority() { + public long getPriority() { throw new UnsupportedOperationException(); - } + } - public void setPriority(long value) { + public void setPriority(long value) { throw new UnsupportedOperationException(); - } + } } -- 2.34.1