Hello,
I’m running into some problems again with replacing documents when a database has updating indexes turned on.
Basically I can add a certain number of documents and then replacing a document will cause an error.
Unexpected error: Improper use? Potential bug? Your feedback is welcome: Contact: basex-talk@mailman.uni-konstanz.de Version: BaseX 8.2.1 beta 0e44488 Java: Oracle Corporation, 1.8.0_31 OS: Mac OS X, x86_64 Stack Trace: java.lang.ArrayIndexOutOfBoundsException
And then I can’t add anything.
Things I’ve tried: - turn off UPDINDEX: everything works correctly - use db:add instead of db:replace: everything works correctly
From this I don’t think there’s anything wrong with my code, or the documents themselves but instead something is amiss in the logic for updating an index. But I’m not sure exactly where to look - the trace isn’t very detailed.
I can’t narrow it down perfectly but I have managed to create a set of 5 messages (about 40kB) that will cause the error every time on my system. I can’t share these publicly but I can send them over privately for the purposes of testing if required.
I’m happy to try to look a bit closer but I’m not sure what to look at and I think you have made some changes to the updating indexes in recent versions.
Many thanks for your help, James
To recreate the error I’m using RESTXQ with the following function:
module namespace _ = 'push';
import module namespace Request = 'http://exquery.org/ns/request'; import module namespace functx = "http://www.functx.com%E2%80%9D;
declare %rest:POST("{$data}") %rest:path("/push") %updating function _:test($data) { let $odf := $data/OdfBody let $discipline := substring($odf/@DocumentCode,1,2) let $path := functx:pad-string-to-length($odf/@DocumentCode,"_",9) || functx:pad-string-to-length($odf/@DocumentSubcode,"_",10) || functx:pad-string-to-length($odf/@DocumentType,"_",30) || functx:pad-string-to-length($odf/@DocumentSubtype,"_",20) || functx:pad-string-to-length($odf/@FeedFlag,"_",1) || functx:pad-string-to-length($odf/@Language,"_",3) || ".xml" return ( if (db:exists("ODF-MIN-" || $discipline)) then ( db:replace("ODF-MIN-"||$discipline,$path,$data) (: db:add("ODF-MIN-"||$discipline,$data,$path) :) ) else ( db:create("ODF-MIN-"||$discipline,$data,$path,map { 'textindex': true(), 'attrindex':true(), 'updindex':true() }) (: db:create("ODF-MIN-"||$discipline,$data,$path) :) ) ) };
Delete the database if it exists then load the five files one at a time. I use this bash script to upload each file from a folder:
#!/bin/bash # Usage: push all .xml files in the supplied directory (or single xml file) to server shopt -s nullglob
echo $1 PASSED=$1
if [[ -d "$PASSED" ]]; then echo "Directory" FILES="$PASSED/*.xml" elif [[ -f "$PASSED" ]]; then if [[ ( $PASSED == *.xml ) || ( $PASSED == *.XML ) ]]; then FILES=$PASSED else echo "Not an XML file" exit 0 fi else echo "Not valid file or directory" exit 0 fi
for f in $FILES do echo "Pushing file - $f" curl -X POST -H 'Content-Type:text/xml' --data @$f http://localhost:8984/push done