From: Wolfgang M. M. <wol...@us...> - 2004-06-16 13:37:04
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/storage In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12518/src/org/exist/storage Modified Files: NativeTextEngine.java NativeElementIndex.java Log Message: Adding an attribute through xupdate didn't work. Index: NativeElementIndex.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/NativeElementIndex.java,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** NativeElementIndex.java 16 Jun 2004 09:23:49 -0000 1.29 --- NativeElementIndex.java 16 Jun 2004 13:36:54 -0000 1.30 *************** *** 413,486 **** // try to retrieve old index entry for the element try { ! lock.acquire(Lock.READ_LOCK); is = dbElement.getAsStream(ref); ! } catch (LockException e) { ! LOG.error("could not acquire lock for index on " + qname); ! return; ! } catch (IOException e) { ! LOG.error("io error while reindexing " + qname, e); ! is = null; ! } finally { ! lock.release(); ! } ! os.clear(); ! oldList.clear(); ! if (is != null) { ! // add old entries to the new list ! try { ! while (is.available() > 0) { ! docId = is.readInt(); ! len = is.readInt(); ! if (docId != oldDoc.getDocId()) { ! // section belongs to another document: ! // copy data to new buffer ! os.writeInt(docId); ! os.writeInt(len); ! is.copyTo(os, len * 4); ! } else { ! // copy nodes to new list ! last = 0; ! for (int j = 0; j < len; j++) { ! delta = is.readLong(); ! gid = last + delta; ! last = gid; ! address = StorageAddress.read(is); ! if (node == null ! && oldDoc.getTreeLevel(gid) < oldDoc ! .reindexRequired()) { ! idList.add(new NodeProxy(oldDoc, gid, ! address)); ! } else if (node != null ! && (!XMLUtil.isDescendant(oldDoc, ! node.getGID(), gid))) { ! oldList.add(new NodeProxy(oldDoc, gid, ! address)); } } } } - } catch (EOFException e) { - } catch (IOException e) { - LOG.error("io-error while updating index for element " - + qname); } ! } ! if (node != null) idList.addAll(oldList); ! // write out the updated list ! FastQSort.sort(idList, 0, idList.size() - 1); ! len = idList.size(); ! os.writeInt(doc.getDocId()); ! os.writeInt(len); ! last = 0; ! for (int j = 0; j < len; j++) { ! p = (NodeProxy) idList.get(j); ! delta = p.gid - last; ! last = p.gid; ! os.writeLong(delta); ! StorageAddress.write(p.getInternalAddress(), os); ! } ! //data = os.toByteArray(); ! try { ! lock.acquire(Lock.WRITE_LOCK); if (is == null) dbElement.put(ref, os.data()); --- 413,475 ---- // try to retrieve old index entry for the element try { ! lock.acquire(Lock.WRITE_LOCK); is = dbElement.getAsStream(ref); ! os.clear(); ! oldList.clear(); ! if (is != null) { ! // add old entries to the new list ! try { ! while (is.available() > 0) { ! docId = is.readInt(); ! len = is.readInt(); ! if (docId != oldDoc.getDocId()) { ! // section belongs to another document: ! // copy data to new buffer ! os.writeInt(docId); ! os.writeInt(len); ! is.copyTo(os, len * 4); ! } else { ! // copy nodes to new list ! last = 0; ! for (int j = 0; j < len; j++) { ! delta = is.readLong(); ! gid = last + delta; ! last = gid; ! address = StorageAddress.read(is); ! if (node == null ! && oldDoc.getTreeLevel(gid) < oldDoc ! .reindexRequired()) { ! idList.add(new NodeProxy(oldDoc, gid, ! address)); ! } else if (node != null ! && (!XMLUtil.isDescendant(oldDoc, ! node.getGID(), gid))) { ! oldList.add(new NodeProxy(oldDoc, gid, ! address)); ! } } } } + } catch (EOFException e) { + } catch (IOException e) { + LOG.error("io-error while updating index for element " + + qname); } } ! if (node != null) idList.addAll(oldList); ! // write out the updated list ! FastQSort.sort(idList, 0, idList.size() - 1); ! len = idList.size(); ! os.writeInt(doc.getDocId()); ! os.writeInt(len); ! last = 0; ! for (int j = 0; j < len; j++) { ! p = (NodeProxy) idList.get(j); ! delta = p.gid - last; ! last = p.gid; ! os.writeLong(delta); ! StorageAddress.write(p.getInternalAddress(), os); ! } ! //data = os.toByteArray(); if (is == null) dbElement.put(ref, os.data()); *************** *** 491,497 **** } } catch (LockException e) { ! LOG.error("could not acquire lock on elements", e); } finally { ! lock.release(); } } --- 480,490 ---- } } catch (LockException e) { ! LOG.error("could not acquire lock for index on " + qname); ! return; ! } catch (IOException e) { ! LOG.error("io error while reindexing " + qname, e); ! is = null; } finally { ! lock.release(Lock.WRITE_LOCK); } } Index: NativeTextEngine.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/NativeTextEngine.java,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** NativeTextEngine.java 16 Jun 2004 09:23:49 -0000 1.56 --- NativeTextEngine.java 16 Jun 2004 13:36:54 -0000 1.57 *************** *** 586,590 **** LOG.warn("Failed to acquire lock on collections.dbx", e); } finally { ! lock.release(); } } --- 586,590 ---- LOG.warn("Failed to acquire lock on collections.dbx", e); } finally { ! lock.release(Lock.WRITE_LOCK); } } *************** *** 947,1062 **** public void reindex(DocumentImpl oldDoc, NodeImpl node) { ! final short collectionId = oldDoc.getCollection().getId(); ! int len, docId; ! Map.Entry entry; ! String word; ! LongLinkedList idList; ! long[] ids; ! long last, gid; ! long delta; ! byte section; ! NodeProxy p; ! WordRef ref; ! VariableByteInput is = null; ! Lock lock = dbWords.getLock(); ! for (int k = 0; k < 2; k++) { ! for (Iterator i = words[k].entrySet().iterator(); i.hasNext();) { ! entry = (Map.Entry) i.next(); ! word = (String) entry.getKey(); ! idList = (LongLinkedList) entry.getValue(); ! ref = new WordRef(collectionId, word); ! try { ! lock.acquire(Lock.READ_LOCK); ! is = dbWords.getAsStream(ref); ! } catch (LockException e) { ! LOG.error("could not acquire lock on index for '" ! + word + "'"); ! is = null; ! } catch (IOException e) { ! LOG.error("io error while reindexing word '" + word ! + "'"); ! is = null; ! } finally { ! lock.release(); ! } ! os.clear(); ! if (is != null) { ! // add old entries to the new list ! try { ! while (is.available() > 0) { ! docId = is.readInt(); ! section = is.readByte(); ! len = is.readInt(); ! if (docId != oldDoc.getDocId() || section != k) { ! // section belongs to another document: ! // copy data to new buffer ! os.writeInt(docId); ! os.writeByte(section); ! os.writeInt(len); ! is.copyTo(os, len); ! } else { ! // copy nodes to new list ! gid = 0; ! for (int j = 0; j < len; j++) { ! delta = is.readLong(); ! gid += delta; ! if (node == null ! && oldDoc.getTreeLevel(gid) < oldDoc ! .reindexRequired()) { ! idList.add(gid); ! } else if (node != null ! && (!XMLUtil ! .isDescendantOrSelf( ! oldDoc, ! node.getGID(), ! gid))) { ! idList.add(gid); ! } ! } ! } ! } ! } catch (EOFException e) { ! //LOG.error("end-of-file while reading index entry ! // for " + word, e); ! } catch (IOException e) { ! LOG.error("io-error while reading index entry for " ! + word, e); ! } ! } ! ids = idList.getData(); ! Arrays.sort(ids); ! len = ids.length; ! os.writeInt(oldDoc.getDocId()); ! os.writeByte(k == 0 ? TEXT_SECTION : ATTRIBUTE_SECTION); ! os.writeInt(len); ! last = 0; ! for (int j = 0; j < len; j++) { ! delta = ids[j] - last; ! if (delta < 0) { ! LOG.debug("neg. delta: " + delta + " for " + word); ! LOG.debug("id = " + ids[j] + "; prev = " + last); ! } ! os.writeLong(delta); ! last = ids[j]; ! } ! try { ! lock.acquire(Lock.WRITE_LOCK); ! try { ! if (is == null) ! dbWords.put(ref, os.data()); ! else { ! dbWords.update(((BFile.PageInputStream) is) ! .getAddress(), ref, os.data()); ! } ! } catch (ReadOnlyException e) { ! } ! } catch (LockException e) { ! LOG.warn("could not acquire lock", e); ! } finally { ! lock.release(); ! } ! } ! words[k].clear(); ! } } --- 947,1055 ---- public void reindex(DocumentImpl oldDoc, NodeImpl node) { ! final short collectionId = oldDoc.getCollection().getId(); ! int len, docId; ! Map.Entry entry; ! String word; ! LongLinkedList idList; ! long[] ids; ! long last, gid; ! long delta; ! byte section; ! NodeProxy p; ! WordRef ref; ! VariableByteInput is = null; ! Lock lock = dbWords.getLock(); ! for (int k = 0; k < 2; k++) { ! for (Iterator i = words[k].entrySet().iterator(); i.hasNext();) { ! entry = (Map.Entry) i.next(); ! word = (String) entry.getKey(); ! idList = (LongLinkedList) entry.getValue(); ! ref = new WordRef(collectionId, word); ! try { ! lock.acquire(Lock.WRITE_LOCK); ! is = dbWords.getAsStream(ref); ! os.clear(); ! if (is != null) { ! // add old entries to the new list ! try { ! while (is.available() > 0) { ! docId = is.readInt(); ! section = is.readByte(); ! len = is.readInt(); ! if (docId != oldDoc.getDocId() || section != k) { ! // section belongs to another document: ! // copy data to new buffer ! os.writeInt(docId); ! os.writeByte(section); ! os.writeInt(len); ! is.copyTo(os, len); ! } else { ! // copy nodes to new list ! gid = 0; ! for (int j = 0; j < len; j++) { ! delta = is.readLong(); ! gid += delta; ! if (node == null ! && oldDoc.getTreeLevel(gid) < oldDoc ! .reindexRequired()) { ! idList.add(gid); ! } else if (node != null ! && (!XMLUtil ! .isDescendantOrSelf( ! oldDoc, ! node.getGID(), ! gid))) { ! idList.add(gid); ! } ! } ! } ! } ! } catch (EOFException e) { ! //LOG.error("end-of-file while reading index entry ! // for " + word, e); ! } catch (IOException e) { ! LOG.error("io-error while reading index entry for " ! + word, e); ! } ! } ! ids = idList.getData(); ! Arrays.sort(ids); ! len = ids.length; ! os.writeInt(oldDoc.getDocId()); ! os.writeByte(k == 0 ? TEXT_SECTION : ATTRIBUTE_SECTION); ! os.writeInt(len); ! last = 0; ! for (int j = 0; j < len; j++) { ! delta = ids[j] - last; ! if (delta < 0) { ! LOG.debug("neg. delta: " + delta + " for " + word); ! LOG.debug("id = " + ids[j] + "; prev = " + last); ! } ! os.writeLong(delta); ! last = ids[j]; ! } ! try { ! if (is == null) ! dbWords.put(ref, os.data()); ! else { ! dbWords.update(((BFile.PageInputStream) is) ! .getAddress(), ref, os.data()); ! } ! } catch (ReadOnlyException e) { ! } ! } catch (LockException e) { ! LOG.error("could not acquire lock on index for '" ! + word + "'"); ! is = null; ! } catch (IOException e) { ! LOG.error("io error while reindexing word '" + word ! + "'"); ! is = null; ! } finally { ! lock.release(Lock.WRITE_LOCK); ! } ! } ! words[k].clear(); ! } } |