Issue with UPDINDEX and db:replace (8.2.1 beta)
Wednesday, 3 June 2015 · 3 messages · last reply 5 Jun 2015
JB
James Ball3 Jun 2015 18:54 #
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 at 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”;
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=$1if [[ -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
doneCG
Christian Grün3 Jun 2015 19:07 #
Hi James,
Thanks for the example. I assume the error is due the
UPDINDEX flag.
I will check out if I can reproduce the problem. If you should manage in the meanwhile to build a little example that can be run out of the box, you are of course welcome to provide us with that example ;)
Best,
ChristianQuoted text · James Ball · 92 lines
On Wed, Jun 3, 2015 at 6:54 PM, James Ball <basex-talk at jamesball.co.uk> wrote: > 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 at 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”; > > 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
CG
Christian Grün5 Jun 2015 12:05 #
Written for BaseX 8.2. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery