Skip to content

Commit

Permalink
Merge pull request #280 from tilezen/remove-gzip
Browse files Browse the repository at this point in the history
Remove gzip rawr formatter
  • Loading branch information
rmarianski authored Nov 1, 2017
2 parents 2873ce5 + 7a67609 commit 9e64f81
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
3 changes: 1 addition & 2 deletions tilequeue/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -1537,7 +1537,6 @@ def tilequeue_rawr_process(cfg, peripherals):
rawr_postgresql_yaml = rawr_yaml.get('postgresql')
assert rawr_postgresql_yaml, 'Missing rawr postgresql config'

from raw_tiles.formatter.gzip import Gzip
from raw_tiles.formatter.msgpack import Msgpack
from raw_tiles.gen import RawrGenerator
from raw_tiles.source.conn import ConnectionContextManager
Expand Down Expand Up @@ -1596,7 +1595,7 @@ def tilequeue_rawr_process(cfg, peripherals):

logger = make_logger(cfg, 'rawr_process')
rawr_osm_source = OsmSource(conn_ctx)
rawr_formatter = Gzip(Msgpack())
rawr_formatter = Msgpack()
rawr_gen = RawrGenerator(rawr_osm_source, rawr_formatter, rawr_sink)
stats_handler = RawrTilePipelineStatsHandler(peripherals.stats)
rawr_proc_logger = JsonRawrProcessingLogger(logger)
Expand Down
15 changes: 7 additions & 8 deletions tilequeue/rawr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from botocore.exceptions import ClientError
from collections import defaultdict
from collections import namedtuple
from contextlib import closing
from cStringIO import StringIO
from ModestMaps.Core import Coordinate
from msgpack import Unpacker
Expand Down Expand Up @@ -390,25 +391,22 @@ def make_rawr_zip_payload(rawr_tile, date_time=None):
return buf.getvalue()


def unpack_rawr_zip_payload(table_sources, filelike):
def unpack_rawr_zip_payload(table_sources, payload):
"""unpack a zipfile and turn it into a callable "tables" object."""
# the io we get from S3 is streaming, so we can't seek on it, but zipfile
# seems to require that. so we buffer it all in memory. RAWR tiles are
# generally up to around 100MB in size, which should be safe to store in
# RAM.
from tilequeue.query.common import Table
from io import BytesIO
from gzip import GzipFile

buf = BytesIO(filelike.read())
zfh = zipfile.ZipFile(buf, 'r')
zfh = zipfile.ZipFile(BytesIO(payload), 'r')

def get_table(table_name):
# need to extract the whole compressed file from zip reader, as it
# doesn't support .tell() on the filelike, which gzip requires.
data = zfh.open(table_name, 'r').read()
ungzip = GzipFile(table_name, 'rb', 0, BytesIO(data))
unpacker = Unpacker(file_like=ungzip)
unpacker = Unpacker(file_like=BytesIO(data))
source = table_sources[table_name]
return Table(source, unpacker)

Expand Down Expand Up @@ -514,7 +512,8 @@ def __call__(self, tile):
# check that the response isn't a delete marker.
assert 'DeleteMarker' not in response

body = response['Body']
with closing(response['Body']) as body_fp:
body = body_fp.read()
return unpack_rawr_zip_payload(self.table_sources, body)


Expand All @@ -535,7 +534,7 @@ def _get_object(self, tile):

def __call__(self, tile):
payload = self._get_object(tile)
return unpack_rawr_zip_payload(self.table_sources, StringIO(payload))
return unpack_rawr_zip_payload(self.table_sources, payload)


def make_rawr_queue(name, region, wait_time_secs):
Expand Down

0 comments on commit 9e64f81

Please sign in to comment.