Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Won't Fix
-
None
-
None
-
None
Description
CouchDB 2.0 violates some query server protocol's rules. It is possible to receive "add_fun" without preceding "add_lib". This doesn't happen in CouchDB 1.6
Design document (just example)
{ "_id": "_design/test", "_rev": "2-e4b55d8d82fe023421624901deb9cf17", "views": { "lib": { "utils": "exports.MAGIC = 42;" }, "test": { "map": "function(doc) {emit(doc._id,doc._rev);}", "reduce": "function(keys,values,rereduce) {if (rereduce) return sum(values); else return values.length;}" } } }
Recorded log:
[debug] 2017-04-21T06:48:46.000000Z couchdb@localhost <0.7374.0> -------- OS Process #Port<0.7565> Input :: ["reset",{"reduce_limit":true,"timeout":5000}] [debug] 2017-04-21T06:48:46.001000Z couchdb@localhost <0.7374.0> -------- OS Process #Port<0.7565> Output :: true [debug] 2017-04-21T06:48:46.001000Z couchdb@localhost <0.7374.0> -------- OS Process #Port<0.7565> Input :: ["add_fun","function(doc) {emit(doc._id,doc._rev);}"] [debug] 2017-04-21T06:48:46.003000Z couchdb@localhost <0.7374.0> -------- OS Process #Port<0.7565> Output :: true [debug] 2017-04-21T06:48:46.004000Z couchdb@localhost <0.7374.0> -------- OS Process #Port<0.7565> Input :: ["add_fun","function(keys,values,rereduce) {if (rereduce) return sum(values); else return values.length;}"] [debug] 2017-04-21T06:48:46.007000Z couchdb@localhost <0.7374.0> -------- OS Process #Port<0.7565> Output :: true
However, later
[debug] 2017-04-21T06:49:01.525000Z couchdb@localhost <0.7372.0> -------- OS Process #Port<0.7564> Input :: ["reset",{"reduce_limit":true,"timeout":5000}] [debug] 2017-04-21T06:49:01.525000Z couchdb@localhost <0.7372.0> -------- OS Process #Port<0.7564> Output :: true [debug] 2017-04-21T06:49:01.525000Z couchdb@localhost <0.7372.0> -------- OS Process #Port<0.7564> Input :: ["add_lib",{"utils":"exports.MAGIC = 42;"}] [debug] 2017-04-21T06:49:01.526000Z couchdb@localhost <0.7372.0> -------- OS Process #Port<0.7564> Output :: true [debug] 2017-04-21T06:49:01.526000Z couchdb@localhost <0.7372.0> -------- OS Process #Port<0.7564> Input :: ["add_fun","function(doc) {emit(doc._id,doc._rev);}"] [debug] 2017-04-21T06:49:01.527000Z couchdb@localhost <0.7372.0> -------- OS Process #Port<0.7564> Output :: true
This behaviour is OK for javascript, but it leads to serious issues in custom query servers. If the query server uses benefit of add_fun to prepare and possibly to compile the function, The compiler require presence of add_lib to complete the compilation of the code. Otherwise, the compiler has no way to detect, whether add_lib is missing due this behaviour or due error in design document.
This happen during PUT of the design document.
Ondrej Novak
PS: Working on couchcpp project - C++ query server protocil,
https://github.com/ondra-novak/couchcpp