Cross platform read and write to couchbase
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:17And 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)
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.
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?
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!
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.