You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by "Ondřej Novák (JIRA)" <ji...@apache.org> on 2017/04/21 07:01:04 UTC

[jira] [Created] (COUCHDB-3387) add_fun without add_lib (query server protocol)

Ondřej Novák created COUCHDB-3387:
-------------------------------------

             Summary:  add_fun without add_lib (query server protocol)
                 Key: COUCHDB-3387
                 URL: https://issues.apache.org/jira/browse/COUCHDB-3387
             Project: CouchDB
          Issue Type: Bug
          Components: Database Core
            Reporter: Ondřej Novák


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)
{noformat}
{
  "_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;}"
    }
  }
}
{noformat}
Recorded log:
{noformat}
[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
{noformat}
However, later
{noformat}
[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
{noformat}
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



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)