def wal_restore(self, wal_name, wal_destination, prefetch_max):
url = '<STR_LIT>'.format(<EOL>self.layout.scheme, self.layout.store_name(),<EOL>self.layout.wal_path(wal_name))<EOL>if prefetch_max > <NUM_LIT:0>:<EOL><INDENT>base = os.path.dirname(os.path.realpath(wal_destination))<EOL>pd = prefetch.Dirs(base)<EOL>seg = WalSegment(wal_name)<EOL>started = start_prefetches(seg, pd, prefetch_max)<EOL>last_size = <NUM_LIT:0><EOL>while True:<EOL><INDENT>if pd.contains(seg):<EOL><INDENT>pd.promote(seg, wal_destination)<EOL>logger.info(<EOL>msg='<STR_LIT>',<EOL>structured={'<STR_LIT:action>': '<STR_LIT>',<EOL>'<STR_LIT:key>': url,<EOL>'<STR_LIT>': wal_name,<EOL>'<STR_LIT>': self.layout.path_prefix})<EOL>pd.clear_except(started)<EOL>return True<EOL><DEDENT>sz = pd.running_size(seg)<EOL>if sz <= last_size:<EOL><INDENT>break<EOL><DEDENT>last_size = sz<EOL>gevent.sleep(<NUM_LIT:0.5>)<EOL><DEDENT>pd.clear_except(started)<EOL><DEDENT>logger.info(<EOL>msg='<STR_LIT>',<EOL>structured={'<STR_LIT:action>': '<STR_LIT>',<EOL>'<STR_LIT:key>': url,<EOL>'<STR_LIT>': wal_name,<EOL>'<STR_LIT>': self.layout.path_prefix,<EOL>'<STR_LIT:state>': '<STR_LIT>'})<EOL>ret = do_lzop_get(self.creds, url, wal_destination,<EOL>self.gpg_key_id is not None)<EOL>logger.info(<EOL>msg='<STR_LIT>',<EOL>structured={'<STR_LIT:action>': '<STR_LIT>',<EOL>'<STR_LIT:key>': url,<EOL>'<STR_LIT>': wal_name,<EOL>'<STR_LIT>': self.layout.path_prefix,<EOL>'<STR_LIT:state>': '<STR_LIT>'})<EOL>return ret<EOL>
Downloads a WAL file from S3 or Windows Azure Blob Service

This code is intended to typically be called from Postgres's
restore_command feature.

NB: Postgres doesn't guarantee that wal_name ==
basename(wal_path), so both are required.