From: Wolfgang M. M. <wol...@us...> - 2004-07-12 17:17:52
|
Update of /cvsroot/exist/eXist-1.0/src/org/dbxml/core/filer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32480/src/org/dbxml/core/filer Modified Files: Paged.java Log Message: Various concurrency-related bug fixes: * there has been a conflicting access to the owner property in class DOMFile: in some cases, a second thread set the property to itself while another thread has been in the process of writing data. As the owner object is used to determine the current page in the document, the writing thread used a wrong data page (for a very short period). Thus, one or two document nodes got lost. * a number of small caching problems in dom.dbx led to inconsistencies in the db. Also, queries using string-equality comparisons did not use the cache, so increasing the cache size had no positive effect on query speed. Index: Paged.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/dbxml/core/filer/Paged.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** Paged.java 14 Apr 2004 12:17:23 -0000 1.23 --- Paged.java 12 Jul 2004 17:17:43 -0000 1.24 *************** *** 456,463 **** protected final void writeValue(Page page, Value value) throws IOException { byte[] data = value.getData(); PageHeader hdr = page.getPageHeader(); hdr.dataLen = fileHeader.workSize; ! if (data.length < hdr.dataLen) hdr.dataLen = data.length; page.write(data); } --- 456,468 ---- protected final void writeValue(Page page, Value value) throws IOException { byte[] data = value.getData(); + writeValue(page, data); + } + + protected final void writeValue(Page page, byte[] data) throws IOException { PageHeader hdr = page.getPageHeader(); hdr.dataLen = fileHeader.workSize; ! if (data.length < hdr.dataLen) { hdr.dataLen = data.length; + } page.write(data); } *************** *** 820,824 **** this(); if(pageNum < 0) ! Thread.dumpStack(); setPageNum(pageNum); } --- 825,829 ---- this(); if(pageNum < 0) ! throw new IOException("Illegal page num: " + pageNum); setPageNum(pageNum); } *************** *** 865,882 **** } - /** - * Gets the pageNum attribute of the Page object - * - *@return The pageNum value - */ public long getPageNum() { return pageNum; } - /** - * Gets the refCount attribute of the Page object - * - *@return The refCount value - */ public int getRefCount() { return refCount; --- 870,877 ---- *************** *** 887,913 **** } - /** Description of the Method */ public void incRefCount() { refCount++; } - /** - * Description of the Method - * - *@exception IOException Description of the Exception - */ public byte[] read() throws IOException { try { if (raf.getFilePointer() != offset) { raf.seek(offset); } Arrays.fill(tempHeaderData, (byte)0); raf.read(tempHeaderData); ! // Read in the header header.read(tempHeaderData, 0); // Read the working data final byte[] workData = new byte[header.dataLen]; raf.read(workData); return workData; } catch(Exception e) { --- 882,906 ---- } public void incRefCount() { refCount++; } public byte[] read() throws IOException { try { + // dumpPage(); if (raf.getFilePointer() != offset) { raf.seek(offset); } + Arrays.fill(tempHeaderData, (byte)0); raf.read(tempHeaderData); ! // Read in the header header.read(tempHeaderData, 0); + // Read the working data final byte[] workData = new byte[header.dataLen]; raf.read(workData); + return workData; } catch(Exception e) { *************** *** 916,925 **** } } ! ! /** ! * Sets the pageNum attribute of the Page object ! * ! *@param pageNum The new pageNum value ! */ public void setPageNum(long pageNum) { this.pageNum = pageNum; --- 909,913 ---- } } ! public void setPageNum(long pageNum) { this.pageNum = pageNum; *************** *** 930,940 **** write(null); } ! private final void write(byte[] data) throws IOException { ! //System.out.println(getFile().getName() + " writing page " + pageNum); if(data == null) // Removed page: fill with 0 Arrays.fill(tempPageData, (byte)0); ! // Write out the header header.write(tempPageData, 0); --- 918,928 ---- write(null); } ! private final void write(byte[] data) throws IOException { ! if(data == null) // Removed page: fill with 0 Arrays.fill(tempPageData, (byte)0); ! // Write out the header header.write(tempPageData, 0); *************** *** 972,975 **** --- 960,971 ---- return -1; } + + public void dumpPage() throws IOException { + if (raf.getFilePointer() != offset) + raf.seek(offset); + byte[] data = new byte[fileHeader.pageSize]; + raf.read(data); + LOG.debug("Contents of page " + pageNum + ": " + hexDump(data)); + } } *************** *** 1035,1038 **** --- 1031,1044 ---- } + public int write(byte[] data, int offset) throws IOException { + data[offset++] = status; + ByteConversion.intToByte(dataLen, data, offset); + offset += 4; + ByteConversion.longToByte(nextPage, data, offset); + offset += 8; + dirty = false; + return offset; + } + /** * The length of the Data *************** *** 1068,1082 **** dirty = true; } ! ! public int write(byte[] data, int offset) throws IOException { ! data[offset++] = status; ! ByteConversion.intToByte(dataLen, data, offset); ! offset += 4; ! ByteConversion.longToByte(nextPage, data, offset); ! offset += 8; ! dirty = false; ! return offset; } } } --- 1074,1108 ---- dirty = true; } ! ! } ! ! private static String[] hex = {"0", "1", "2", "3", "4", "5", "6", "7", ! "8", "9", "a", "b", "c", "d", "e", "f"}; ! ! public static String hexDump(byte[] data) { ! StringBuffer buf = new StringBuffer(); ! buf.append("\r\n"); ! int columns = 0; ! for(int i = 0; i < data.length; i++, columns++) { ! byteToHex(buf, data[i]); ! if(columns == 16) { ! buf.append("\r\n"); ! columns = 0; ! } else ! buf.append(' '); } + return buf.toString(); } + private static void byteToHex( StringBuffer buf, byte b ) { + int n = b; + if ( n < 0 ) { + n = 256 + n; + } + int d1 = n / 16; + int d2 = n % 16; + buf.append( hex[d1] ); + buf.append( hex[d2] ); + } + } |