From: Wolfgang M. M. <wol...@us...> - 2004-03-29 14:26:42
|
Update of /cvsroot/exist/eXist-1.0/src/org/dbxml/core/filer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31676/src/org/dbxml/core/filer Modified Files: BTree.java Paged.java Log Message: * Fixed stability issues: collection pointers got corrupted occasionally, resulting in ArrayIndexOutOfBoundsExceptions. * Added check for file format versions: the database will throw an exception if the database files are incompatible with the current eXist version. Index: Paged.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/dbxml/core/filer/Paged.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** Paged.java 29 Jan 2004 15:06:48 -0000 1.19 --- Paged.java 29 Mar 2004 14:15:13 -0000 1.20 *************** *** 100,103 **** --- 100,107 ---- } + public short getFileVersion() { + return 0; + } + public final static void setPageSize(int pageSize) { PAGE_SIZE = pageSize; *************** *** 191,194 **** --- 195,203 ---- public boolean close() throws DBException { + try { + raf.close(); + } catch (IOException e) { + throw new DBException("an error occurred while closing database file: " + e.getMessage()); + } return true; } *************** *** 347,360 **** } ! /** ! * Description of the Method ! * ! *@return Description of the Return Value ! *@exception DBException Description of the Exception ! */ ! public boolean open() throws DBException { try { if (exists()) { fileHeader.read(); return true; } else --- 356,367 ---- } ! public boolean open(short expectedVersion) throws DBException { try { if (exists()) { fileHeader.read(); + if(fileHeader.getVersion() != expectedVersion) + throw new DBException("Database file " + + getFile().getName() + " has a storage format incompatible with this " + + "version of eXist. Please do a backup/restore of your data first."); return true; } else *************** *** 472,484 **** writeValue(getPage(page), value); } ! /** * FileHeader * *@author Wolfgang Meier <me...@if...> - *@created 26. Mai 2002 */ public abstract class FileHeader { private boolean dirty = false; private long firstFreePage = -1; --- 479,493 ---- writeValue(getPage(page), value); } ! /** * FileHeader * *@author Wolfgang Meier <me...@if...> */ public abstract class FileHeader { + + private short versionId; + private boolean dirty = false; private long firstFreePage = -1; *************** *** 508,542 **** } - /** - * Constructor for the FileHeader object - * - *@param pageCount Description of the Parameter - *@param pageSize Description of the Parameter - */ public FileHeader(long pageCount, int pageSize) { this(pageCount, pageSize, (byte) 4); } - /** - * Constructor for the FileHeader object - * - *@param pageCount Description of the Parameter - *@param pageSize Description of the Parameter - *@param blockSize Description of the Parameter - */ public FileHeader(long pageCount, int pageSize, byte blockSize) { this.pageSize = pageSize; this.pageCount = pageCount; ! totalCount = pageCount; ! headerSize = (short) pageSize; calculateWorkSize(); } - /** - * Constructor for the FileHeader object - * - *@param read Description of the Parameter - *@exception IOException Description of the Exception - */ public FileHeader(boolean read) throws IOException { if (read) --- 517,533 ---- } public FileHeader(long pageCount, int pageSize) { this(pageCount, pageSize, (byte) 4); } public FileHeader(long pageCount, int pageSize, byte blockSize) { this.pageSize = pageSize; this.pageCount = pageCount; ! this.totalCount = pageCount; ! this.headerSize = (short) pageSize; ! this.versionId = getFileVersion(); calculateWorkSize(); } public FileHeader(boolean read) throws IOException { if (read) *************** *** 644,647 **** --- 635,642 ---- } + public final short getVersion() { + return versionId; + } + /** Increment the number of records being managed by the file */ public final synchronized void incRecordCount() { *************** *** 659,667 **** } - /** - * Description of the Method - * - *@exception IOException Description of the Exception - */ public final synchronized void read() throws IOException { raf.seek(0); --- 654,657 ---- *************** *** 671,681 **** } - /** - * Description of the Method - * - *@param raf Description of the Parameter - *@exception IOException Description of the Exception - */ public void read(RandomAccessFile raf) throws IOException { headerSize = raf.readShort(); pageSize = raf.readInt(); --- 661,666 ---- } public void read(RandomAccessFile raf) throws IOException { + versionId = raf.readShort(); headerSize = raf.readShort(); pageSize = raf.readInt(); *************** *** 790,798 **** } - /** - * Description of the Method - * - *@exception IOException Description of the Exception - */ public final synchronized void write() throws IOException { raf.seek(0); --- 775,778 ---- *************** *** 801,811 **** } - /** - * Description of the Method - * - *@param raf Description of the Parameter - *@exception IOException Description of the Exception - */ public void write(RandomAccessFile raf) throws IOException { raf.writeShort(headerSize); raf.writeInt(pageSize); --- 781,786 ---- } public void write(RandomAccessFile raf) throws IOException { + raf.writeShort(versionId); raf.writeShort(headerSize); raf.writeInt(pageSize); Index: BTree.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/dbxml/core/filer/BTree.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** BTree.java 2 Feb 2004 15:30:38 -0000 1.20 --- BTree.java 29 Mar 2004 14:15:13 -0000 1.21 *************** *** 133,138 **** } ! public boolean open() throws DBException { ! if (super.open()) { cache = new LRDCache(buffers); cache.setFileName(getFile().getName()); --- 133,138 ---- } ! public boolean open(short expectedVersion) throws DBException { ! if (super.open(expectedVersion)) { cache = new LRDCache(buffers); cache.setFileName(getFile().getName()); *************** *** 431,436 **** private int calcDataLen() { int length = ptrs == null ? 0 : ptrs.length << 3; ! final int keyLen = fileHeader.getFixedKeyLen() < 0 ? 2 : 0; ! length += keyLen * values.length; for (int i = 0; i < values.length; i++) length += values[i].getLength(); --- 431,436 ---- private int calcDataLen() { int length = ptrs == null ? 0 : ptrs.length << 3; ! if(fileHeader.getFixedKeyLen() < 0) ! length += 2 * values.length; for (int i = 0; i < values.length; i++) length += values[i].getLength(); *************** *** 667,672 **** idx = - (idx + 1); - // Check to see if we've exhausted the block - //boolean split = ph.getDataLen() + 6 + value.getLength() > fileHeader.getWorkSize(); setValues(insertArrayValue(values, value.trim(), //new Value(value.getData()), --- 667,670 ---- *************** *** 688,693 **** public void promoteValue(Value value, long rightPointer) throws IOException, BTreeException { - // Check to see if we've exhausted the block - //boolean split = ph.getDataLen() + 6 + value.getLength() > fileHeader.getWorkSize(); int idx = Arrays.binarySearch(values, value); if (idx < 0) --- 686,689 ---- *************** *** 701,705 **** if (split) split(); - //write(); } --- 697,700 ---- |