Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
BSONObjBuilder decouple
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
khanalesb  
View profile  
 More options Nov 13 2012, 12:28 pm
From: khanalesb <khanal...@gmail.com>
Date: Tue, 13 Nov 2012 09:28:28 -0800 (PST)
Local: Tues, Nov 13 2012 12:28 pm
Subject: BSONObjBuilder decouple

I am trying to use BSONObjBuilder as a serializer and decouple to avoid
memcopy.

        mongo::BSONObjBuilder bldr;
....................
....................
....................

#ifdef X  
//THIS WORKS
        mongo::BSONObj obj = bldr.obj();
        zmq::message_t replyBody( obj.objsize() );
        std::memcpy( replyBody.data(), obj.objdata(), obj.objsize() );
#else
//SEG FAILT
        int len;
        char* buf = bldr.decouple(len);
        zmq::message_t replyBody( buf, len, zmqFree );
#endif

Do I have to call anything else before decouple? Can I use it at all?
Thanks.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James  
View profile  
 More options Nov 13 2012, 3:24 pm
From: James <james.wah...@10gen.com>
Date: Tue, 13 Nov 2012 12:24:21 -0800 (PST)
Local: Tues, Nov 13 2012 3:24 pm
Subject: Re: BSONObjBuilder decouple

It looks like this should work, given "bldr.obj()" in your working example
calls decouple as well to transfer buffer ownership. Can you provide a
stack trace for this? I will try to reproduce as well.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James  
View profile  
 More options Nov 13 2012, 5:37 pm
From: James <james.wah...@10gen.com>
Date: Tue, 13 Nov 2012 14:37:08 -0800 (PST)
Local: Tues, Nov 13 2012 5:37 pm
Subject: Re: BSONObjBuilder decouple

I was not able to reproduce this running through the decouple operation.
Please provide stack trace and more details. Even better would be to share
buildable/runnable sample code that reproduces. Thanks!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
khanalesb  
View profile  
 More options Nov 14 2012, 10:55 am
From: khanalesb <khanal...@gmail.com>
Date: Wed, 14 Nov 2012 07:55:46 -0800 (PST)
Local: Wed, Nov 14 2012 10:55 am
Subject: Re: BSONObjBuilder decouple

This works:
        int len;
        char* buf = bldr.decouple(len);
        char* buf1 = (char*) malloc(len);
        memcpy(buf1, buf, len);
        zmq::message_t replyBody( buf1, len, zmqFree );
but it is malloc and memcpy...
In original example:
        int len;
        char* buf = bldr.decouple(len);
        zmq::message_t replyBody( buf, len, zmqFree );
it cores when 0mq calls my clallback to free buffer(zmqFree). All zmqFree
does is free...
inline void zmqFree(void* ptr, void* hint) {
    ::free(ptr);


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
khanalesb  
View profile  
 More options Nov 14 2012, 11:20 am
From: khanalesb <khanal...@gmail.com>
Date: Wed, 14 Nov 2012 08:20:19 -0800 (PST)
Local: Wed, Nov 14 2012 11:20 am
Subject: Re: BSONObjBuilder decouple

Stacktrace:
 (gdb) where
#0  0x00007ffff638a8a5 in raise () from /lib64/libc.so.6
#1  0x00007ffff638c085 in abort () from /lib64/libc.so.6
#2  0x00007ffff63c7a37 in __libc_message () from /lib64/libc.so.6
#3  0x00007ffff63cd366 in malloc_printerr () from /lib64/libc.so.6
#4  0x0000000000413b40 in its::hvr::ps::zmqFree (ptr=0x7fffe4017314,
hint=0x0) at ../src/CommonDefs.cpp:16
#5  0x00007ffff7b6b0f2 in zmq_msg_close (msg_=0x7fffec0013e0) at zmq.cpp:152
#6  zmq_msg_close (msg_=0x7fffec0013e0) at zmq.cpp:130
#7  0x00007ffff7b52fa5 in zmq::encoder_t::message_ready
(this=0x7fffec001398) at encoder.cpp:56
#8  0x00007ffff7b6c914 in get_data (this=0x7fffec0012e0) at encoder.hpp:80
#9  zmq::zmq_engine_t::out_event (this=0x7fffec0012e0) at zmq_engine.cpp:165
#10 0x00007ffff7b5773e in zmq::object_t::process_command
(this=0x7fffdc005d10, cmd_=...) at object.cpp:63
#11 0x00007ffff7b546ec in zmq::io_thread_t::in_event (this=0x7391d0) at
io_thread.cpp:83
#12 0x00007ffff7b5373e in zmq::epoll_t::loop (this=0x7395c0) at
epoll.cpp:161
#13 0x00007ffff7b67566 in thread_routine (arg_=0x739630) at thread.cpp:75
#14 0x00007ffff6142851 in start_thread () from /lib64/libpthread.so.0
#15 0x00007ffff643f67d in clone () from /lib64/libc.so.6

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
khanalesb  
View profile  
 More options Nov 14 2012, 11:29 am
From: khanalesb <khanal...@gmail.com>
Date: Wed, 14 Nov 2012 08:29:20 -0800 (PST)
Local: Wed, Nov 14 2012 11:29 am
Subject: Re: BSONObjBuilder decouple

Wrong builder constructor?
    mongo::BSONObjBuilder bldrReply;
    bldrReply.append( "HasMore", ( src.holdings_.size() >
Profile::getInstance().getReplyMsgSize() ) );
    bldrReply.append( "RequestId", src.requestId_ );

    int len;
    char* buf = bldrReply.decouple(len);
    std::cerr << (void*) buf << "\n";
    free(buf);
 This cores on free call!!!!
Should I use different constructor?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James  
View profile  
 More options Nov 14 2012, 11:41 am
From: James <james.wah...@10gen.com>
Date: Wed, 14 Nov 2012 08:41:47 -0800 (PST)
Local: Wed, Nov 14 2012 11:41 am
Subject: Re: BSONObjBuilder decouple

I can reproduce now. Thanks for the clarification on crash location. The
constructor you are using should be fine. Will debug and get back to you
with my findings.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
khanalesb  
View profile  
 More options Nov 14 2012, 11:56 am
From: khanalesb <khanal...@gmail.com>
Date: Wed, 14 Nov 2012 08:56:38 -0800 (PST)
Local: Wed, Nov 14 2012 11:56 am
Subject: Re: BSONObjBuilder decouple

decouple returns buffer + offset  rather than just buffer !!!!            
!!! char *data = _b.buf() + _offset; !!!
How do I get buffer to free ??????
      char* _done() {
            if ( _doneCalled )
                return _b.buf() + _offset;

            _doneCalled = true;
            _s.endField();
            _b.appendNum((char) EOO);
            char *data = _b.buf() + _offset;
            int size = _b.len() - _offset;
            *((int*)data) = size;
            if ( _tracker )
                _tracker->got( size );
            return data;
        }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
khanalesb  
View profile  
 More options Nov 14 2012, 12:26 pm
From: khanalesb <khanal...@gmail.com>
Date: Wed, 14 Nov 2012 09:26:44 -0800 (PST)
Local: Wed, Nov 14 2012 12:26 pm
Subject: Re: BSONObjBuilder decouple

Working version:
    mongo::BufBuilder& bb = bldrReply.bb();
    void* hint = bb.buf();
    int len;
    char* buf = bldrReply.decouple(len);
    zmq::message_t reply( buf, len, zmqFreeHint, hint );

Actually call free on buffer from builder - ugly. Better idea?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James  
View profile  
 More options Nov 15 2012, 12:29 pm
From: James <james.wah...@10gen.com>
Date: Thu, 15 Nov 2012 09:29:51 -0800 (PST)
Local: Thurs, Nov 15 2012 12:29 pm
Subject: Re: BSONObjBuilder decouple

Your original usage of the decouple method was correct. This is definitely
a bug in the implementation of BSONObjBuilder. A ticket has been entered to
fix:
https://jira.mongodb.org/browse/SERVER-7671

While waiting on a fix my suggestion would to use your original
implementation (with the memcpy) if you can afford to do so or test an
alternate solution very carefully. Please track the ticket above for status
on the fix.

Thanks for your help in identifying this!

James


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
khanalesb  
View profile  
 More options Nov 16 2012, 12:02 am
From: khanalesb <khanal...@gmail.com>
Date: Thu, 15 Nov 2012 21:02:33 -0800 (PST)
Local: Fri, Nov 16 2012 12:02 am
Subject: Re: BSONObjBuilder decouple

Hmm...
If you do fix - every user is broken. On the other hand in doc/code
it says that has to be freed  (::free())
Do you expect to change BufBuilder? Reason not to keep this implementation?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »