-
-
Save mcroydon/151070717bfe56a3da1a to your computer and use it in GitHub Desktop.
Getting a RiakError when setting links with RiakPbcTransport
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from riak import RiakClient | |
from riak import RiakPbcTransport | |
c = RiakClient(port=8087, transport_class=RiakPbcTransport) | |
# c = RiakClient() | |
bucket = c.bucket('linktest') | |
# Group data | |
for n in xrange(0,10): # used to be 0,9 | |
group = bucket.new('group_%s' % n, {'id' : n}) | |
group.store() | |
# User data | |
for n in xrange(0,1000): | |
key = 'user_%s' % n | |
print 'Adding user %s' % n | |
# Create the user | |
data = {'name' : 'User %s' % n, 'id' : n} | |
u = bucket.new(key, data) | |
u = u.store() | |
# Update the group list | |
group_id = n % 10 | |
group_data = bucket.get('group_%s' % group_id) | |
group_data.set_content_type('application/json') # This was required to make HTTP transport work | |
group_data.add_link(u) | |
group_data.store() | |
# The line above throws riak.RiakError: 'Socket returned short packet length - expected 4' | |
# on user 9 but only when using RiakPbcTransport. | |
# Check the buckets | |
for n in xrange(0,10): # used to be 0,9 | |
print 'Group %s has %s users.' % (n, len(bucket.get('group_%s' % n).get_links())) |
I fixed this by changing all xrange(0,9) calls to xrange(0,10), which is what I should have been doing in the first place.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code yields the following output/stacktrace on OSX 10.6 using Riak 0.13.0 via homebrew and riak-python-client 1.1.1:
Adding user 0
Adding user 1
Adding user 2
Adding user 3
Adding user 4
Adding user 5
Adding user 6
Adding user 7
Adding user 8
Adding user 9
Traceback (most recent call last):
File "riak_gist.py", line 31, in
group_data.store()
File "/Library/Python/2.6/site-packages/riak-1.1.1-py2.6.egg/riak/riak_object.py", line 237, in store
Result = t.put(self, w, dw, return_body)
File "/Library/Python/2.6/site-packages/riak-1.1.1-py2.6.egg/riak/transports/pbc.py", line 190, in put
msg_code, resp = self.recv_msg()
File "/Library/Python/2.6/site-packages/riak-1.1.1-py2.6.egg/riak/transports/pbc.py", line 326, in recv_msg
self.recv_pkt()
File "/Library/Python/2.6/site-packages/riak-1.1.1-py2.6.egg/riak/transports/pbc.py", line 364, in recv_pkt
format(nmsglen))
riak.RiakError: 'Socket returned short packet length - expected 4'