From 6b461432e13ee06d01d815f2a174cf6f5e416a34 Mon Sep 17 00:00:00 2001 From: navid Date: Mon, 26 Jan 2009 07:07:45 +0000 Subject: [PATCH] *** empty log message *** --- .../Utilities/Conversions.java | 202 ++++++++++++++++++ .../core/ExtendedTransaction.java | 11 +- .../core/GlobalINodeState.java | 1 + .../TransactionalIO/core/GlobalLength.java | 2 + .../src/TransactionalIO/core/INode.java | 2 +- .../core/TransactionalFile.java | 74 ++++--- .../dstm2/src/dstm2/factory/BaseFactory.java | 5 +- .../src/dstm2/util/StringKeyHashMap.java | 27 +-- .../tuplesoup/core/DualFileTable.java | 3 + .../core/DualFileTableTransactional.java | 141 ++++++------ .../tuplesoup/core/HashedTable.java | 2 +- .../core/IndexedTableReaderTransactional.java | 3 + .../tuplesoup/core/PagedIndex.java | 4 + .../core/PagedIndexTransactional.java | 16 +- .../tuplesoup/core/RowTransactional.java | 6 + .../tuplesoup/core/TableIndexEntry.java | 1 + .../core/TableIndexEntryTransactional.java | 37 ++-- .../core/TableIndexNodeTransactional.java | 15 +- .../tuplesoup/core/TableIndexPage.java | 26 ++- .../core/TableIndexPageTransactional.java | 47 +++- .../tuplesoup/core/ValueTransactional.java | 75 ++++--- .../test/OrigParralelPerformanceTest.java | 174 +++++++++++++++ .../tuplesoup/test/OrigParralelThread.java | 74 +++++++ .../test/ParallelPerformanceTest.java | 50 +++-- .../tuplesoup/test/ParallelThread.java | 13 +- 25 files changed, 813 insertions(+), 198 deletions(-) create mode 100644 Robust/Transactions/TransactionalIO/src/TransactionalIO/Utilities/Conversions.java create mode 100644 Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/test/OrigParralelPerformanceTest.java create mode 100644 Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/test/OrigParralelThread.java diff --git a/Robust/Transactions/TransactionalIO/src/TransactionalIO/Utilities/Conversions.java b/Robust/Transactions/TransactionalIO/src/TransactionalIO/Utilities/Conversions.java new file mode 100644 index 00000000..de8763f7 --- /dev/null +++ b/Robust/Transactions/TransactionalIO/src/TransactionalIO/Utilities/Conversions.java @@ -0,0 +1,202 @@ +package TransactionalIO.Utilities; + +/* ============================================================= + * SmallSQL : a free Java DBMS library for the Java(tm) platform + * ============================================================= + * + * (C) Copyright 2004-2007, by Volker Berlin. + * + * Project Info: http://www.smallsql.de/ + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * --------------- + * Utils.java + * --------------- + * Author: Volker Berlin + * + */ + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.RandomAccessFile; +import java.nio.channels.FileLock; +import java.sql.SQLException; + + +public class Conversions { + + + + + public static int long2int(long value){ + if(value > Integer.MAX_VALUE) + return Integer.MAX_VALUE; + if(value < Integer.MIN_VALUE) + return Integer.MIN_VALUE; + return (int)value; + } + + public static long double2long(double value){ + if(value > Long.MAX_VALUE) + return Long.MAX_VALUE; + if(value < Long.MIN_VALUE) + return Long.MIN_VALUE; + return (long)value; + } + + + + public static float bytes2float( byte[] bytes ){ + return Float.intBitsToFloat( bytes2int( bytes ) ); + } + + public static double bytes2double( byte[] bytes ){ + return Double.longBitsToDouble( bytes2long( bytes ) ); + } + + public static long bytes2long( byte[] bytes ){ + long result = 0; + int length = Math.min( 8, bytes.length); + for(int i=0; i> 56); + result[1] = (byte)(value >> 48); + result[2] = (byte)(value >> 40); + result[3] = (byte)(value >> 32); + result[4] = (byte)(value >> 24); + result[5] = (byte)(value >> 16); + result[6] = (byte)(value >> 8); + result[7] = (byte)(value); + return result; + } + + public static int money2int( long value ) { + if (value < Integer.MIN_VALUE) return Integer.MIN_VALUE; + else if (value > Integer.MAX_VALUE) return Integer.MAX_VALUE; + else return (int) value; + } + + public static byte[] int2bytes( int value ){ + byte[] result = new byte[4]; + result[0] = (byte)(value >> 24); + result[1] = (byte)(value >> 16); + result[2] = (byte)(value >> 8); + result[3] = (byte)(value); + return result; + } + + + + + + private static int hexDigit2int(char digit){ + if(digit >= '0' && digit <= '9') return digit - '0'; + digit |= 0x20; + if(digit >= 'a' && digit <= 'f') return digit - 'W'; // -'W' == -'a' + 10 + throw new RuntimeException(); + } + + + + + static boolean string2boolean( String val){ + try{ + return Double.parseDouble( val ) != 0; + }catch(NumberFormatException e){/*ignore it if it not a number*/} + return "true".equalsIgnoreCase( val ) || "yes".equalsIgnoreCase( val ) || "t".equalsIgnoreCase( val ); + } + + + static long doubleToMoney(double value){ + if(value < 0) + return (long)(value * 10000 - 0.5); + return (long)(value * 10000 + 0.5); + } + + static int indexOf( char value, char[] str, int offset, int length ){ + value |= 0x20; + for(int end = offset+length;offset < end; offset++){ + if((str[offset] | 0x20) == value) return offset; + } + return -1; + } + + public static int indexOf( int value, int[] list ){ + int offset = 0; + for(int end = list.length; offset < end; offset++){ + if((list[offset]) == value) return offset; + } + return -1; + } + + public static int indexOf( byte[] value, byte[] list, int offset ){ + int length = value.length; + loop1: + for(int end = list.length-length; offset <= end; offset++){ + for(int i=0; i other.getNumber()) return 1; else{ - System.out.println("Logical Eroor Two Inodes cannot have the same number"); + System.out.println("Logical Error Two Inodes cannot have the same number" + this.filepath + " " + other.filepath); return 0; } diff --git a/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/TransactionalFile.java b/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/TransactionalFile.java index 9f5be140..22bac250 100644 --- a/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/TransactionalFile.java +++ b/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/TransactionalFile.java @@ -4,6 +4,7 @@ */ package TransactionalIO.core; +import TransactionalIO.Utilities.Conversions; import TransactionalIO.Utilities.Range; import TransactionalIO.exceptions.AbortedException; import TransactionalIO.exceptions.PanicException; @@ -122,10 +123,24 @@ public class TransactionalFile implements Comparable { } } + /* synchronized(this){ + if (to_be_created){ + try { + offsetlock = new ReentrantLock(); + file = new RandomAccessFile(filename, mode); + try { + System.out.println("ll " + file.length()); + } catch (IOException ex) { + Logger.getLogger(TransactionalFile.class.getName()).log(Level.SEVERE, null, ex); + } + } catch (FileNotFoundException ex) { + Logger.getLogger(TransactionalFile.class.getName()).log(Level.SEVERE, null, ex); + } + } + }*/ inode = TransactionalFileWrapperFactory.getINodefromFileName(filename); inodestate = TransactionalFileWrapperFactory.createTransactionalFile(inode, filename, mode); - - + sequenceNum = inodestate.seqNum; inodestate.seqNum++; @@ -138,7 +153,6 @@ public class TransactionalFile implements Comparable { if (inodestate != null) { synchronized (inodestate) { committedoffset = new GlobalOffset(0); - } } @@ -147,6 +161,8 @@ public class TransactionalFile implements Comparable { private int invokeNativepread(byte buff[], long offset, int size) { try { + + return nativepread(buff, offset, size, file.getFD()); } catch (IOException ex) { @@ -199,7 +215,12 @@ public class TransactionalFile implements Comparable { ExtendedTransaction me = Wrapper.getTransaction(); if (me == null) { - return non_Transactional_getFilePointer(); + long length = -1; + inodestate.commitedfilesize.lengthlock.lock(); + length = inodestate.commitedfilesize.getLength(); + inodestate.commitedfilesize.lengthlock.unlock(); + + return length; } if (!(me.getGlobaltoLocalMappings().containsKey(this))) { @@ -310,11 +331,11 @@ public class TransactionalFile implements Comparable { return 0; } pos = getFilePointer(); - len = length(); + // len = length(); newpos = pos + n; - if (newpos > len) { - newpos = len; - } + // if (newpos > len) { + // newpos = len; + // } seek(newpos); /* return the actual number of bytes skipped */ @@ -339,21 +360,28 @@ public class TransactionalFile implements Comparable { byte[] data = new byte[2]; read(data); int result = (short)((data[0] << 8) | data[1]); + System.out.println("res " + result); return result; } public final int readInt(){ byte[] data = new byte[4]; - read(data); - int result = (data[0] << 24) | (data[1] << 16) + (data[2] << 8) + data[3]; + int k = read(data); + + int result = Conversions.bytes2int(data); + //int result = (data[0] << 24) | (data[1] << 16) + (data[2] << 8) + (data[3]<<0); + System.out.println("int res " + result); return result; } public final long readLong(){ + //long result = ((long)(readInt()) << 32) + (readInt() & 0xFFFFFFFFL); byte[] data = new byte[8]; read(data); - long result = ((long)data[0] << 56) + ((long)data[1] << 48) + ((long)data[2] << 40) + ((long)data[3] << 32) + ((long)data[4] << 24) + ((long)data[5] << 16)+ ((long)data[6] << 8) + data[7]; + //long result = ((long)data[0] << 56) + ((long)data[1] << 48) + ((long)data[2] << 40) + ((long)data[3] << 32) + ((long)data[4] << 24) + ((long)data[5] << 16)+ ((long)data[6] << 8) + data[7]; + long result = Conversions.bytes2long(data); + System.out.println("long res " + result); return result; } @@ -397,9 +425,9 @@ public class TransactionalFile implements Comparable { public final void writeInt(int value){ try { byte[] result = new byte[4]; - result[0] = (byte) (value >> 24); - result[1] = (byte) (value >> 16); - result[2] = (byte) (value >> 8); + result[0] = (byte) (value >>> 24 & 0xFF); + result[1] = (byte) (value >>> 16 & 0xFF); + result[2] = (byte) (value >>> 8 & 0xFF); result[3] = (byte) (value); write(result); } catch (IOException ex) { @@ -414,14 +442,14 @@ public class TransactionalFile implements Comparable { public final void writeLong(long value){ try { - byte[] result = new byte[4]; - result[0] = (byte)(value >> 56); - result[1] = (byte)(value >> 48); - result[2] = (byte)(value >> 40); - result[3] = (byte)(value >> 32); - result[4] = (byte)(value >> 24); - result[5] = (byte)(value >> 16); - result[6] = (byte)(value >> 8); + byte[] result = new byte[8]; + result[0] = (byte)(value >>> 56); + result[1] = (byte)(value >>> 48); + result[2] = (byte)(value >>> 40); + result[3] = (byte)(value >>> 32); + result[4] = (byte)(value >>> 24); + result[5] = (byte)(value >>> 16); + result[6] = (byte)(value >>> 8); result[7] = (byte)(value); write(result); } catch (IOException ex) { @@ -517,7 +545,6 @@ public class TransactionalFile implements Comparable { int size = b.length; int result = 0; if (me == null) { // not a transaction, but any I/O operation even though within a non-transaction is considered a single opertion transactiion - return non_Transactional_Read(b); } @@ -870,7 +897,6 @@ public class TransactionalFile implements Comparable { public void lockOffset(ExtendedTransaction me) { boolean locked = false; if (me.getStatus() == Status.ACTIVE) { //locking the offset - offsetlock.lock(); locked = true; } diff --git a/Robust/Transactions/dstm2/src/dstm2/factory/BaseFactory.java b/Robust/Transactions/dstm2/src/dstm2/factory/BaseFactory.java index 82431bff..4a0a1abe 100644 --- a/Robust/Transactions/dstm2/src/dstm2/factory/BaseFactory.java +++ b/Robust/Transactions/dstm2/src/dstm2/factory/BaseFactory.java @@ -152,7 +152,10 @@ public abstract class BaseFactory implements Factory { if (method.getName().substring(0,3).equals("get") && !method.getDeclaringClass().getCanonicalName().contains("dstm2.util.LinkedList") && !method.getDeclaringClass().getCanonicalName().contains("dstm2.util.Hashtable") && - !method.getDeclaringClass().getCanonicalName().contains("dstm2.util.HashMap")) { + !method.getDeclaringClass().getCanonicalName().contains("dstm2.util.HashMap") && + !method.getDeclaringClass().getCanonicalName().contains("com.solidosystems.tuplesoup.core.TableIndexPageTransactional") && + !method.getDeclaringClass().getCanonicalName().contains("com.solidosystems.tuplesoup.core.TableIndexNodeTransactional") && + !method.getDeclaringClass().getCanonicalName().contains("dstm2.util.StringKeyHashMap")){ if (!isAtomicOrScalar(method.getReturnType())) { throw new PanicException("Method %s return type %s not scalar or atomic.", method.getName(), method.getReturnType().getName()); diff --git a/Robust/Transactions/dstm2/src/dstm2/util/StringKeyHashMap.java b/Robust/Transactions/dstm2/src/dstm2/util/StringKeyHashMap.java index dde4153d..e7310dac 100644 --- a/Robust/Transactions/dstm2/src/dstm2/util/StringKeyHashMap.java +++ b/Robust/Transactions/dstm2/src/dstm2/util/StringKeyHashMap.java @@ -719,29 +719,30 @@ public class StringKeyHashMap implements Itera } } -// private class EntryIterator extends HashIterator> { -// public Map.Entry next() { -// return nextEntry(); -// } -// } + private class EntryIterator extends HashIterator> { + public StringKeyHashMap.TEntry next() { + return nextEntry(); + } + } // Subclass overrides these to alter behavior of views' iterator() method public Iterator newKeyIterator() { return new KeyIterator(); } public Iterator newValueIterator() { + return new ValueIterator(); } -// Iterator> newEntryIterator() { -// return new EntryIterator(); -// } + Iterator> newEntryIterator() { + return new EntryIterator(); + } // Views private transient Set> entrySet = null; - + private class KeySet extends AbstractSet { public Iterator iterator() { @@ -781,10 +782,10 @@ public class StringKeyHashMap implements Itera return (es != null ? es : (entrySet = (Set>) (Set) new EntrySet())); } - private class EntrySet {//extends AbstractSet/*>*/ { -// public Iterator/*>*/ iterator() { -// return newEntryIterator(); -// } + private class EntrySet extends AbstractSet>{//extends AbstractSet/*>*/ { + public Iterator/*>*/ iterator() { + return newEntryIterator(); + } public boolean contains(StringKeyHashMap.TEntry o) { StringKeyHashMap.TEntry e = (StringKeyHashMap.TEntry) o; TEntry candidate = getEntry(e.getHash()); diff --git a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/DualFileTable.java b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/DualFileTable.java index 8bfbe140..f4f17d13 100644 --- a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/DualFileTable.java +++ b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/DualFileTable.java @@ -143,6 +143,7 @@ public class DualFileTable implements Table{ if(!this.location.endsWith(File.separator))this.location+=File.separator; switch(indextype){ case PAGED : index=new PagedIndex(getFileName(INDEX)); + break; } @@ -217,12 +218,14 @@ public class DualFileTable implements Table{ private synchronized void openFile(int type) throws IOException{ switch(type){ case FILEA : if(fileastream==null){ + System.out.println("file a " + getFileName(FILEA)); fileastream=new DataOutputStream(new BufferedOutputStream(new FileOutputStream(getFileName(FILEA),true))); File ftest=new File(getFileName(FILEA)); fileaposition=ftest.length(); } break; case FILEB : if(filebstream==null){ + System.out.println("file b " + getFileName(FILEB)); filebstream=new DataOutputStream(new BufferedOutputStream(new FileOutputStream(getFileName(FILEB),true))); File ftest=new File(getFileName(FILEB)); filebposition=ftest.length(); diff --git a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/DualFileTableTransactional.java b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/DualFileTableTransactional.java index b55c46c6..483b0e9d 100644 --- a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/DualFileTableTransactional.java +++ b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/DualFileTableTransactional.java @@ -39,6 +39,8 @@ import java.nio.channels.*; import com.solidosystems.tuplesoup.filter.*; import dstm2.atomic; import dstm2.Thread; +import dstm2.benchmark.FinancialTransaction.FinancialTransactionDS; +import dstm2.factory.Factory; import dstm2.util.StringKeyHashMap; import java.util.concurrent.Callable; @@ -80,37 +82,39 @@ public class DualFileTableTransactional implements TableTransactional{ private StringKeyHashMap indexcache; //private Hashtable indexcache; - + static Factory factory = Thread.makeFactory(DualFileTableTSInf.class); + // static Factory factory = Thread.makeFactory(FinancialTransactionDS.class); DualFileTableTSInf atomicfields; // Statistic counters + public @atomic interface DualFileTableTSInf{ - long getstat_add(); - long getstat_update(); - long getstat_delete(); - long getstat_add_size(); - long getstat_update_size(); - long getstat_read_size(); - long getstat_read(); - long getstat_cache_hit(); - long getstat_cache_miss(); - long getstat_cache_drop(); - long getFileaposition(); - long getFilebposition(); - int getIndexcacheusage(); + Long getstat_add(); + Long getstat_update(); + Long getstat_delete(); + Long getstat_add_size(); + Long getstat_update_size(); + Long getstat_read_size(); + Long getstat_read(); + Long getstat_cache_hit(); + Long getstat_cache_miss(); + Long getstat_cache_drop(); + Long getFileaposition(); + Long getFilebposition(); + Integer getIndexcacheusage(); - void setstat_add(long val); - void setstat_update(long val); - void setstat_delete(long val); - void setstat_add_size(long val); - void setstat_update_size(long val); - void setstat_read_size(long val); - void setstat_read(long val); - void setstat_cache_hit(long val); - void setstat_cache_miss(long val); - void setstat_cache_drop(long val); - void setIndexcacheusage(int val); - void setFileaposition(long val); - void setFilebposition(long val); + void setstat_add(Long val); + void setstat_update(Long val); + void setstat_delete(Long val); + void setstat_add_size(Long val); + void setstat_update_size(Long val); + void setstat_read_size(Long val); + void setstat_read(Long val); + void setstat_cache_hit(Long val); + void setstat_cache_miss(Long val); + void setstat_cache_drop(Long val); + void setIndexcacheusage(Integer val); + void setFileaposition(Long val); + void setFilebposition(Long val); } /*long stat_add=0; @@ -159,16 +163,17 @@ public class DualFileTableTransactional implements TableTransactional{ hash.put("stat_table_cache_hit",atomicfields.getstat_cache_hit()); hash.put("stat_table_cache_miss",atomicfields.getstat_cache_miss()); hash.put("stat_table_cache_drop",atomicfields.getstat_cache_drop()); - atomicfields.setstat_add(0); - atomicfields.setstat_update(0); - atomicfields.setstat_delete(0); - atomicfields.setstat_add_size(0); - atomicfields.setstat_update_size(0); - atomicfields.setstat_read_size(0); - atomicfields.setstat_read(0); - atomicfields.setstat_cache_hit(0); - atomicfields.setstat_cache_miss(0); - atomicfields.setstat_cache_drop(0); + atomicfields.setstat_add(Long.valueOf(0)); + atomicfields.setstat_update(Long.valueOf(0)); + atomicfields.setstat_delete(Long.valueOf(0)); + atomicfields.setstat_add_size(Long.valueOf(0)); + atomicfields.setstat_update_size(Long.valueOf(0)); + atomicfields.setstat_read_size(Long.valueOf(0)); + atomicfields.getstat_read_size(); + atomicfields.setstat_read(Long.valueOf(0)); + atomicfields.setstat_cache_hit(Long.valueOf(0)); + atomicfields.setstat_cache_miss(Long.valueOf(0)); + atomicfields.setstat_cache_drop(Long.valueOf(0)); Hashtable ihash=index.readStatistics(); hash.putAll(ihash); return hash; @@ -186,6 +191,8 @@ public class DualFileTableTransactional implements TableTransactional{ * Create a new table object with a specific index model */ public DualFileTableTransactional(String title,String location, int indextype) throws IOException{ + atomicfields = factory.create(); + this.title=title; this.location=location; if(!this.location.endsWith(File.separator))this.location+=File.separator; @@ -196,9 +203,19 @@ public class DualFileTableTransactional implements TableTransactional{ } indexcachefirst=null; indexcachelast=null; - atomicfields.setFileaposition(0); - atomicfields.setFilebposition(0); - atomicfields.setIndexcacheusage(0); + atomicfields.setFileaposition(Long.valueOf(0)); + atomicfields.setFilebposition(Long.valueOf(0)); + atomicfields.setstat_update_size(Long.valueOf(0)); + atomicfields.setstat_update(Long.valueOf(0)); + atomicfields.setstat_read_size(Long.valueOf(0)); + atomicfields.setstat_read(Long.valueOf(0)); + atomicfields.setstat_delete(Long.valueOf(0)); + atomicfields.setstat_cache_miss(Long.valueOf(0)); + atomicfields.setstat_cache_hit(Long.valueOf(0)); + atomicfields.setstat_cache_drop(Long.valueOf(0)); + atomicfields.setstat_add_size(Long.valueOf(0)); + atomicfields.setstat_add(Long.valueOf(0)); + atomicfields.setIndexcacheusage(Integer.valueOf(0)); indexcache=new StringKeyHashMap(); } @@ -268,6 +285,7 @@ public class DualFileTableTransactional implements TableTransactional{ switch(type){ case FILEA : if(fileastream==null){ // fileastream=new DataOutputStream(new BufferedOutputStream(new FileOutputStream(getFileName(FILEA),true))); + System.out.println("file a " + getFileName(FILEA)); fileastream=new TransactionalFile(getFileName(FILEA),"rw"); //File ftest=new File(getFileName(FILEA)); @@ -277,6 +295,7 @@ public class DualFileTableTransactional implements TableTransactional{ } break; case FILEB : if(filebstream==null){ + System.out.println("file a " + getFileName(FILEB)); filebstream=new TransactionalFile(getFileName(FILEB),"rw"); //File ftest=new File(getFileName(FILEB)); //atomicfields.setFilebposition(ftest.length()); @@ -391,14 +410,11 @@ public class DualFileTableTransactional implements TableTransactional{ private void updateCacheEntry(TableIndexEntryTransactional entry){ - final Vector args = new Vector(); - args.add(entry); - Thread.doIt(new Callable() { - public Boolean call() throws Exception{ + //synchronized(indexcache){ - if(indexcache.containsKey(((TableIndexEntryTransactional)(args.get(0))).getId())){ - TableIndexNodeTransactional node=indexcache.get(((TableIndexEntryTransactional)(args.get(0))).getId()); - node.setData(((TableIndexEntryTransactional)(args.get(0)))); + if(indexcache.containsKey(entry.getId())){ + TableIndexNodeTransactional node=indexcache.get(entry.getId()); + node.setData(entry); if(node!=indexcachelast){ if(node==indexcachefirst){ indexcachefirst=node.getNext(); @@ -410,11 +426,11 @@ public class DualFileTableTransactional implements TableTransactional{ indexcachelast=node; } }else{ - addCacheEntry(((TableIndexEntryTransactional)(args.get(0)))); + addCacheEntry(entry); } - return true; - } - }); + // return true; + // } + // }); } private void removeCacheEntry(String id){ @@ -454,14 +470,10 @@ public class DualFileTableTransactional implements TableTransactional{ } private TableIndexEntryTransactional getCacheEntry(String id){ - final Vector args = new Vector(); - args.add(id); - - TableIndexEntryTransactional res = Thread.doIt(new Callable() { - public TableIndexEntryTransactional call() throws Exception{ + //synchronized(indexcache){ - if(indexcache.containsKey((String)(args.get(0)))){ - TableIndexNodeTransactional node=indexcache.get((String)(args.get(0))); + if(indexcache.containsKey(id)){ + TableIndexNodeTransactional node=indexcache.get(id); if(node!=indexcachelast){ if(node==indexcachefirst){ indexcachefirst=node.getNext(); @@ -477,19 +489,10 @@ public class DualFileTableTransactional implements TableTransactional{ // } return node.getData(); } - return null; - } - }); - if (res != null) - return res; - - Thread.doIt(new Callable() { - public Boolean call() throws Exception{ + //synchronized(statlock){ atomicfields.setstat_cache_miss(atomicfields.getstat_cache_miss()+1); - return true; - } - }); + //} return null; } diff --git a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/HashedTable.java b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/HashedTable.java index b7d19687..c0588cd7 100644 --- a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/HashedTable.java +++ b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/HashedTable.java @@ -42,7 +42,7 @@ import com.solidosystems.tuplesoup.filter.*; * Every row must have a unique id within a table. */ public class HashedTable implements Table{ - private int TABLESETSIZE=16; + private int TABLESETSIZE=5; private List tableset; private String title; private String location; diff --git a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/IndexedTableReaderTransactional.java b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/IndexedTableReaderTransactional.java index c034aa1a..e9c5cad7 100644 --- a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/IndexedTableReaderTransactional.java +++ b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/IndexedTableReaderTransactional.java @@ -36,8 +36,11 @@ import java.util.*; import java.util.concurrent.Callable; import dstm2.Thread; +import dstm2.factory.Factory; public class IndexedTableReaderTransactional extends TupleStreamTransactional{ + + private DataInputStream fileastream=null; private DataInputStream filebstream=null; private long fileaposition=0; diff --git a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/PagedIndex.java b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/PagedIndex.java index a7903995..a36fb047 100644 --- a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/PagedIndex.java +++ b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/PagedIndex.java @@ -59,15 +59,19 @@ protected static final int INITIALPAGEHASH=1024; if(!ftest.exists())ftest.createNewFile(); out=new RandomAccessFile(filename,"rw"); root=new TableIndexPage[INITIALPAGEHASH]; + System.out.println(filename); + System.out.println(out.length()); if(out.length()>0){ for(int i=0;i factory = Thread.makeFactory(PageIndexTSInf.class); + PageIndexTSInf atomicfields; @@ -51,21 +54,32 @@ public class PagedIndexTransactional implements TableIndexTransactional{ protected static final int PAGESIZE=2048; public PagedIndexTransactional(String filename) throws IOException{ + atomicfields = factory.create(); + + atomicfields.setStat_create_page(Long.valueOf(0)); + atomicfields.setStat_page_branch(Long.valueOf(0)); + atomicfields.setStat_page_next(Long.valueOf(0)); + atomicfields.setStat_read(Long.valueOf(0)); + atomicfields.setStat_write(Long.valueOf(0)); + this.atomicfields.setFilename(filename); File ftest=new File(filename); if(!ftest.exists())ftest.createNewFile(); out=new TransactionalFile(filename,"rw"); atomicfields.setRoots(new AtomicArray(TableIndexPageTransactional.class, INITIALPAGEHASH)); - + System.out.println(filename); + System.out.println(out.length()); if(out.length()>0){ for(int i=0;i factory = Thread.makeFactory(RowTSInf.class); + private String id; // private int size; RowTSInf atomicfields; @@ -33,6 +37,8 @@ public class RowTransactional { } public RowTransactional(String id){ + atomicfields = factory.create(); + this.id=id; atomicfields.setSize(-1); values=new StringKeyHashMap(); diff --git a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/TableIndexEntry.java b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/TableIndexEntry.java index 4102ff4c..a944a6c9 100644 --- a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/TableIndexEntry.java +++ b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/TableIndexEntry.java @@ -162,6 +162,7 @@ public class TableIndexEntry implements Comparable{ protected static TableIndexEntry readData(DataInputStream in) throws IOException{ in.readInt(); int num=in.readShort(); + System.out.println("num=444444444444444444444444 " + num); StringBuilder buf=new StringBuilder(num); for(int i=0;i{ - + + static Factory factory = Thread.makeFactory(TableIndexEntryTSInf.class); + TableIndexEntryTSInf atomicfields; public @atomic interface TableIndexEntryTSInf{ String getId(); - int getLocation(); - long getPosition(); - int getSize(); - int getRowsize(); + Integer getLocation(); + Long getPosition(); + Integer getSize(); + Integer getRowsize(); void setId(String val); - void setLocation(int val); - void setPosition(long val); - void setSize(int val); - void setRowsize(int val); + void setLocation(Integer val); + void setPosition(Long val); + void setSize(Integer val); + void setRowsize(Integer val); } public TableIndexEntryTransactional(String id,int rowsize,int location,long position){ + atomicfields = factory.create(); + this.atomicfields.setId(id); this.atomicfields.setLocation(location); this.atomicfields.setPosition(position); @@ -61,7 +67,7 @@ public class TableIndexEntryTransactional implements AtomicSuperClass, Comparabl } public int getRowSize(){ - return atomicfields.getRowsize(); + return atomicfields.getRowsize().intValue(); } public int compareTo(TableIndexEntryTransactional obj) throws ClassCastException{ @@ -87,7 +93,7 @@ public class TableIndexEntryTransactional implements AtomicSuperClass, Comparabl public int getSize(){ if(atomicfields.getSize()<0) calcSize(); - return atomicfields.getSize(); + return atomicfields.getSize().intValue(); } public void setSize(int size){ this.atomicfields.setSize(size); @@ -99,7 +105,7 @@ public class TableIndexEntryTransactional implements AtomicSuperClass, Comparabl dout.writeInt(atomicfields.getId().hashCode()); dout.writeShort(atomicfields.getId().length()); dout.writeChars(atomicfields.getId()); - dout.writeInt(atomicfields.getRowsize()); + dout.writeInt(atomicfields.getRowsize().intValue()); dout.writeByte(atomicfields.getLocation()); dout.writeLong(atomicfields.getPosition()); setSize(bout.size()); @@ -115,7 +121,7 @@ public class TableIndexEntryTransactional implements AtomicSuperClass, Comparabl out.writeInt(atomicfields.getId().hashCode()); out.writeShort(atomicfields.getId().length()); out.writeChars(atomicfields.getId()); - out.writeInt(atomicfields.getRowsize()); + out.writeInt(atomicfields.getRowsize().intValue()); out.writeByte(atomicfields.getLocation()); out.writeLong(atomicfields.getPosition()); setSize((int)(out.getFilePointer()-pre)); @@ -123,7 +129,7 @@ public class TableIndexEntryTransactional implements AtomicSuperClass, Comparabl protected void updateData(TransactionalFile out) throws IOException{ long pre=out.getFilePointer(); out.skipBytes(4+2+atomicfields.getId().length()*2); - out.writeInt(atomicfields.getRowsize()); + out.writeInt(atomicfields.getRowsize().intValue()); out.writeByte(atomicfields.getLocation()); out.writeLong(atomicfields.getPosition()); setSize((int)(out.getFilePointer()-pre)); @@ -132,7 +138,7 @@ public class TableIndexEntryTransactional implements AtomicSuperClass, Comparabl out.writeInt(atomicfields.getId().hashCode()); out.writeShort(atomicfields.getId().length()); out.writeChars(atomicfields.getId()); - out.writeInt(atomicfields.getRowsize()); + out.writeInt(atomicfields.getRowsize().intValue()); out.writeByte(atomicfields.getLocation()); out.writeLong(atomicfields.getPosition()); } @@ -140,6 +146,7 @@ public class TableIndexEntryTransactional implements AtomicSuperClass, Comparabl long pre=in.getFilePointer(); in.readInt(); int num=in.readShort(); + //System.out.println("num= " + num); StringBuilder buf=new StringBuilder(num); for(int i=0;i factory = Thread.makeFactory(TableIndexInodeTSInf.class); + TableIndexInodeTSInf atomicfields; - public @atomic interface TableIndexInodeTSinf{ + public @atomic interface TableIndexInodeTSInf{ TableIndexNodeTransactional getPrevious(); TableIndexEntryTransactional getData(); TableIndexNodeTransactional getNext(); @@ -30,12 +33,16 @@ public class TableIndexNodeTransactional implements AtomicSuperClass{ } public TableIndexNodeTransactional(){ + atomicfields = factory.create(); + atomicfields.setPrevious(null); atomicfields.setData(null); atomicfields.setNext(null); } public TableIndexNodeTransactional(TableIndexEntryTransactional entry){ + atomicfields = factory.create(); + atomicfields.setPrevious(null); atomicfields.setData(entry); atomicfields.setNext(null); @@ -43,12 +50,16 @@ public class TableIndexNodeTransactional implements AtomicSuperClass{ } public TableIndexNodeTransactional(TableIndexNodeTransactional prev,TableIndexEntryTransactional entry){ + atomicfields = factory.create(); + atomicfields.setPrevious(prev); atomicfields.setData(entry); atomicfields.setNext(null); } public TableIndexNodeTransactional(TableIndexNodeTransactional prev,TableIndexEntryTransactional entry,TableIndexNodeTransactional nex){ + atomicfields = factory.create(); + atomicfields.setPrevious(prev); atomicfields.setData(entry); atomicfields.setNext(nex); diff --git a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/TableIndexPage.java b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/TableIndexPage.java index 37549217..dc8c2890 100644 --- a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/TableIndexPage.java +++ b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/TableIndexPage.java @@ -54,26 +54,43 @@ public class TableIndexPage{ private PagedIndex index=null; public TableIndexPage(PagedIndex index,RandomAccessFile file) throws IOException{ - this.file=file; + this.file=file; this.index=index; first=false; location=file.getFilePointer(); + System.out.println(location); size=file.readInt(); next=file.readLong(); lower=file.readLong(); offset=file.readInt(); endhash=file.readInt(); + System.out.println("si " + size); + System.out.println("next " + next); + System.out.println("lower " + lower); + System.out.println("offset " + offset); + System.out.println("endhash " + endhash); if(offset>0)starthash=file.readInt(); + System.out.println("here tav;eindepage"); + + } public static TableIndexPage createNewPage(PagedIndex index,RandomAccessFile file,int size) throws IOException{ long pre=file.length(); + System.out.println("pre " + pre); + System.out.println("pointer1 " + file.length()+size+BASEOFFSET); file.setLength(file.length()+size+BASEOFFSET); file.seek(pre); + + System.out.println("pointer2 " + file.getFilePointer()); file.writeInt(size); + System.out.println("pointer2 " + file.getFilePointer()); file.writeLong(-1l); + System.out.println("pointer2 " + file.getFilePointer()); file.writeLong(-1l); + System.out.println("pointer2 " + file.getFilePointer()); file.writeInt(0); + System.out.println("pointer2 " + file.getFilePointer()); file.writeInt(-1); file.seek(pre); index.stat_create_page++; @@ -140,7 +157,9 @@ public class TableIndexPage{ } public TableIndexEntry scanIndex(String id,int hashcode) throws IOException{ + System.out.println("sacn index"); if(!first){ + if(hashcodeendhash){ + if(next==-1)return null; if(nextpage==null){ file.seek(next); @@ -163,11 +183,15 @@ public class TableIndexPage{ file.seek(location+BASEOFFSET); long pre=file.getFilePointer(); while(file.getFilePointer() factory = Thread.makeFactory(TableIndexPageTSInf.class); + + /*static*/ TableIndexPageTSInf atomicfields = null; private final static int BASEOFFSET=4+8+8+4+4; //private RandomAccessFile file=null; private TransactionalFile file = null; + public @atomic interface TableIndexPageTSInf{ Long getLocation(); Integer getSize(); @@ -60,8 +65,8 @@ public class TableIndexPageTransactional implements AtomicSuperClass{ void setLowerpage(TableIndexPageTransactional lowerpage); void setNextpage(TableIndexPageTransactional nextpage); void setFirst(Boolean val); - void setEndhash(int val); - void setStarthash(int val); + void setEndhash(Integer val); + void setStarthash(Integer val); void setOffset(Integer offset); void setNext(Long next); void setSize(Integer size); @@ -74,28 +79,63 @@ public class TableIndexPageTransactional implements AtomicSuperClass{ public TableIndexPageTransactional(PagedIndexTransactional index,TransactionalFile file) throws IOException{ this.file=file; + atomicfields = factory.create(); this.atomicfields.setIndex(index); this.atomicfields.setFirst(false); this.atomicfields.setLocation(file.getFilePointer()); + System.out.println(file.getFilePointer()); this.atomicfields.setSize(file.readInt()); + System.out.println(file.getFilePointer()); this.atomicfields.setNext(file.readLong()); + System.out.println(file.getFilePointer()); this.atomicfields.setLower(file.readLong()); + System.out.println(file.getFilePointer()); + System.out.println(file.getFilePointer()); this.atomicfields.setOffset(file.readInt()); + System.out.println(file.getFilePointer()); this.atomicfields.setEndhash(file.readInt()); + System.out.println("size " + atomicfields.getSize()); + System.out.println("next " + atomicfields.getNext()); + System.out.println("lower " + atomicfields.getLower()); + System.out.println("offset " + atomicfields.getOffset()); + System.out.println("endhash " + atomicfields.getEndhash()); if(this.atomicfields.getOffset()>0) this.atomicfields.setStarthash(file.readInt()); + else + this.atomicfields.setStarthash(-1); } public static TableIndexPageTransactional createNewPage(PagedIndexTransactional index,TransactionalFile file,int size) throws IOException{ + long pre=file.length(); + System.out.println("pre " + pre); // file.setLength(file.length()+size+BASEOFFSET); file.seek(pre); + byte[] dummy = new byte[size+BASEOFFSET]; + file.write(dummy); + System.out.println("pointer " + file.getFilePointer()); + + file.seek(pre); + System.out.println("pointer2 " + file.getFilePointer()); file.writeInt(size); + + System.out.println("pointer2 " + file.getFilePointer()); file.writeLong(-1l); + System.out.println("pointer2 " + file.getFilePointer()); file.writeLong(-1l); + System.out.println("pointer2 " + file.getFilePointer()); file.writeInt(0); + System.out.println("pointer2 " + file.getFilePointer()); file.writeInt(-1); file.seek(pre); + file.readInt(); + file.readLong(); + file.readLong(); + file.readInt(); + file.readInt(); + file.seek(pre); + + //index.atomicfields.setStat_create_page((long)2); index.atomicfields.setStat_create_page(index.atomicfields.getStat_create_page()+1); return new TableIndexPageTransactional(index,file); } @@ -183,6 +223,7 @@ public class TableIndexPageTransactional implements AtomicSuperClass{ file.seek(this.atomicfields.getLocation()+BASEOFFSET); long pre=file.getFilePointer(); while(file.getFilePointer() factory = Thread.makeFactory(ValueTSInf.class); public @atomic interface ValueTSInf{ - byte getType(); + Byte getType(); String getStr_value(); - long getInt_value(); - double getFloat_value(); + Long getInt_value(); + Double getFloat_value(); AtomicByteArray getBinary(); - void setType(byte val); + void setType(Byte val); void setStr_value(String val); - void setInt_value(long val); - void setFloat_value(double val); + void setInt_value(Long val); + void setFloat_value(Double val); void setBinary(AtomicByteArray bytes); } @@ -84,12 +87,12 @@ public class ValueTransactional implements AtomicSuperClass{ int hash=0; switch(atomicfields.getType()){ case STRING : hash+=atomicfields.getStr_value().hashCode(); - case INT : hash+=(int)atomicfields.getInt_value(); - case LONG : hash+=(int)atomicfields.getInt_value(); - case FLOAT : hash+=(int)atomicfields.getFloat_value(); - case DOUBLE : hash+=(int)atomicfields.getFloat_value(); - case BOOLEAN : hash+=(int)atomicfields.getInt_value(); - case TIMESTAMP : hash+=(int)atomicfields.getInt_value(); + case INT : hash+=atomicfields.getInt_value(); + case LONG : hash+=atomicfields.getInt_value(); + case FLOAT : hash+=atomicfields.getFloat_value(); + case DOUBLE : hash+=atomicfields.getFloat_value(); + case BOOLEAN : hash+=atomicfields.getInt_value(); + case TIMESTAMP : hash+=atomicfields.getInt_value(); case BINARY : hash+=atomicfields.getBinary().hashCode(); } return hash; @@ -311,11 +314,11 @@ public class ValueTransactional implements AtomicSuperClass{ try{ switch(atomicfields.getType()){ case STRING : return Integer.parseInt(atomicfields.getStr_value()); - case INT : return (int)atomicfields.getInt_value(); - case LONG : return (int)atomicfields.getInt_value(); - case FLOAT : return (int)atomicfields.getFloat_value(); - case DOUBLE : return (int)atomicfields.getFloat_value(); - case BOOLEAN : return (int)atomicfields.getInt_value(); + case INT : return atomicfields.getInt_value().intValue(); + case LONG : return (int)atomicfields.getInt_value().intValue(); + case FLOAT : return (int)atomicfields.getFloat_value().intValue(); + case DOUBLE : return (int)atomicfields.getFloat_value().intValue(); + case BOOLEAN : return (int)atomicfields.getInt_value().intValue(); case TIMESTAMP : return (int)(atomicfields.getInt_value()/1000); } }catch(Exception e){} @@ -336,8 +339,8 @@ public class ValueTransactional implements AtomicSuperClass{ case STRING : return Long.parseLong(atomicfields.getStr_value()); case INT : return atomicfields.getInt_value(); case LONG : return atomicfields.getInt_value(); - case FLOAT : return (long)atomicfields.getFloat_value(); - case DOUBLE : return (long)atomicfields.getFloat_value(); + case FLOAT : return (long)atomicfields.getFloat_value().longValue(); + case DOUBLE : return (long)atomicfields.getFloat_value().longValue(); case BOOLEAN : return atomicfields.getInt_value(); case TIMESTAMP : return atomicfields.getInt_value(); } @@ -357,11 +360,11 @@ public class ValueTransactional implements AtomicSuperClass{ try{ switch(atomicfields.getType()){ case STRING : return Float.parseFloat(atomicfields.getStr_value()); - case INT : return (float)atomicfields.getInt_value(); - case LONG : return (float)atomicfields.getInt_value(); - case FLOAT : return (float)atomicfields.getFloat_value(); - case DOUBLE : return (float)atomicfields.getFloat_value(); - case BOOLEAN : return (float)atomicfields.getInt_value(); + case INT : return (float)atomicfields.getInt_value().floatValue(); + case LONG : return (float)atomicfields.getInt_value().floatValue(); + case FLOAT : return (float)atomicfields.getFloat_value().floatValue(); + case DOUBLE : return (float)atomicfields.getFloat_value().floatValue(); + case BOOLEAN : return (float)atomicfields.getInt_value().floatValue(); case TIMESTAMP : return (float)(atomicfields.getInt_value()/1000); } }catch(Exception e){} @@ -433,7 +436,7 @@ public class ValueTransactional implements AtomicSuperClass{ case INT : return new Date(atomicfields.getInt_value()*1000l); case LONG : return new Date(atomicfields.getInt_value()); case FLOAT : return new Date((long)(atomicfields.getFloat_value()*1000l)); - case DOUBLE : return new Date((long)atomicfields.getFloat_value()); + case DOUBLE : return new Date((long)atomicfields.getFloat_value().longValue()); case TIMESTAMP : return new Date(atomicfields.getInt_value()); } }catch(Exception e){} @@ -462,11 +465,11 @@ public class ValueTransactional implements AtomicSuperClass{ out.writeChar(atomicfields.getStr_value().charAt(i)); } break; - case INT : out.writeInt((int)atomicfields.getInt_value()); + case INT : out.writeInt((int)atomicfields.getInt_value().intValue()); break; case LONG : out.writeLong(atomicfields.getInt_value()); break; - case FLOAT : out.writeFloat((float)atomicfields.getFloat_value()); + case FLOAT : out.writeFloat((float)atomicfields.getFloat_value().intValue()); break; case DOUBLE : out.writeDouble(atomicfields.getFloat_value()); break; @@ -496,11 +499,11 @@ public class ValueTransactional implements AtomicSuperClass{ out.writeChar(atomicfields.getStr_value().charAt(i)); } break; - case INT : out.writeInt((int)atomicfields.getInt_value()); + case INT : out.writeInt((int)atomicfields.getInt_value().intValue()); break; case LONG : out.writeLong(atomicfields.getInt_value()); break; - case FLOAT : out.writeFloat((float)atomicfields.getFloat_value()); + case FLOAT : out.writeFloat((float)atomicfields.getFloat_value().intValue()); break; case DOUBLE : out.writeDouble(atomicfields.getFloat_value()); break; @@ -562,6 +565,7 @@ public class ValueTransactional implements AtomicSuperClass{ public ValueTransactional(byte[] val){ this(); + atomicfields.setBinary(new AtomicByteArray(Byte.class, val.length)); for (int i=0; i lst=new ArrayList(); + for(int i=0;i hash){ + Set keys=hash.keySet(); + Iterator it=keys.iterator(); + while(it.hasNext()){ + String key=it.next(); + outbr(4,key+" "+hash.get(key)); + } + } +} \ No newline at end of file diff --git a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/test/OrigParralelThread.java b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/test/OrigParralelThread.java new file mode 100644 index 00000000..3d5a0245 --- /dev/null +++ b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/test/OrigParralelThread.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2007, Solido Systems + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of Solido Systems nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + + package com.solidosystems.tuplesoup.test; + + import com.solidosystems.tuplesoup.core.*; + import com.solidosystems.tuplesoup.filter.*; + + import java.util.*; + import java.io.*; + + +public class OrigParralelThread implements Runnable{ + String id; + int records; + OrigParralelPerformanceTest app; + Table table; + //TableTransactional table; + + public OrigParralelThread(OrigParralelPerformanceTest app,Table table,String id,int records){ + this.id=id; + this.records=records; + this.app=app; + this.table=table; + } + + public void run(){ + try{ + //long time; + long time=app.benchmarkLargeWrite(table,records,id); + synchronized(app){ + app.writetime+=time; + } + /*long*/ time=app.benchmarkLargeRead(table,records,id); + synchronized(app){ + app.readtime+=time; + } + time=app.benchmarkLargeRandomRead(table,records,id); + synchronized(app){ + app.randomtime+=time; + } + }catch(Exception e){ + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/test/ParallelPerformanceTest.java b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/test/ParallelPerformanceTest.java index e4173c3f..adb7188c 100644 --- a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/test/ParallelPerformanceTest.java +++ b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/test/ParallelPerformanceTest.java @@ -34,6 +34,7 @@ import com.solidosystems.tuplesoup.core.*; import com.solidosystems.tuplesoup.filter.*; +import dstm2.Init; import java.util.*; import java.io.*; @@ -45,10 +46,11 @@ public class ParallelPerformanceTest extends BasicTest implements Runnable{ long randomtime; public ParallelPerformanceTest(){ - String path="./Volumes/My Book/test/"; + String path="/home/navid/Volumes/My Book/test/"; try{ - int records=50000; - for(int i=1;i<11;i++){ + //int records=10; + int records=5; + for(int i=1;i<2;i++){ outbr("Running Parallel DualFileTable Performance test"); outbr(1,i+" x "+(records/i)+" Large records"); @@ -65,13 +67,14 @@ public class ParallelPerformanceTest extends BasicTest implements Runnable{ table.deleteFiles();*/ outbr(2,"Paged index"); - Table table=new DualFileTable("Performance-test",path,Table.PAGED); - benchmark(table,i,(records/i)); + //Table table=new DualFileTable("Performance-test",path,Table.PAGED); + TableTransactional table=new DualFileTableTransactional("Performance-test",path,TableTransactional.PAGED); + benchmark(table,5,(records/i)); table.close(); - table.deleteFiles(); + // table.deleteFiles(); - outbr("Running Parallel HashedTable Performance test"); - outbr(1,i+" x "+(records/i)+" Large records"); + // outbr("Running Parallel HashedTable Performance test"); + //outbr(1,i+" x "+(records/i)+" Large records"); /* outbr(2,"Memory index"); table=new HashedTable("Performance-test",path,Table.MEMORY); @@ -85,11 +88,12 @@ public class ParallelPerformanceTest extends BasicTest implements Runnable{ table.close(); table.deleteFiles();*/ - outbr(2,"Paged index"); - table=new HashedTable("Performance-test",path,Table.PAGED); - benchmark(table,i,(records/i)); - table.close(); - table.deleteFiles(); + // outbr(2,"Paged index"); + //table=new HashedTableTransactional("Performance-test",path,TableTransactional.PAGED); + // table=new HashedTableTransactional("Performance-test",path,TableTransactional.PAGED); + // benchmark(table,i,(records/i)); + // table.close(); + // table.deleteFiles();*/ } @@ -98,10 +102,11 @@ public class ParallelPerformanceTest extends BasicTest implements Runnable{ } } public static void main(String[] args){ + Init.init(); new ParallelPerformanceTest(); } - public void benchmark(Table table,int threadcount, int records) throws Exception{ + public void benchmark(TableTransactional table/*Table table*/,int threadcount, int records) throws Exception{ writetime=0; readtime=0; randomtime=0; @@ -123,33 +128,36 @@ public class ParallelPerformanceTest extends BasicTest implements Runnable{ } - public long benchmarkLargeWrite(Table table,int records, String id) throws IOException{ + public long benchmarkLargeWrite(TableTransactional table,int records, String id) throws IOException{ long pre=System.currentTimeMillis(); for(int i=0;i