Skip to content

Commit

Permalink
Split out transactions to 10 keys per
Browse files Browse the repository at this point in the history
Doing everything in one transaction risks a 413: Request Entity Too
Large
  • Loading branch information
DJ Enriquez committed Oct 12, 2016
1 parent 281a1eb commit c476e31
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/consul.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ def restore_kv(self, restore_file):

for line in restore_file:
kv = line.split(':')
logger.debug('Key: {}, Value: {}'.format(kv[0], base64.standard_b64decode(kv[1]).decode('utf-8')))

transaction_data.append({ 'KV' : { 'Verb': 'set', 'Key': kv[0], 'Value': kv[1] } })

self._upload_kv(transaction_data)
for x in range(0, len(transaction_data), 10):
self._upload_kv(transaction_data[x:x+10])

def _upload_kv(self, transaction_data):
headers = { 'X-Consul-Token': self._token } if self._token is not None else {}
Expand Down

0 comments on commit c476e31

Please sign in to comment.