Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account
List archives

Erlang Doc structure

Android?
(13 lines)
error when compiling couchdb trunk
(504 lines)
Jun 3, 2010
Mike Keen
Mike Keen
I've been playing with Erlang views on and off in CouchDB, and find the
information on the internal Erlang structure of Docs lacking. Is there
somewhere I can read up on this? I had initially assumed that a Doc was a
list of tuples, but I am starting to suspect that I am wrong.

Mike

Reply
Tags: docserlangtupleslist
Messages in this thread
Erlang Doc structure
reply Re: Erlang Doc structure
(26 lines) Jun 3, 2010 14:27
reply Re: Erlang Doc structure
(33 lines) Jun 3, 2010 15:14
reply Re: Erlang Doc structure
(32 lines) Jun 3, 2010 16:02
reply Re: Erlang Doc structure
(46 lines) Jun 3, 2010 16:34
Similar Threads
Thrift API for Erlang
Greetings.

I noticed a small inconvenience in the thrift_client Erlang module.

call(Client, Function, Args)
  when is_pid(Client), is_atom(Function), is_list(Args) ->
    case gen_server:call(Client, {call, Function, Args}) of
        R = {ok, _} -> R;
        R = {error, _} -> R;
        {exception, Exception} -> throw(Exception)
    end.

The inconvenience is that we can use atoms as pointers to processes in
Erlang.

Say, I write the following wrapper:

-module(hbase).
-export([
    start_link/0
]).

start_link() ->
    {ok, Client} = thrift_client:start_link("localhost", 9090,
hbase_thrift),
    register(hbase, Client),
    {ok, Client}.


and then I'll want to access hbase like the following:

thrift_client:call(hbase, getTableNames, []).

but the guard at the code above won't allow me to use this
construction. Moreover, we may want to access a pid like this:
{Node, Pid}.

I'd rather remove the is_pid check totally from the code and also add
a possibility to register the thrift client.

Here's the full diff:

--- thrift_client.erl
+++ thrift_client.erl
@@ -22,7 +22,7 @@
 -behaviour(gen_server).

 %% API
--export([start_link/2, start_link/3, start_link/4,
+-export([start_link/2, start_link/3, start_link/4, start_link/5,
          start/3, start/4,
          call/3, send_call/3, close/1]).

@@ -46,6 +46,11 @@
 start_link(Host, Port, Service) when is_integer(Port), is_atom(Service)
->
     start_link(Host, Port, Service, []).

+start_link(RegisterName, Host, Port, Service, Options) ->
+    {ok, Client} = start_link(Host, Port, Service, Options),
+    register(RegisterName, Client),
+    {ok, Client}.
+
 start_link(Host, Port, Service, Options) ->
     start(Host, Port, Service, [{monitor, link} | Options]).

@@ -141,7 +146,7 @@
     end.

 call(Client, Function, Args)
-  when is_pid(Client), is_atom(Function), is_list(Args) ->
+  when is_atom(Function), is_list(Args) ->
     case gen_server:call(Client, {call, Function, Args}) of
         R = {ok, _} -> R;
         R = {error, _} -> R;
@@ -149,17 +154,17 @@
     end.

 cast(Client, Function, Args)
-  when is_pid(Client), is_atom(Function), is_list(Args) ->
+  when is_atom(Function), is_list(Args) ->
     gen_server:cast(Client, {call, Function, Args}).

 %% Sends a function call but does not read the result. This is useful
 %% if you're trying to log non-oneway function calls to write-only
 %% transports like thrift_disk_log_transport.
 send_call(Client, Function, Args)
-  when is_pid(Client), is_atom(Function), is_list(Args) ->
+  when is_atom(Function), is_list(Args) ->
     gen_server:call(Client, {send_call, Function, Args}).

-close(Client) when is_pid(Client) ->
+close(Client) ->
     gen_server:cast(Client, close).

 %%
Re: Using Cassandra via the Erlang Thrift Client API (HOW ??)
Greetings,


I am also exploring erlang and cassandra via thrift..

but when inserting i've encountered this error.


(tes### @ubuntu)11> thrift_client:call(C,'insert',[
"Keyspace1","1",#columnPath{column_family="Standard1", column="email"},
"te### @example.com",1,1 ]).

=ERROR REPORT==== 8-Jun-2010::15:07:58 ===
** Generic server <0.118.0> terminating 
** Last message in was {call,insert,
                             ["Keyspace1","1",
                              {columnPath,"Standard1",undefined,"email"},
                              "te### @example.com",1,1]}
** When Server state == {state,cassandra_thrift,
                         {protocol,thrift_binary_protocol,
                          {binary_protocol,
                          
{transport,thrift_buffered_transport,<0.119.0>},
                           true,true}},
                         0}
** Reason for termination == 
** {'module could not be loaded',
       [{cassandra_thrift,function_info,[insert,params_type]},
        {thrift_client,send_function_call,3},
        {thrift_client,'-handle_call/3-fun-0-',3},
        {thrift_client,catch_function_exceptions,2},
        {thrift_client,handle_call,3},
        {gen_server,handle_msg,5},
        {proc_lib,init_p_do_apply,3}]}
** exception exit: undef
     in function  cassandra_thrift:function_info/2
        called as cassandra_thrift:function_info(insert,params_type)
     in call from thrift_client:send_function_call/3
     in call from thrift_client:'-handle_call/3-fun-0-'/3
     in call from thrift_client:catch_function_exceptions/2
     in call from thrift_client:handle_call/3
     in call from gen_server:handle_msg/5
     in call from proc_lib:init_p_do_apply/3


Is there anyone who encountered the problem above. :)


thanks in advanced :)

- Niel Riddle :)




Upgrading to Cassanda 0.7 Thrift Erlang
Hi,

I just tried upgrading a perfectly working Cassandra 0.6.3 to Cassandra
0.7
and am finding that even after re-generating the erlang thrift bindings
that
I am unable to perform any operation.
I can get a connection but if I try to login or set the keyspace I get a
report from the erlang bindings to say that the connection is closed.

I then tried upgrading to a later version of thrift but still get the same
error.

e.g.
(zotoni### @127.0.0.1)1> thrift_client:start_link("localhost", 9160,
cassandra_thrift).
{ok,<0.327.0>}
(zotoni### @127.0.0.1)2> {ok,C}=thrift_client:start_link("localhost",
9160,
cassandra_thrift).
{ok,<0.358.0>}
(zoton### @127.0.0.1)3> thrift_client:call( C, set_keyspace, [
<<"Test">>
 ]).

=ERROR REPORT==== 27-Jul-2010::03:48:08 ===
** Generic server <0.358.0> terminating
** Last message in was {call,set_keyspace,[<<"Test">>]}
** When Server state == {state,cassandra_thrift,
                         {protocol,thrift_binary_protocol,
                          {binary_protocol,
                          
{transport,thrift_buffered_transport,<0.359.0>},
                           true,true}},
                         0}
** Reason for termination ==
** {{case_clause,{error,closed}},
    [{thrift_client,read_result,3},
     {thrift_client,catch_function_exceptions,2},
     {thrift_client,handle_call,3},
     {gen_server,handle_msg,5},
     {proc_lib,init_p_do_apply,3}]}
** exception exit: {case_clause,{error,closed}}
     in function  thrift_client:read_result/3
     in call from thrift_client:catch_function_exceptions/2
     in call from thrift_client:handle_call/3
     in call from gen_server:handle_msg/5
     in call from proc_lib:init_p_do_apply/3

The cassandra log seems to indicate that a connection has been made
(although thats only apparent by a TRACE log message saying that a logout
has been done).

The cassandra-cli program is able to connect and function normally so I
can
only assume that there is a problem with the erlang bindings.

Has anyone else had any success using 0.7 from Erlang ?

JT.


Erlang process consuming most resources on Ubuntu
My system is Ubuntu 10.04. Couchdb is 0.11. My both cores are utilised
at about 70% by erlang:

Full process name is:
/usr/lib/erlang/erts-5.7.4/bin/beam.smp -Bd -K true -- -root
/usr/lib/erlang -progname erl -- -home /home/pawel -- -noshell
-noinput -sasl errlog_type error -couch_ini /etc/couchdb/default.ini
/etc/xdg/desktop-couch/compulsory-auth.ini
/home/pawel/.config/desktop-couch/desktop-couchdb.ini -s couch
-pidfile /home/pawel/.cache/desktop-couch/desktop-couchdb.pid -heart

Why is it utilising so much resources, and how can I do something about
it?

