-
-
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())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.