--- /dev/null
+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<length; i++){
+ result = (result << 8) | (bytes[i] & 0xFF);
+ }
+ return result;
+ }
+
+ public static int bytes2int( byte[] bytes ){
+ int result = 0;
+ int length = Math.min( 4, bytes.length);
+ for(int i=0; i<length; i++){
+ result = (result << 8) | (bytes[i] & 0xFF);
+ }
+ return result;
+ }
+
+ static byte[] double2bytes( double value ){
+ return long2bytes(Double.doubleToLongBits(value));
+ }
+
+ public static byte[] float2bytes( float value ){
+ return int2bytes(Float.floatToIntBits(value));
+ }
+
+ public static byte[] long2bytes( long value ){
+ 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);
+ 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<length; i++ ){
+ if(list[offset+i] != value[i]){
+ continue loop1;
+ }
+ }
+ return offset;
+ }
+ return -1;
+ }
+
+ public static int compareBytes( byte[] leftBytes, byte[] rightBytes){
+ int length = Math.min( leftBytes.length, rightBytes.length );
+ int comp = 0;
+ for(int i=0; i<length; i++){
+ if(leftBytes[i] != rightBytes[i]){
+ comp = leftBytes[i] < rightBytes[i] ? -1 : 1;
+ break;
+ }
+ }
+ if(comp == 0 && leftBytes.length != rightBytes.length){
+ comp = leftBytes.length < rightBytes.length ? -1 : 1;
+ }
+ return comp;
+ }
+
+
+}
\ No newline at end of file
heldlengthlocks.remove(trf.getInodestate().commitedfilesize.lengthlock);
trf.getInodestate().commitedfilesize.lengthlock.unlock();
}
+ if (((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(trf)).lenght_read){
+ trf.getInodestate().commitedfilesize.getLengthReaders().remove(this);
+ //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();
- }
+
}
lockmap = new HashMap();
commitedfilesize = new GlobalLength(length);
+ // System.out.println(length);
this.inode = inode;
}
public GlobalLength(long length) {
this.length = length;
+ lengthlock = new ReentrantLock();
+ lengthReaders = new Vector();
}
else if (this.getNumber() > 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;
}
*/
package TransactionalIO.core;
+import TransactionalIO.Utilities.Conversions;
import TransactionalIO.Utilities.Range;
import TransactionalIO.exceptions.AbortedException;
import TransactionalIO.exceptions.PanicException;
}
}
+ /* 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++;
if (inodestate != null) {
synchronized (inodestate) {
committedoffset = new GlobalOffset(0);
-
}
}
private int invokeNativepread(byte buff[], long offset, int size) {
try {
+
+
return nativepread(buff, offset, size, file.getFD());
} catch (IOException ex) {
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))) {
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 */
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;
}
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) {
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) {
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);
}
public void lockOffset(ExtendedTransaction me) {
boolean locked = false;
if (me.getStatus() == Status.ACTIVE) { //locking the offset
-
offsetlock.lock();
locked = true;
}
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());
}
}
-// private class EntryIterator extends HashIterator<Map.Entry<K,V>> {
-// public Map.Entry<K,V> next() {
-// return nextEntry();
-// }
-// }
+ private class EntryIterator extends HashIterator<StringKeyHashMap.TEntry<V>> {
+ public StringKeyHashMap.TEntry<V> next() {
+ return nextEntry();
+ }
+ }
// Subclass overrides these to alter behavior of views' iterator() method
public Iterator<Integer> newKeyIterator() {
return new KeyIterator();
}
public Iterator<V> newValueIterator() {
+
return new ValueIterator();
}
-// Iterator<Map.Entry<K,V>> newEntryIterator() {
-// return new EntryIterator();
-// }
+ Iterator<StringKeyHashMap.TEntry<V>> newEntryIterator() {
+ return new EntryIterator();
+ }
// Views
private transient Set<StringKeyHashMap.TEntry<V>> entrySet = null;
-
+
private class KeySet extends AbstractSet<Integer> {
public Iterator<Integer> iterator() {
return (es != null ? es : (entrySet = (Set<StringKeyHashMap.TEntry<V>>) (Set) new EntrySet()));
}
- private class EntrySet {//extends AbstractSet/*<Map.Entry<K,V>>*/ {
-// public Iterator/*<Map.Entry<K,V>>*/ iterator() {
-// return newEntryIterator();
-// }
+ private class EntrySet extends AbstractSet<StringKeyHashMap.TEntry<V>>{//extends AbstractSet/*<Map.Entry<K,V>>*/ {
+ public Iterator/*<Map.Entry<K,V>>*/ iterator() {
+ return newEntryIterator();
+ }
public boolean contains(StringKeyHashMap.TEntry<V> o) {
StringKeyHashMap.TEntry<V> e = (StringKeyHashMap.TEntry<V>) o;
TEntry<V> candidate = getEntry(e.getHash());
if(!this.location.endsWith(File.separator))this.location+=File.separator;
switch(indextype){
case PAGED : index=new PagedIndex(getFileName(INDEX));
+
break;
}
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();
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;
private StringKeyHashMap<TableIndexNodeTransactional> indexcache;
//private Hashtable<String,TableIndexNode> indexcache;
-
+ static Factory<DualFileTableTSInf> factory = Thread.makeFactory(DualFileTableTSInf.class);
+ // static Factory<FinancialTransactionDS> 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;
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<String,Long> ihash=index.readStatistics();
hash.putAll(ihash);
return hash;
* 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;
}
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<TableIndexNodeTransactional>();
}
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));
}
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());
private void updateCacheEntry(TableIndexEntryTransactional entry){
- final Vector args = new Vector();
- args.add(entry);
- Thread.doIt(new Callable<Boolean>() {
- 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();
indexcachelast=node;
}
}else{
- addCacheEntry(((TableIndexEntryTransactional)(args.get(0))));
+ addCacheEntry(entry);
}
- return true;
- }
- });
+ // return true;
+ // }
+ // });
}
private void removeCacheEntry(String id){
}
private TableIndexEntryTransactional getCacheEntry(String id){
- final Vector args = new Vector();
- args.add(id);
-
- TableIndexEntryTransactional res = Thread.doIt(new Callable<TableIndexEntryTransactional>() {
- 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();
// }
return node.getData();
}
- return null;
- }
- });
- if (res != null)
- return res;
-
- Thread.doIt(new Callable<Boolean>() {
- public Boolean call() throws Exception{
+
//synchronized(statlock){
atomicfields.setstat_cache_miss(atomicfields.getstat_cache_miss()+1);
- return true;
- }
- });
+
//}
return null;
}
* 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<Table> tableset;
private String title;
private String location;
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;
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<INITIALPAGEHASH;i++){
root[i]=new TableIndexPage(this,out);
root[i].setFirst();
+ System.out.println("In loop " + root[i].getEndLocation());
out.seek(root[i].getEndLocation());
}
}else{
for(int i=0;i<INITIALPAGEHASH;i++){
root[i]=TableIndexPage.createNewPage(this,out,PAGESIZE);
+ System.out.println("In Othe loop " + root[i].getEndLocation());
root[i].setFirst();
}
}
import dstm2.AtomicArray;
import dstm2.atomic;
import dstm2.Thread;
+import dstm2.factory.Factory;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
*/
public class PagedIndexTransactional implements TableIndexTransactional{
+ static Factory<PageIndexTSInf> factory = Thread.makeFactory(PageIndexTSInf.class);
+
PageIndexTSInf atomicfields;
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>(TableIndexPageTransactional.class, INITIALPAGEHASH));
-
+ System.out.println(filename);
+ System.out.println(out.length());
if(out.length()>0){
for(int i=0;i<INITIALPAGEHASH;i++){
atomicfields.getRoots().set(i, new TableIndexPageTransactional(this,out));
atomicfields.getRoots().get(i).setFirst();
+ System.out.println("In loop " + atomicfields.getRoots().get(i).getEndLocation());
out.seek(atomicfields.getRoots().get(i).getEndLocation());
}
}else{
for(int i=0;i<INITIALPAGEHASH;i++){
atomicfields.getRoots().set(i, TableIndexPageTransactional.createNewPage(this,out,PAGESIZE));
+ System.out.println("In Othe loop " + atomicfields.getRoots().get(i).getEndLocation());
atomicfields.getRoots().get(i).setFirst();
}
}
import TransactionalIO.core.TransactionalFile;
import dstm2.atomic;
+import dstm2.Thread;
+import dstm2.factory.Factory;
import dstm2.util.StringKeyHashMap;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
* @author navid
*/
public class RowTransactional {
+ Factory<RowTSInf> factory = Thread.makeFactory(RowTSInf.class);
+
private String id;
// private int size;
RowTSInf atomicfields;
}
public RowTransactional(String id){
+ atomicfields = factory.create();
+
this.id=id;
atomicfields.setSize(-1);
values=new StringKeyHashMap<ValueTransactional>();
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<num;i++){
buf.append(in.readChar());
import TransactionalIO.core.TransactionalFile;
import dstm2.AtomicSuperClass;
import dstm2.atomic;
+import dstm2.Thread;
+import dstm2.factory.Factory;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
* @author navid
*/
public class TableIndexEntryTransactional implements AtomicSuperClass, Comparable<TableIndexEntryTransactional>{
-
+
+ static Factory<TableIndexEntryTSInf> 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);
}
public int getRowSize(){
- return atomicfields.getRowsize();
+ return atomicfields.getRowsize().intValue();
}
public int compareTo(TableIndexEntryTransactional obj) throws ClassCastException{
public int getSize(){
if(atomicfields.getSize()<0) calcSize();
- return atomicfields.getSize();
+ return atomicfields.getSize().intValue();
}
public void setSize(int size){
this.atomicfields.setSize(size);
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());
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));
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));
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());
}
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<num;i++){
buf.append(in.readChar());
import dstm2.AtomicSuperClass;
import dstm2.atomic;
+import dstm2.Thread;
+import dstm2.factory.Factory;
/**
*
//private TableIndexNodeTransactional previous;
//private TableIndexEntryTransactional data;
//private TableIndexNodeTransactional next;
- TableIndexInodeTSinf atomicfields;
+ static Factory<TableIndexInodeTSInf> factory = Thread.makeFactory(TableIndexInodeTSInf.class);
+ TableIndexInodeTSInf atomicfields;
- public @atomic interface TableIndexInodeTSinf{
+ public @atomic interface TableIndexInodeTSInf{
TableIndexNodeTransactional getPrevious();
TableIndexEntryTransactional getData();
TableIndexNodeTransactional getNext();
}
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);
}
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);
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++;
}
public TableIndexEntry scanIndex(String id,int hashcode) throws IOException{
+ System.out.println("sacn index");
if(!first){
+
if(hashcode<starthash){
if(lower==-1)return null;
if(lowerpage==null){
}
}
if(hashcode>endhash){
+
if(next==-1)return null;
if(nextpage==null){
file.seek(next);
file.seek(location+BASEOFFSET);
long pre=file.getFilePointer();
while(file.getFilePointer()<pre+offset){
+ System.out.println("neddddxtex " + next);
TableIndexEntry entry=TableIndexEntry.lookForData(id,file);
if(entry!=null)return entry;
}
+ System.out.println("neddddxt " + next);
if(next==-1)return null;
+
if(nextpage==null){
+ System.out.println("next " + next);
file.seek(next);
nextpage=new TableIndexPage(index,file);
}
import TransactionalIO.core.TransactionalFile;
import dstm2.AtomicSuperClass;
import dstm2.atomic;
+import dstm2.Thread;
+import dstm2.factory.Factory;
import java.io.*;
import java.util.*;
public class TableIndexPageTransactional implements AtomicSuperClass{
- TableIndexPageTSInf atomicfields = null;
+ static Factory<TableIndexPageTSInf> 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();
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);
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);
}
file.seek(this.atomicfields.getLocation()+BASEOFFSET);
long pre=file.getFilePointer();
while(file.getFilePointer()<pre+this.atomicfields.getOffset()){
+ System.out.println("neddddxtex " + atomicfields.getNext());
TableIndexEntryTransactional entry=TableIndexEntryTransactional.lookForData(id,file);
if(entry!=null)return entry;
}
import dstm2.AtomicByteArray;
import dstm2.AtomicSuperClass;
import dstm2.atomic;
+import dstm2.factory.Factory;
import java.util.*;
- import java.io.*;
+import java.io.*;
+import dstm2.Thread;
/**
*
public class ValueTransactional implements AtomicSuperClass{
ValueTSInf atomicfields;
+ static Factory<ValueTSInf> 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);
}
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;
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){}
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();
}
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){}
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){}
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;
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;
public ValueTransactional(byte[] val){
this();
+ atomicfields.setBinary(new AtomicByteArray(Byte.class, val.length));
for (int i=0; i<val.length; i++)
atomicfields.getBinary().set(i, val[i]);
* Initializes this Value as null.
*/
public ValueTransactional(){
+ atomicfields = factory.create();
atomicfields.setStr_value(null);
- atomicfields.setInt_value(0);
+ atomicfields.setInt_value(Long.valueOf(0));
atomicfields.setFloat_value(0.0);
atomicfields.setBinary(new AtomicByteArray(Byte.class, NULL));
atomicfields.setType((byte)NULL);
*/
public ValueTransactional(int val){
this();
- atomicfields.setInt_value(val);
+ atomicfields.setInt_value(Long.valueOf(val));
atomicfields.setType((byte)INT);
}
*/
public ValueTransactional(float val){
this();
- atomicfields.setFloat_value(val);
+ atomicfields.setFloat_value(Double.valueOf(val));
atomicfields.setType((byte)FLOAT);
}
public ValueTransactional(boolean val){
this();
if(val){
- atomicfields.setInt_value(1);
+ atomicfields.setInt_value(Long.valueOf(1));
}else{
- atomicfields.setInt_value(0);
+ atomicfields.setInt_value(Long.valueOf(0));
}
atomicfields.setType((byte)BOOLEAN);
}
--- /dev/null
+/*
+ * 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 dstm2.Init;
+ import java.util.*;
+ import java.io.*;
+
+
+public class OrigParralelPerformanceTest extends BasicTest implements Runnable{
+
+ long writetime;
+ long readtime;
+ long randomtime;
+
+ public OrigParralelPerformanceTest(){
+ String path="/home/navid/Volumes/My Book/test/";
+ try{
+ //int records=50000;
+ int records=5;
+ for(int i=1;i<2/*11*/;i++){
+ outbr("Running Parallel DualFileTable Performance test");
+ outbr(1,i+" x "+(records/i)+" Large records");
+
+ // outbr(2,"Memory index");
+ /* Table table=new DualFileTable("Performance-test",path,Table.MEMORY);
+ benchmark(table,i,(records/i));
+ table.close();
+ table.deleteFiles();*/
+
+ /* outbr(2,"Flat index");
+ table=new DualFileTable("Performance-test",path,Table.FLAT);
+ benchmark(table,i,(records/i));
+ table.close();
+ table.deleteFiles();*/
+
+ outbr(2,"Paged index");
+ 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();
+
+ 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);
+ benchmark(table,i,(records/i));
+ table.close();
+ table.deleteFiles();
+
+ outbr(2,"Flat index");
+ table=new HashedTable("Performance-test",path,Table.FLAT);
+ benchmark(table,i,(records/i));
+ table.close();
+ table.deleteFiles();*/
+
+ // outbr(2,"Paged index");
+ //table=new HashedTableTransactional("Performance-test",path,TableTransactional.PAGED);
+ // table=new HashedTable("Performance-test",path,Table.PAGED);
+ // benchmark(table,i,(records/i));
+ // table.close();
+ // table.deleteFiles();*/
+ }
+
+
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+ public static void main(String[] args){
+ Init.init();
+ new OrigParralelPerformanceTest();
+ }
+
+ public void benchmark(Table table,int threadcount, int records) throws Exception{
+ writetime=0;
+ readtime=0;
+ randomtime=0;
+ List<Thread> lst=new ArrayList<Thread>();
+ for(int i=0;i<threadcount;i++){
+ Thread thr=new Thread(new OrigParralelThread(this,table,i+"",records));
+ thr.start();
+ lst.add(thr);
+ }
+ for(int i=0;i<threadcount;i++){
+ lst.get(i).join();
+ }
+ outbr(3,"Write "+writetime+" ms");
+ outbr(3,"Read "+readtime+" ms");
+ outbr(3,"Random "+randomtime+" ms");
+ }
+
+ public void run(){
+
+ }
+
+ public long benchmarkLargeWrite(Table table,int records, String id) throws IOException{
+ long pre=System.currentTimeMillis();
+ for(int i=0;i<records;i++){
+ // RowTransactional row=new RowTransactional(id+i);
+ Row row=new Row(id+i);
+ row.put("key1","foobarbaz");
+ row.put("key2",123456);
+ row.put("key3",3.141592);
+ row.put("key4",true);
+ row.put("key5",new Value(new byte[]{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}));
+ table.addRow(row);
+ }
+ long post=System.currentTimeMillis();
+ return post-pre;
+ }
+ public long benchmarkLargeRead(Table table,int records, String id) throws IOException{
+ long pre=System.currentTimeMillis();
+ TupleStream stream=table.getRows();
+ //TupleStreamTransactional stream=table.getRows();
+ while(stream.hasNext()){
+ stream.next();
+ }
+ long post=System.currentTimeMillis();
+ return post-pre;
+ }
+ public long benchmarkLargeRandomRead(Table table,int records, String id) throws IOException{
+ long pre=System.currentTimeMillis();
+ for(int i=0;i<records;i++){
+ Row row=table.getRow(id+(int)(Math.random()*records));
+ //RowTransactional row=table.getRow(id+(int)(Math.random()*records));
+ }
+ long post=System.currentTimeMillis();
+ return post-pre;
+ }
+
+ public void printStats(Hashtable<String,Long> hash){
+ Set<String> keys=hash.keySet();
+ Iterator<String> it=keys.iterator();
+ while(it.hasNext()){
+ String key=it.next();
+ outbr(4,key+" "+hash.get(key));
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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
import com.solidosystems.tuplesoup.core.*;
import com.solidosystems.tuplesoup.filter.*;
+import dstm2.Init;
import java.util.*;
import java.io.*;
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");
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);
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();*/
}
}
}
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;
}
- 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<records;i++){
- Row row=new Row(id+i);
+ RowTransactional row=new RowTransactional(id+i);
+ //Row row=new Row(id+i);
row.put("key1","foobarbaz");
row.put("key2",123456);
row.put("key3",3.141592);
row.put("key4",true);
- row.put("key5",new Value(new byte[]{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}));
+ row.put("key5",new ValueTransactional(new byte[]{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}));
table.addRow(row);
}
long post=System.currentTimeMillis();
return post-pre;
}
- public long benchmarkLargeRead(Table table,int records, String id) throws IOException{
+ public long benchmarkLargeRead(TableTransactional table,int records, String id) throws IOException{
long pre=System.currentTimeMillis();
- TupleStream stream=table.getRows();
+ //TupleStream stream=table.getRows();
+ TupleStreamTransactional stream=table.getRows();
while(stream.hasNext()){
stream.next();
}
long post=System.currentTimeMillis();
return post-pre;
}
- public long benchmarkLargeRandomRead(Table table,int records, String id) throws IOException{
+ public long benchmarkLargeRandomRead(TableTransactional table/*Table table*/,int records, String id) throws IOException{
long pre=System.currentTimeMillis();
for(int i=0;i<records;i++){
- Row row=table.getRow(id+(int)(Math.random()*records));
+ //Row row=table.getRow(id+(int)(Math.random()*records));
+ RowTransactional row=table.getRow(id+(int)(Math.random()*records));
}
long post=System.currentTimeMillis();
return post-pre;
String id;
int records;
ParallelPerformanceTest app;
- Table table;
+ //Table table;
+ TableTransactional table;
- public ParallelThread(ParallelPerformanceTest app,Table table,String id,int records){
+ public ParallelThread(ParallelPerformanceTest app,TableTransactional table/*Table table*/,String id,int records){
this.id=id;
this.records=records;
this.app=app;
public void run(){
try{
- long time=app.benchmarkLargeWrite(table,records,id);
+ long time=app.benchmarkLargeWrite(table,records,id);
synchronized(app){
app.writetime+=time;
- }
- time=app.benchmarkLargeRead(table,records,id);
+ }
+ 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();
}