Best regards



OT: erts configure fail during windows build of erlang R13B04
A bit OT, but I am struggling to get erlang to build on windows,
before even getting to couchdb. I have sorted out all the various
compiler/path/include crap between windows & cygwin now but am getting
an epic fail during ./otp_build configure, in configure erts that has
me completely beaten - full story in
http://friendpaste.com/31QFPpBNEvIkTBtNSuQF1

./otp_build autoconf runs fine
./otp_build configure is OK until it starts configuring erts

[...]
checking if we can link wxwidgets programs... yes
configure: creating win32/config.status
config.status: creating config.mk
config.status: creating c_src/Makefile
=== configuring in erts (/cygdrive/c/src/otp_src_R13B04/erts)
configure: running /bin/sh
/cygdrive/c/src/otp_src_R13B04//erts/configure
--disable-option-checking '--prefix=/usr/local'
'--build=i686-pc-cygwin' 'build_alias=win32' '--host=win32'
'--target=win32' 'CC=cc.sh' 'CXX=cc.sh' 'RANLIB=true' 'AR=ar.sh'
'host_alias=win32' 'target_alias=win32'
'ERL_TOP=/cygdrive/c/src/otp_src_R13B04/'
--cache-file=/cygdrive/c/src/otp_src_R13B04//erts/autoconf/win32.config.cache
--srcdir=/cygdrive/c/src/otp_src_R13B04//erts
configure: loading cache
/cygdrive/c/src/otp_src_R13B04//erts/autoconf/win32.config.cache
configure: error: You need to run configure with argument
--srcdir=/cygdrive/c/src/otp_src_R13B04//erts
configure: error: /cygdrive/c/src/otp_src_R13B04//erts/configure failed
for erts

re-running ./otp_build configure. or just plain configure inside erts,
with the --srcdir=... param still doesn't help. I guess this is likely
a simple fix?

On the upside, I have however got wxwidgets 2.8.11 to build using the
free vc2008 express so people don't have to fork out for the full
Visual Studio suite. More on that when I can post an updated
end-to-end build.

cheers
Dave


list of structure..
Hello everybody!

We have puppet infrastructure integrated with ldap. I can pass
different variables via puppetVars attribute in ldap.
Currently, I need to write puppet class to configure mod_proxy server.
mod_proxy servers has 5-10 configured sites. Every site configuration
has some variables: site name, listen port, destination site name,
destination port, protocol..
Does anybody has an idea, how can I place all this variables out of
puppet classes? In ldap? Or maybe puppet have some internal database,
like chef?





Can I call system shell commands from server side CouchDB JavaScript or Erlang?
Hi,

I would like to write a CouchDB app which creates an inventory of
files on the user's computer. I know I could write a client in Python
which would update CouchDB but I would really like to be able to do it
all from the couchdb app. Is there a way to call system commands from
CouchDB with JavaScript (or Erlang)? Something similar to Python's
subprocess module would be perfect:
http://docs.python.org/release/2.5.2/...e-subprocess.html

Many thanks,
Cillian


JMS-MAP-JSON Improper Data structure
I am getting an odd error in my data from my broker. Using perl I am
changing
a map message to json using jms-map-json. This returns an improperly
structured version of my data.



