Skip to content

Commit

Permalink
Use buffered gzip stream with python 2.7.
Browse files Browse the repository at this point in the history
- Fixes bug 898169.
- It's possible to make GzipFile inherits io.BufferedIOBase in python
  2.6, but IMO it's better let people to use 2.7 if they really need
  this feature.

Change-Id: I4c6e4858e3f616af892e7f4fa6daae0f6ee31723
  • Loading branch information
iryoung authored and chmouel committed Jun 28, 2012
1 parent fcab7b7 commit c67e568
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion swift/common/ring/ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from struct import unpack_from
from time import time
import os
from io import BufferedReader

from swift.common.utils import hash_path, validate_configuration
from swift.common.ring.utils import tiers_for_dev
Expand Down Expand Up @@ -61,7 +62,7 @@ def __init__(self, pickle_gz_path, reload_time=15, ring_name=None):
def _reload(self, force=False):
self._rtime = time() + self.reload_time
if force or self.has_changed():
ring_data = pickle.load(GzipFile(self.pickle_gz_path, 'rb'))
ring_data = pickle.load(self._get_gz_file())
if not hasattr(ring_data, 'devs'):
ring_data = RingData(ring_data['replica2part2dev_id'],
ring_data['devs'], ring_data['part_shift'])
Expand All @@ -72,6 +73,14 @@ def _reload(self, force=False):
self._part_shift = ring_data._part_shift
self._rebuild_tier_data()

def _get_gz_file(self):
gz_file = GzipFile(self.pickle_gz_path, 'rb')
if hasattr(gz_file, '_checkReadable'):
return BufferedReader(gz_file)
else:
# Python 2.6 doesn't support BufferedIO
return gz_file

def _rebuild_tier_data(self):
self.tier2devs = defaultdict(list)
for dev in self.devs:
Expand Down

0 comments on commit c67e568

Please sign in to comment.