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"));
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 {
//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++) {
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){
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;
+ }
}
* 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;
*
* @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);
}
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();
}
-
-
-
-
-
-
-
-
}
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){
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) {
// 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
private TransactionStatu othersystem;
private boolean flag = true;
+ private boolean IOTransaction = false;
+
+
/**
* Possible transaction status
**/
public void abortThisSystem() {
abort();
}
+
+ public boolean isIOTransaction() {
+ return IOTransaction;
+ }
+
+ public void setIOTransaction(boolean IOTransaction) {
+ this.IOTransaction = IOTransaction;
+ }
}
currentAttempt = 0;
}
public void resolveConflict(Transaction me, Transaction other) {
+ //
if (currentAttempt <= MAX_RETRIES) {
if (!other.isActive()) {
return;
}
}
public void resolveConflict(Transaction me, Collection<Transaction> others) {
+
if (currentAttempt <= MAX_RETRIES) {
int logBackoff = currentAttempt - 2 + MIN_LOG_BACKOFF;
if (logBackoff > MAX_LOG_BACKOFF) {
* 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<Transaction> 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();
- }
+ }
}