From e2d377f73580d6d599109efe8774396f4c63cf34 Mon Sep 17 00:00:00 2001 From: navid Date: Tue, 27 Jan 2009 01:12:16 +0000 Subject: [PATCH] *** empty log message *** --- .../core/TransactionalFile.java | 129 ++++++++++++++++-- .../tuplesoup/core/DualFileTable.java | 3 + .../core/DualFileTableTransactional.java | 61 +++++---- .../core/IndexedTableReaderTransactional.java | 26 ++-- .../tuplesoup/core/PagedIndex.java | 9 +- .../core/PagedIndexTransactional.java | 22 +-- .../tuplesoup/core/RowTransactional.java | 19 ++- .../core/TableIndexEntryTransactional.java | 1 + .../tuplesoup/core/TableIndexPage.java | 25 ++-- .../core/TableIndexPageTransactional.java | 46 ++++--- .../tuplesoup/core/ValueTransactional.java | 29 +++- 11 files changed, 276 insertions(+), 94 deletions(-) diff --git a/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/TransactionalFile.java b/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/TransactionalFile.java index 22bac250..694246a9 100644 --- a/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/TransactionalFile.java +++ b/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/TransactionalFile.java @@ -342,28 +342,139 @@ public class TransactionalFile implements Comparable { return (int) (newpos - pos); } - public final int readByte(){ + public final byte readByte(){ byte[] data = new byte[1]; read(data); - int result = (byte)(data[0]); + byte result = (byte)(data[0]); return result; } - public final int readChar(){ + public final boolean readBoolean(){ + byte[] data = new byte[1]; + read(data); + if (data[0] == 0 ) + return false; + return true; + //return ((boolean)data[0]);// != 0); + } + + public final char readChar(){ byte[] data = new byte[2]; read(data); - int result = (char)((data[0] << 8) | data[0]); + char result = (char)((data[0] << 8) | data[0]); return result; } - public final int readShort(){ + public final short readShort(){ byte[] data = new byte[2]; read(data); - int result = (short)((data[0] << 8) | data[1]); - System.out.println("res " + result); + short result = (short)((data[0] << 8) | data[1]); + // System.out.println("res " + result); return result; } + public final int readUnsignedShort() throws IOException { + byte[] data = new byte[2]; + read(data); + return (data[0] << 8) + (data[1] << 0); + } + + public final String readUTF() throws UTFDataFormatException{ + int utflen = -1; + byte[] bytearr = null; + char[] chararr = null; + try { + utflen = readUnsignedShort(); + } catch (IOException ex) { + Logger.getLogger(TransactionalFile.class.getName()).log(Level.SEVERE, null, ex); + } + bytearr = new byte[utflen]; + chararr = new char[utflen]; + + + int c, char2, char3; + int count = 0; + int chararr_count = 0; + + read(bytearr); + + while (count < utflen) { + c = (int) bytearr[count] & 0xff; + if (c > 127) + break; + count++; + chararr[chararr_count++] = (char) c; + } + + while (count < utflen) { + c = (int) bytearr[count] & 0xff; + switch (c >> 4) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + /* 0xxxxxxx*/ + count++; + chararr[chararr_count++] = (char) c; + break; + case 12: + case 13: + /* 110x xxxx 10xx xxxx*/ + count += 2; + if (count > utflen) + throw new UTFDataFormatException( + "malformed input: partial character at end"); + char2 = (int) bytearr[count - 1]; + if ((char2 & 0xC0) != 0x80) + throw new UTFDataFormatException( + "malformed input around byte " + count); + chararr[chararr_count++] = (char) (((c & 0x1F) << 6) | (char2 & 0x3F)); + break; + case 14: + /* 1110 xxxx 10xx xxxx 10xx xxxx */ + count += 3; + if (count > utflen) + throw new UTFDataFormatException( + "malformed input: partial character at end"); + char2 = (int) bytearr[count - 2]; + char3 = (int) bytearr[count - 1]; + if (((char2 & 0xC0) != 0x80) + || ((char3 & 0xC0) != 0x80)) + throw new UTFDataFormatException( + "malformed input around byte " + + (count - 1)); + chararr[chararr_count++] = (char) (((c & 0x0F) << 12) + | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0)); + break; + default: + /* 10xx xxxx, 1111 xxxx */ + throw new UTFDataFormatException( + "malformed input around byte " + count); + } + } + // The number of chars produced may be less than utflen + return new String(chararr, 0, chararr_count); + + } + + public final float readFloat(){ + // byte[] data = new byte[4]; + // int k = read(data); + return Float.intBitsToFloat(readInt()); + // float result = Conversions.bytes2float(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 double readDouble(){ + return Double.longBitsToDouble(readLong()); + } + public final int readInt(){ byte[] data = new byte[4]; @@ -371,7 +482,7 @@ public class TransactionalFile implements Comparable { 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); + // System.out.println("int res " + result); return result; } @@ -381,7 +492,7 @@ public class TransactionalFile implements Comparable { 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 = Conversions.bytes2long(data); - System.out.println("long res " + result); + // System.out.println("long res " + result); return result; } 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 f4f17d13..cbc26ac1 100644 --- a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/DualFileTable.java +++ b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/DualFileTable.java @@ -548,8 +548,10 @@ public class DualFileTable implements Table{ TableIndexEntry entry=null; // Handle index entry caching if(INDEXCACHESIZE>0){ + // System.out.println("in h"); synchronized(indexcache){ entry=getCacheEntry(id); + // System.out.println(entry); if(entry==null){ entry=index.scanIndex(id); if(entry!=null){ @@ -563,6 +565,7 @@ public class DualFileTable implements Table{ if(entry!=null){ long dataoffset=0; DataInputStream data=null; + // System.out.println(entry); if(entry.location==Table.FILEA){ data=new DataInputStream(new BufferedInputStream(new FileInputStream(getFileName(Table.FILEA)))); }else if(entry.location==Table.FILEB){ 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 483b0e9d..971feb1d 100644 --- a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/DualFileTableTransactional.java +++ b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/DualFileTableTransactional.java @@ -355,7 +355,9 @@ public class DualFileTableTransactional implements TableTransactional{ args.add(row); Thread.doIt(new Callable() { public Boolean call() throws Exception{ - openFile(FILEA); + + openFile(FILEA); + //int pre=fileastream.size(); int pre= (int)fileastream.getFilePointer(); //row.writeToStream(fileastream); @@ -374,7 +376,7 @@ public class DualFileTableTransactional implements TableTransactional{ TableIndexEntryTransactional entry=new TableIndexEntryTransactional(((RowTransactional)args.get(0)).getId(),((RowTransactional)args.get(0)).getSize(),FILEA,atomicfields.getFileaposition()); addCacheEntry(entry); } - atomicfields.setFileaposition(atomicfields.getFileaposition()+Row.calcSize(pre,post)); + atomicfields.setFileaposition(atomicfields.getFileaposition()+RowTransactional.calcSize(pre,post)); return true; } }); @@ -402,7 +404,7 @@ public class DualFileTableTransactional implements TableTransactional{ TableIndexEntryTransactional entry=new TableIndexEntryTransactional(((RowTransactional)args.get(0)).getId(),((RowTransactional)args.get(0)).getSize(),FILEB,atomicfields.getFilebposition()); addCacheEntry(entry); } - atomicfields.setFilebposition(atomicfields.getFilebposition()+Row.calcSize(pre,post)); + atomicfields.setFilebposition(atomicfields.getFilebposition()+RowTransactional.calcSize(pre,post)); return true; } }); @@ -517,19 +519,19 @@ public class DualFileTableTransactional implements TableTransactional{ TableIndexEntryTransactional entry=null; final Vector args = new Vector(); args.add(row); - args.add(entry); + //args.add(entry); // Handle index entry caching if(INDEXCACHESIZE>0){ - Thread.doIt(new Callable() { - public Boolean call() throws Exception { - TableIndexEntryTransactional entry = (TableIndexEntryTransactional) (args.get(1)); + entry = Thread.doIt(new Callable() { + public TableIndexEntryTransactional call() throws Exception { + TableIndexEntryTransactional entry;// = (TableIndexEntryTransactional) (args.get(1)); RowTransactional row = (RowTransactional) (args.get(0)); entry = getCacheEntry(row.getId()); if(entry==null){ entry=index.scanIndex(row.getId()); addCacheEntry(entry); } - return true; + return entry; } }); /* synchronized(indexcache){ @@ -598,9 +600,11 @@ public class DualFileTableTransactional implements TableTransactional{ private void updateRowA(RowTransactional row) throws IOException{ final Vector args = new Vector(); args.add(row); + System.out.println("b"); Thread.doIt(new Callable() { public Boolean call() throws Exception{ //synchronized(filealock){ + System.out.println("add a"); openFile(FILEA); //int pre=filebstream.size(); int pre=(int)fileastream.getFilePointer(); @@ -623,10 +627,11 @@ public class DualFileTableTransactional implements TableTransactional{ private void updateRowB(RowTransactional row) throws IOException{ final Vector args = new Vector(); + System.out.println("b"); args.add(row); Thread.doIt(new Callable() { public Boolean call() throws Exception{ - + System.out.println("add b"); //synchronized(fileblock){ openFile(FILEB); //int pre=filebstream.size(); @@ -703,36 +708,44 @@ public class DualFileTableTransactional implements TableTransactional{ */ public RowTransactional getRow(String id) throws IOException{ TableIndexEntryTransactional entry=null; + final Vector args = new Vector(); + args.add(id); + // args.add(entry); // Handle index entry caching if(INDEXCACHESIZE>0){ - final Vector args = new Vector(); - args.add(id); - args.add(entry); + //synchronized(indexcache){ - Thread.doIt(new Callable() { - public Boolean call() throws Exception{ - TableIndexEntryTransactional entry = (TableIndexEntryTransactional) (args.get(1)); + entry = Thread.doIt(new Callable() { + public TableIndexEntryTransactional call() throws Exception{ + TableIndexEntryTransactional entry;// = (TableIndexEntryTransactional) (args.get(1)); String id = (String) (args.get(0)); entry=getCacheEntry(id); + // System.out.println("presalam " + (TableIndexEntryTransactional) (args.get(1))); if(entry==null){ entry=index.scanIndex(id); if(entry!=null){ addCacheEntry(entry); } } - return true; + return entry; } }); }else{ entry=index.scanIndexTransactional(id); } +// entry = (TableIndexEntryTransactional) (args.get(1)); + // args.clear(); + if(entry!=null){ long dataoffset=0; - DataInputStream data=null; - if(entry.getLocation()==Table.FILEA){ - data=new DataInputStream(new BufferedInputStream(new FileInputStream(getFileName(Table.FILEA)))); - }else if(entry.getLocation()==Table.FILEB){ - data=new DataInputStream(new BufferedInputStream(new FileInputStream(getFileName(Table.FILEB)))); + //DataInputStream data=null; + TransactionalFile data=null; + if(entry.getLocation()==TableTransactional.FILEA){ + //data=new DataInputStream(new BufferedInputStream(new FileInputStream(getFileName(TableTransactional.FILEA)))); + data=new TransactionalFile(getFileName(TableTransactional.FILEA), "rw"); + }else if(entry.getLocation()==TableTransactional.FILEB){ + data=new TransactionalFile(getFileName(TableTransactional.FILEB), "rw"); + //data=new DataInputStream(new BufferedInputStream(new FileInputStream(getFileName(TableTransactional.FILEB)))); } if(data!=null){ while(dataoffset!=entry.getPosition()){ @@ -740,13 +753,13 @@ public class DualFileTableTransactional implements TableTransactional{ } RowTransactional row=RowTransactional.readFromStream(data); data.close(); - final Vector args = new Vector(); - args.add(row); + final Vector args2 = new Vector(); + args2.add(row); Thread.doIt(new Callable() { public Boolean call() throws Exception{ //synchronized(statlock){ atomicfields.setstat_read(atomicfields.getstat_read()+1); - atomicfields.setstat_read_size(atomicfields.getstat_read_size()+((RowTransactional)args.get(0)).getSize()); + atomicfields.setstat_read_size(atomicfields.getstat_read_size()+((RowTransactional)args2.get(0)).getSize()); return true; } }); 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 e9c5cad7..0289d575 100644 --- a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/IndexedTableReaderTransactional.java +++ b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/IndexedTableReaderTransactional.java @@ -31,6 +31,7 @@ package com.solidosystems.tuplesoup.core; +import TransactionalIO.core.TransactionalFile; import com.solidosystems.tuplesoup.filter.*; import java.io.*; import java.util.*; @@ -41,8 +42,11 @@ import dstm2.factory.Factory; public class IndexedTableReaderTransactional extends TupleStreamTransactional{ - private DataInputStream fileastream=null; - private DataInputStream filebstream=null; + private TransactionalFile fileastream=null; + private TransactionalFile filebstream=null; + + //private DataInputStream fileastream=null; + //private DataInputStream filebstream=null; private long fileaposition=0; private long filebposition=0; @@ -76,9 +80,9 @@ public class IndexedTableReaderTransactional extends TupleStreamTransactional{ TableIndexEntryTransactional entry=it.next(); // TODO: we really shouldn't get nulls here if(entry!=null){ - if(entry.getLocation()==Table.FILEA){ + if(entry.getLocation()==TableTransactional.FILEA){ fileaentries.add(entry); - }else if(entry.getLocation()==Table.FILEB){ + }else if(entry.getLocation()==TableTransactional.FILEB){ filebentries.add(entry); } } @@ -109,9 +113,9 @@ public class IndexedTableReaderTransactional extends TupleStreamTransactional{ TableIndexEntryTransactional entry=it.next(); // TODO: we really shouldn't get nulls here if(entry!=null){ - if(entry.getLocation()==Table.FILEA){ + if(entry.getLocation()==TableTransactional.FILEA){ fileaentries.add(entry); - }else if(entry.getLocation()==Table.FILEB){ + }else if(entry.getLocation()==TableTransactional.FILEB){ filebentries.add(entry); } } @@ -135,7 +139,8 @@ public class IndexedTableReaderTransactional extends TupleStreamTransactional{ if(fileaentries.size()>0){ TableIndexEntryTransactional nextfilea=fileaentries.remove(0); if(fileastream==null){ - fileastream=new DataInputStream(new BufferedInputStream(new FileInputStream(table.getFileName(Table.FILEA)))); + fileastream=new TransactionalFile(table.getFileName(TableTransactional.FILEA), "rw"); + // fileastream=new DataInputStream(new BufferedInputStream(new FileInputStream(table.getFileName(TableTransactional.FILEA)))); fileaposition=0; } if(fileaposition>nextfilea.getPosition()){ @@ -185,7 +190,8 @@ public class IndexedTableReaderTransactional extends TupleStreamTransactional{ if(filebentries.size()>0){ TableIndexEntryTransactional nextfileb=filebentries.remove(0); if(filebstream==null){ - filebstream=new DataInputStream(new BufferedInputStream(new FileInputStream(table.getFileName(Table.FILEB)))); + fileastream=new TransactionalFile(table.getFileName(TableTransactional.FILEB), "rw"); + //filebstream=new DataInputStream(new BufferedInputStream(new FileInputStream(table.getFileName(TableTransactional.FILEB)))); filebposition=0; } if(filebposition>nextfileb.getPosition()){ @@ -230,10 +236,10 @@ public class IndexedTableReaderTransactional extends TupleStreamTransactional{ TableIndexEntryTransactional entry=entries.get(rowpointer++); if(entry!=null){ switch(entry.getLocation()){ - case Table.FILEA : readNextFromFileA(entry); + case TableTransactional.FILEA : readNextFromFileA(entry); // return; break; - case Table.FILEB : readNextFromFileB(entry); + case TableTransactional.FILEB : readNextFromFileB(entry); // return; break; } 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 a36fb047..66144350 100644 --- a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/PagedIndex.java +++ b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/PagedIndex.java @@ -39,8 +39,11 @@ import java.nio.channels.*; public class PagedIndex implements TableIndex{ -protected static final int INITIALPAGEHASH=1024; - protected static final int PAGESIZE=2048; +//protected static final int INITIALPAGEHASH=1024; + // protected static final int PAGESIZE=2048; + + protected static final int INITIALPAGEHASH=32; + protected static final int PAGESIZE=64; private RandomAccessFile out=null; private String filename; @@ -65,13 +68,11 @@ protected static final int INITIALPAGEHASH=1024; for(int i=0;i(TableIndexPageTransactional.class, INITIALPAGEHASH)); - System.out.println(filename); - System.out.println(out.length()); + // System.out.println(filename); + // System.out.println(out.length()); if(out.length()>0){ for(int i=0;i scanIndex(List rows) throws IOException{ + public /*synchronized*/ List scanIndex(List rows) throws IOException{ final List rows2 = rows; return Thread.doIt(new Callable>() { public List call() throws Exception{ @@ -168,7 +172,7 @@ public class PagedIndexTransactional implements TableIndexTransactional{ String id=rows2.get(i); TableIndexEntryTransactional entry=scanIndex(id); if(entry!=null){ - if(entry.getLocation()!=Table.DELETE)lst.add(entry); + if(entry.getLocation()!=TableTransactional.DELETE)lst.add(entry); } } return lst; @@ -179,9 +183,11 @@ public class PagedIndexTransactional implements TableIndexTransactional{ return Thread.doIt(new Callable>() { public List call() throws Exception{ ArrayList lst=new ArrayList(); + System.out.println(Thread.currentThread() + " start"); for(int i=0;i{"name":string:"Kasper J. Jeppesen","age":int:31} diff --git a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/TableIndexEntryTransactional.java b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/TableIndexEntryTransactional.java index eaca765b..aa550bf4 100644 --- a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/TableIndexEntryTransactional.java +++ b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/TableIndexEntryTransactional.java @@ -145,6 +145,7 @@ public class TableIndexEntryTransactional implements AtomicSuperClass, Comparabl protected static TableIndexEntryTransactional readData(TransactionalFile in) throws IOException{ long pre=in.getFilePointer(); in.readInt(); + //short num=in.readShort(); int num=in.readShort(); //System.out.println("num= " + num); StringBuilder buf=new StringBuilder(num); 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 dc8c2890..f260cf2f 100644 --- a/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/TableIndexPage.java +++ b/Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/TableIndexPage.java @@ -58,39 +58,33 @@ public class TableIndexPage{ 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); + // 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"); + // 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.writeInt(size); 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++; @@ -148,6 +142,7 @@ public class TableIndexPage{ } file.seek(location+BASEOFFSET); long pre=file.getFilePointer(); + System.out.println(Thread.currentThread() + " " +offset + " " + pre); while(file.getFilePointer()