'map' => [
                     {
                       'entry' => [
                                    {
                                      'string' => [

As you can see it is creating an array where the hash should be.

I now have to access data like @{@{$json->{map}}[0]->{entry}}; Which
is very
unpleasant. We did not have this issue prior. I used to be able to simply
do

@{$json->{map}{entry}} to access my data


This is with amq 5.3.2




arbitrary structure for joins redux
Hi,
I recently discovered the new feature added in couchdb 0.11 which lets to
link related documents in the emit function by passing the _id value of a
given doc like it's explained in
http://blog.couch.io/post/446015664/w...11-part-two-views
I find this feature quite useful, but I would like to know if its planned
to
let use an arbitrary structure as the value for the emit function which
could contain several _id's references like emit(key, {title:"lorem
ipsum",
foo:{_id : "foo"}, bar : {_id : "bar"}})
so there could be linked more than one document with a single emit call. a
possible solution could probably be to call the emit function several
times
but then include_docs parameter could not be used when a reduce function
is
defined.

Thanks in advance

Regards




Need advice about docs structure design.
Hy guy's.

My model:
Users has
  Bookmarks and Posts

have idea keep Bookmarks and Posts in separate DB (for speed views).
But in view i want fetch Bookmarks and Posts with user name,

In what way i can do this?
keep copy of users in each DB?

or may be keep users in separate DB, fetch bookmarks or posts and then
fetch users and then merge?

Yes i know i can copy user name to doc, but have a trouble when user
name is changed (it's force me use stale=ok in request view
+background process to track changes and run rebuild index).

I think it's will be cool crazy stuff if i can update docs(cached
fields - not have effect to index) and say Couch you don't need
rebuild index relax ;).

Any advice?


RE: Delete document Tree Structure

   hi ,

         I am very new to couchdb,  in my design , i just keep parent id
of each documents.
such as if i would like to delete B, i know that to delete C(have B id)
and then I have find and
to delete E(have c id).... etc.

        my question is ....

        1. is this possible ????

        2. how do i pass the document id (such as B) to view that i would
like to search and delete document under its? 

        3. dose couchdb support delete document in view or i have to query
all of them than use http api to delete ?

         

thanks for every ideas 

A.







-------- Original Message --------

  
    
      Subject: 
      Re: Delete document Tree Structure
    
    
      Date: 
      Thu, 27 May 2010 06:43:58 +0200
    
    
      From: 
      J Chris Anderson <jch### @gmail.com>
    
    
      Reply-To: 
      use### @couchdb.apache.org <us### @couchdb.apache.org>
    
    
      To: 
      use### @couchdb.apache.org <us### @couchdb.apache.org>
    
  





On May 26, 2010, at 8:48 PM, Aun... ??????? wrote:

 
 
 Hi,
 
       I design document in couchdb to have relation something like
 
              directory
                    |
                    A---------D
                    |
                    B---------C
                                 |
                                 |
                                 E ------F
 
         if i would like to http (DELETE B) will delete all down
documents what is the possible solution to use.
 
                1.    can i create view and find relation and delete
all of them ?
                2.    get  relation by higher programming api (C#,PHP)
and then delete each one?
                3.    Do you have any solution to suggest on
this.....?
 

It is common to store the full path to each item, on the item, so you'd
have

B > C > E > F stored on F

then you can view easily across the tree.

however, reparenting a node, (say, moving B to become a child of D)
require asynchronous processing or a bulk docs request and is not
transactional.

Chris


 
 Thanks,
 A. 
 
 
 		 	   		  
 
Delete document Tree Structure

Hi,

       I design document in couchdb to have relation something like

              directory
                    |
                    A---------D
                    |
                    B---------C
                                 |
                                 |
                                 E ------F

         if i would like to http (DELETE B) will delete all down documents
what is the possible solution to use.

                1.    can i create view and find relation and delete all
of them ?
                2.    get  relation by higher programming api (C#,PHP) and
then delete each one?
                3.    Do you have any solution to suggest on this.....?


Thanks,
A. 


 		 	   		  

adding request structure access to mod_header
We were dancing around trying to get RequestHeader (mod_header) to add
the authenticated user to a proxy request. The approaches we found
involved tricking other modules into calling ap_add_common_vars to
  apr_table_addn(r->subprocess_env, "REMOTE_USER", r->user);

I decided to simplify by adding %{}r directives à la
  RequestHeader set "x-webobjects-remote-user" "%{user}r"
which interrogate the request structure directly. I re-used
the request structure names 'cause, well, why not?


Please try to reply to <er### @w3.org>. <eri### @gmail.com> is a
temporary hack as ezmlm seems to subscribe the address in the
Return-Path: instead of the From: (grr!).



adding request structure access to mod_header
We were dancing around trying to get RequestHeader (mod_header) to add
the authenticated user to a proxy request. The approaches we found
involved tricking other modules into calling ap_add_common_vars to
  apr_table_addn(r->subprocess_env, "REMOTE_USER", r->user);

I decided to simplify by adding %{}r directives à la
  RequestHeader set "x-webobjects-remote-user" "%{user}r"
which interrogate the request structure directly. I re-used
the request structure names 'cause, well, why not?


Please try to Cc: <er### @w3.org>. <eric### @gmail.com> is a
temporary
hack as ezmlm seems to subscribe the address in the Return-Path:
instead of the From: