Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | SDKs | SDKs

Cross platform read and write to couchbase

4 replies [Last post]
  • Login or register to post comments
Wed, 05/16/2012 - 13:37
arishlabroo
Offline
Joined: 12/22/2011
Groups: None

Couchbase server 2.0
CouchbaseNetClient 1.1.2
PHP SDK For Couchbase Server 1.8.

Hi, I can successfully read and write JSON strings to the couchbase server from both .Net and PHP individually.

But when I try to read a key in PHP which was written by .Net I get this weird error

[16-May-2012 19:18:26 UTC] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 8368851528933051772 bytes) in /path/to/file/couching.php on line 17
[16-May-2012 19:18:26 UTC] PHP Stack trace:
[16-May-2012 19:18:26 UTC] PHP   1. {main}() /path/to/file/couching.php:0
[16-May-2012 19:18:26 UTC] PHP   2. Couchbase->get() /path/to/file/couching.php:17

And when I try to read a key in .Net which was written by PHP, I get this error

unknown typecode was returned: byte
 
 |
 OR
 |
 
System.Runtime.Serialization.SerializationException was unhandled by user code
  Message=End of Stream encountered before parsing was completed.
  Source=mscorlib
  StackTrace:
       at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
       at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
       at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
       at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
       at Enyim.Caching.Memcached.DefaultTranscoder.DeserializeObject(ArraySegment`1 value) in C:\dev\gerrit-a\lib\EnyimMemcached\Enyim.Caching\Memcached\Transcoders\DefaultTranscoder.cs:line 300
       at Enyim.Caching.Memcached.DefaultTranscoder.Deserialize(CacheItem item) in C:\dev\gerrit-a\lib\EnyimMemcached\Enyim.Caching\Memcached\Transcoders\DefaultTranscoder.cs:line 141
       at Enyim.Caching.Memcached.DefaultTranscoder.Enyim.Caching.Memcached.ITranscoder.Deserialize(CacheItem item) in C:\dev\gerrit-a\lib\EnyimMemcached\Enyim.Caching\Memcached\Transcoders\DefaultTranscoder.cs:line 23
       at Couchbase.CouchbaseClient.PerformTryGet(String key, UInt64& cas, Object& value) in C:\dev\gerrit-a\src\Couchbase\CouchbaseClient.cs:line 112
       at Enyim.Caching.MemcachedClient.TryGet(String key, Object& value) in C:\dev\gerrit-a\lib\EnyimMemcached\Enyim.Caching\MemcachedClient.cs:line 150
       at Enyim.Caching.MemcachedClient.Get(String key) in C:\dev\gerrit-a\lib\EnyimMemcached\Enyim.Caching\MemcachedClient.cs:line 125 .....
.....       
  InnerException: 

Both the values are json encoded before writing. .Net uses Newtonsoft JSON.NET, and PHP json_encode.

What am I doing wrong, cross platform reads should not be this hard? For some reason one platform is not able to parse what the other platform wrote.

Help!!

+ For .Net client I can figure that the exception is thrown by the DefaultTranscoder.cs (System.InvalidOperationException : Unknown TypeCode was returned: Byte)

Top
  • Login or register to post comments
Mon, 06/25/2012 - 11:24
natevcoder
Offline
Joined: 06/25/2012
Groups: None

This is a bug in the PHP couchbase client: couchbase.so

I had to debug the C source code to discover the problem manifext after about line 680 of "couchbase.c"

Specifically, this is an issue inside the function: php_couchbase_zval_from_payload()

It tries to decompress an uncompressed character array. After hacking the code to not attempt decompression and after fixing a string length calculation, it worked perfectly for me.

If you are not a C developer, try ensuring your JSON payload is compressed by your Couchbase client if possible and see if that fixes your problem. Otherwise, Couchbase should really fix this.

Top
  • Login or register to post comments
Mon, 06/25/2012 - 17:19
ingenthr
Offline
Joined: 03/16/2010
Groups:

Nate: thanks for identifying that and letting others know. I've filed an issue here:
http://www.couchbase.com/issues/browse/PCBC-77

Is a diff of your changes available? I'm sure we can work it out, but since you've already been down that path, if you can point to what you've done that'd be great.

Top
  • Login or register to post comments
Tue, 06/26/2012 - 13:42
natevcoder
Offline
Joined: 06/25/2012
Groups: None

I have finalized my changes for the fix. It is no longer a hack fix. Where can I submit the diff and/or the new code file?

Top
  • Login or register to post comments
Tue, 06/26/2012 - 19:24
ingenthr
Offline
Joined: 03/16/2010
Groups:

There are a couple of steps, but the best place to submit them is via our code review server as a git push: http://review.couchbase.org

(If you find it's too many steps or too annoying, just email the diff to matt at couchbase)

You'll need to sign up and click through the Contributor License Agreement:
http://review.couchbase.org/#settings,agreements

And then let us know so we can add you appropriately. There is a branch for 1.0 on the project.

After adding the git remote (with "git remote add gerrit ssh://review.couchbase.org:29418/php-ext-couchbase.git") and adding the commit hook script, you'd push it to the 1.0.x branch with a push like: "git push gerrit refs/for/1.0.x". That creates a code review that you can add myself and a few others too, and we'll incorporate it.

More details here (this php extension project doesn't use repo):
http://www.couchbase.com/wiki/display/couchbase/Contributing+Changes

Feel free to raise any of us on irc.freenode.net in #couchbase or #libcouchbase if you have questions, or just email the diff as mentioned.

Thanks so much!

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker