Issue with db:add via restxq in 8.4.2
Monday, 4 April 2016 · 8 messages · last reply 12 Apr 2016
VC
Vincenzo Cestone4 Apr 2016 10:30 #
Hi guys,
in the new basex 8.4.2 version I cannot write on the db via restxq.
For example if you create an empty 'testdb',
set in the .basex conf file the option
MIXUPDATES = true,
and call the '/dbaddtest' restxq implemented as in the following: ---
module namespace o = "test";
declare
%rest:path("/dbaddtest")
%rest:GET
function o:dbaddtest() {
let $o := db:add('testdb', <aaa/>, '111.xml')
return <ok/>
};
---
it will not work in the basex 8.4.2 i.e. the document is not added to the db, but it will return <ok/> without errors.
On the contrary the db:add executed in the BaseX.jar client is working well.
And also the above restxq code is working as expected in the basex 8.3.1 version.
Thank you in advance.
Regards,
VincenzoCG
Christian Grün5 Apr 2016 12:53 #
Thanks Vincenzo,
I could reproduce the problem [1], and we’ll fix it soon.
Generally, I’d recommend you to avoid declaration of variables that will never be used. You could rewrite your code as follows:
db:add('testdb', <aaa/>, '111.xml'),
<ok/>Hope this helps,
Christian
[1] https://github.com/BaseXdb/basex/issues/1281
Quoted text · Vincenzo Cestone · 32 lines
On Mon, Apr 4, 2016 at 10:30 AM, Vincenzo Cestone <v.cestone at gmail.com> wrote: > Hi guys, > > in the new basex 8.4.2 version I cannot write on the db via restxq. > > For example if you create an empty 'testdb', > set in the .basex conf file the option MIXUPDATES = true, > and call the '/dbaddtest' restxq implemented as in the following: > --- > module namespace o = "test"; > > declare > %rest:path("/dbaddtest") > %rest:GET > function o:dbaddtest() { > let $o := db:add('testdb', <aaa/>, '111.xml') > return <ok/> > }; > --- > it will not work in the basex 8.4.2 i.e. the document is not added to the > db, but it will return <ok/> without errors. > On the contrary the db:add executed in the BaseX.jar client is working well. > > And also the above restxq code is working as expected in the basex 8.3.1 > version. > > Thank you in advance. > > Regards, > Vincenzo > >
CG
Christian Grün6 Apr 2016 15:48 #
Il problema è risolto [1,2]; grazie di nuovo.
[1] https://github.com/BaseXdb/basex/issues/1281
[2] http://files.basex.org/releases/latest/
Quoted text · Christian Grün · 51 lines
On Tue, Apr 5, 2016 at 12:53 PM, Christian Grün <christian.gruen at gmail.com> wrote: > Thanks Vincenzo, > > I could reproduce the problem [1], and we’ll fix it soon. > > Generally, I’d recommend you to avoid declaration of variables that > will never be used. You could rewrite your code as follows: > > db:add('testdb', <aaa/>, '111.xml'), > <ok/> > > Hope this helps, > Christian > > [1] https://github.com/BaseXdb/basex/issues/1281 > > > > On Mon, Apr 4, 2016 at 10:30 AM, Vincenzo Cestone <v.cestone at gmail.com> wrote: >> Hi guys, >> >> in the new basex 8.4.2 version I cannot write on the db via restxq. >> >> For example if you create an empty 'testdb', >> set in the .basex conf file the option MIXUPDATES = true, >> and call the '/dbaddtest' restxq implemented as in the following: >> --- >> module namespace o = "test"; >> >> declare >> %rest:path("/dbaddtest") >> %rest:GET >> function o:dbaddtest() { >> let $o := db:add('testdb', <aaa/>, '111.xml') >> return <ok/> >> }; >> --- >> it will not work in the basex 8.4.2 i.e. the document is not added to the >> db, but it will return <ok/> without errors. >> On the contrary the db:add executed in the BaseX.jar client is working well. >> >> And also the above restxq code is working as expected in the basex 8.3.1 >> version. >> >> Thank you in advance. >> >> Regards, >> Vincenzo >> >>
VC
Vincenzo Cestone8 Apr 2016 14:37 #
Thank you Christian,
I checked the issue of the subject with the latest release and now it is working.
But the BaseX843-20160407 release introduces a different issue (supposedly), that is a java.lang.StackOverflowError exception you can reproduce implementing a restxq with a recursive function, as in the following example:
---
module namespace api = "urn:api";
declare function api:fact($val) {
if ($val = 1) then 1
else $val * api:fact($val - 1)
};declare
%rest:path('myapi/{$v}')
%rest:GET
function api:impl_GET($v) {
<result>{api:fact($v)}</result>
};
---
Regards,
Vincenzo
2016-04-06 15:48 GMT+02:00 Christian Grün <christian.gruen at gmail.com>:
Quoted text · Christian Grün · 62 lines
> Il problema è risolto [1,2]; grazie di nuovo. > > [1] https://github.com/BaseXdb/basex/issues/1281 > [2] http://files.basex.org/releases/latest/ > > > > On Tue, Apr 5, 2016 at 12:53 PM, Christian Grün > <christian.gruen at gmail.com> wrote: > > Thanks Vincenzo, > > > > I could reproduce the problem [1], and we’ll fix it soon. > > > > Generally, I’d recommend you to avoid declaration of variables that > > will never be used. You could rewrite your code as follows: > > > > db:add('testdb', <aaa/>, '111.xml'), > > <ok/> > > > > Hope this helps, > > Christian > > > > [1] https://github.com/BaseXdb/basex/issues/1281 > > > > > > > > On Mon, Apr 4, 2016 at 10:30 AM, Vincenzo Cestone <v.cestone at gmail.com> > wrote: > >> Hi guys, > >> > >> in the new basex 8.4.2 version I cannot write on the db via restxq. > >> > >> For example if you create an empty 'testdb', > >> set in the .basex conf file the option MIXUPDATES = true, > >> and call the '/dbaddtest' restxq implemented as in the following: > >> --- > >> module namespace o = "test"; > >> > >> declare > >> %rest:path("/dbaddtest") > >> %rest:GET > >> function o:dbaddtest() { > >> let $o := db:add('testdb', <aaa/>, '111.xml') > >> return <ok/> > >> }; > >> --- > >> it will not work in the basex 8.4.2 i.e. the document is not added to > the > >> db, but it will return <ok/> without errors. > >> On the contrary the db:add executed in the BaseX.jar client is working > well. > >> > >> And also the above restxq code is working as expected in the basex 8.3.1 > >> version. > >> > >> Thank you in advance. > >> > >> Regards, > >> Vincenzo > >> > >> >
CG
Christian Grün8 Apr 2016 14:42 #
Hi Vincenzo,
This looks like a classical stack overflow issue (the same would happen in Java). I am pretty sure it also happened with earlier releases of BaseX. To fix this, you’ll rewrite your query for tail recursion [1], use fold-left [2], or increase your Java stack trace with the -Xss flag [3].
Hope this helps,
Christian
[1] https://en.wikipedia.org/wiki/Tail_call
[2] http://docs.basex.org/wiki/Higher-Order_Functions#fn:fold-left [3] https://blogs.oracle.com/saas-fusion-app-performance/entry/how_set_stack_size_to
Quoted text · Vincenzo Cestone · 93 lines
On Fri, Apr 8, 2016 at 2:37 PM, Vincenzo Cestone <v.cestone at gmail.com> wrote: > Thank you Christian, > > I checked the issue of the subject with the latest release and now it is > working. > But the BaseX843-20160407 release introduces a different issue (supposedly), > that is a java.lang.StackOverflowError exception you can reproduce > implementing a restxq with a recursive function, as in the following > example: > --- > module namespace api = "urn:api"; > > declare function api:fact($val) { > if ($val = 1) then 1 > else $val * api:fact($val - 1) > }; > > declare > %rest:path('myapi/{$v}') > %rest:GET > function api:impl_GET($v) { > <result>{api:fact($v)}</result> > }; > --- > Regards, > Vincenzo > > 2016-04-06 15:48 GMT+02:00 Christian Grün <christian.gruen at gmail.com>: >> >> Il problema è risolto [1,2]; grazie di nuovo. >> >> [1] https://github.com/BaseXdb/basex/issues/1281 >> [2] http://files.basex.org/releases/latest/ >> >> >> >> On Tue, Apr 5, 2016 at 12:53 PM, Christian Grün >> <christian.gruen at gmail.com> wrote: >> > Thanks Vincenzo, >> > >> > I could reproduce the problem [1], and we’ll fix it soon. >> > >> > Generally, I’d recommend you to avoid declaration of variables that >> > will never be used. You could rewrite your code as follows: >> > >> > db:add('testdb', <aaa/>, '111.xml'), >> > <ok/> >> > >> > Hope this helps, >> > Christian >> > >> > [1] https://github.com/BaseXdb/basex/issues/1281 >> > >> > >> > >> > On Mon, Apr 4, 2016 at 10:30 AM, Vincenzo Cestone <v.cestone at gmail.com> >> > wrote: >> >> Hi guys, >> >> >> >> in the new basex 8.4.2 version I cannot write on the db via restxq. >> >> >> >> For example if you create an empty 'testdb', >> >> set in the .basex conf file the option MIXUPDATES = true, >> >> and call the '/dbaddtest' restxq implemented as in the following: >> >> --- >> >> module namespace o = "test"; >> >> >> >> declare >> >> %rest:path("/dbaddtest") >> >> %rest:GET >> >> function o:dbaddtest() { >> >> let $o := db:add('testdb', <aaa/>, '111.xml') >> >> return <ok/> >> >> }; >> >> --- >> >> it will not work in the basex 8.4.2 i.e. the document is not added to >> >> the >> >> db, but it will return <ok/> without errors. >> >> On the contrary the db:add executed in the BaseX.jar client is working >> >> well. >> >> >> >> And also the above restxq code is working as expected in the basex >> >> 8.3.1 >> >> version. >> >> >> >> Thank you in advance. >> >> >> >> Regards, >> >> Vincenzo >> >> >> >> > >
VC
Vincenzo Cestone8 Apr 2016 15:01 #
Hi Christian,
to give more details, I can tell you that with BaseX 8.4.2 doesn't happens. Moreover in the BaseX843-20160407 release happens even if I call the restxq with the 1 value: no recursion.
2016-04-08 14:42 GMT+02:00 Christian Grün <christian.gruen at gmail.com>:
Quoted text · Christian Grün · 116 lines
> Hi Vincenzo, > > This looks like a classical stack overflow issue (the same would > happen in Java). I am pretty sure it also happened with earlier > releases of BaseX. To fix this, you’ll rewrite your query for tail > recursion [1], use fold-left [2], or increase your Java stack trace > with the -Xss flag [3]. > > Hope this helps, > Christian > > [1] https://en.wikipedia.org/wiki/Tail_call > [2] http://docs.basex.org/wiki/Higher-Order_Functions#fn:fold-left > [3] > https://blogs.oracle.com/saas-fusion-app-performance/entry/how_set_stack_size_to > > > > On Fri, Apr 8, 2016 at 2:37 PM, Vincenzo Cestone <v.cestone at gmail.com> > wrote: > > Thank you Christian, > > > > I checked the issue of the subject with the latest release and now it is > > working. > > But the BaseX843-20160407 release introduces a different issue > (supposedly), > > that is a java.lang.StackOverflowError exception you can reproduce > > implementing a restxq with a recursive function, as in the following > > example: > > --- > > module namespace api = "urn:api"; > > > > declare function api:fact($val) { > > if ($val = 1) then 1 > > else $val * api:fact($val - 1) > > }; > > > > declare > > %rest:path('myapi/{$v}') > > %rest:GET > > function api:impl_GET($v) { > > <result>{api:fact($v)}</result> > > }; > > --- > > Regards, > > Vincenzo > > > > 2016-04-06 15:48 GMT+02:00 Christian Grün <christian.gruen at gmail.com>: > >> > >> Il problema è risolto [1,2]; grazie di nuovo. > >> > >> [1] https://github.com/BaseXdb/basex/issues/1281 > >> [2] http://files.basex.org/releases/latest/ > >> > >> > >> > >> On Tue, Apr 5, 2016 at 12:53 PM, Christian Grün > >> <christian.gruen at gmail.com> wrote: > >> > Thanks Vincenzo, > >> > > >> > I could reproduce the problem [1], and we’ll fix it soon. > >> > > >> > Generally, I’d recommend you to avoid declaration of variables that > >> > will never be used. You could rewrite your code as follows: > >> > > >> > db:add('testdb', <aaa/>, '111.xml'), > >> > <ok/> > >> > > >> > Hope this helps, > >> > Christian > >> > > >> > [1] https://github.com/BaseXdb/basex/issues/1281 > >> > > >> > > >> > > >> > On Mon, Apr 4, 2016 at 10:30 AM, Vincenzo Cestone < > v.cestone at gmail.com> > >> > wrote: > >> >> Hi guys, > >> >> > >> >> in the new basex 8.4.2 version I cannot write on the db via restxq. > >> >> > >> >> For example if you create an empty 'testdb', > >> >> set in the .basex conf file the option MIXUPDATES = true, > >> >> and call the '/dbaddtest' restxq implemented as in the following: > >> >> --- > >> >> module namespace o = "test"; > >> >> > >> >> declare > >> >> %rest:path("/dbaddtest") > >> >> %rest:GET > >> >> function o:dbaddtest() { > >> >> let $o := db:add('testdb', <aaa/>, '111.xml') > >> >> return <ok/> > >> >> }; > >> >> --- > >> >> it will not work in the basex 8.4.2 i.e. the document is not added to > >> >> the > >> >> db, but it will return <ok/> without errors. > >> >> On the contrary the db:add executed in the BaseX.jar client is > working > >> >> well. > >> >> > >> >> And also the above restxq code is working as expected in the basex > >> >> 8.3.1 > >> >> version. > >> >> > >> >> Thank you in advance. > >> >> > >> >> Regards, > >> >> Vincenzo > >> >> > >> >> > > > > >
CG
Christian Grün8 Apr 2016 15:09 #
Please provide me with some code that allows me to reproduce the problem. I have run your RESTXQ sample with the latest snapshot and 8.4.2, and this is what I get:
__ latest snapshot ___
curl "http://localhost:8984/myapi/1
<result>1</result>
curl "http://localhost:8984/myapi/3
<result>6</result>
curl "http://localhost:8984/myapi/300000"
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 400 Stopped at F:/webapp/x.xq, 11/10:
[bxerr:BASX0005] Stack Overflow: Try tail recursion?</title>
</head>
...___ 8.4.2 ___
curl "http://localhost:8984/myapi/1
<result>1</result>
curl "http://localhost:8984/myapi/3
<result>6</result>
curl "http://localhost:8984/myapi/300000"
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 400 Stopped at C:/Users/user/Desktop/basex/webapp/x.xq, 11/10:
[bxerr:BASX0005] Stack Overflow: Try tail recursion?</title>
</head>
...CG
Christian Grün12 Apr 2016 12:12 #
…the issue has been resolved, as confirmed by Vincenzo (thanks for the reply).
Quoted text · Christian Grün · 39 lines
On Fri, Apr 8, 2016 at 3:09 PM, Christian Grün <christian.gruen at gmail.com> wrote: > Please provide me with some code that allows me to reproduce the > problem. I have run your RESTXQ sample with the latest snapshot and > 8.4.2, and this is what I get: > > __ latest snapshot ___ > > curl "http://localhost:8984/myapi/1 > <result>1</result> > > curl "http://localhost:8984/myapi/3 > <result>6</result> > > curl "http://localhost:8984/myapi/300000" > <html> > <head> > <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> > <title>Error 400 Stopped at F:/webapp/x.xq, 11/10: > [bxerr:BASX0005] Stack Overflow: Try tail recursion?</title> > </head> > ... > > ___ 8.4.2 ___ > > curl "http://localhost:8984/myapi/1 > <result>1</result> > > curl "http://localhost:8984/myapi/3 > <result>6</result> > > curl "http://localhost:8984/myapi/300000" > <html> > <head> > <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> > <title>Error 400 Stopped at C:/Users/user/Desktop/basex/webapp/x.xq, 11/10: > [bxerr:BASX0005] Stack Overflow: Try tail recursion?</title> > </head> > ...
Written for BaseX 8.4. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery