Merge pull request #895 from tahoe-lafs/3502.mutable-python-3-part-2

Port allmydata.mutable to Python 3, part 2/2

Fixes ticket:3502
This commit is contained in:
Itamar Turner-Trauring 2020-11-20 10:03:38 -05:00 committed by GitHub
commit 729a5a0779
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 61 additions and 13 deletions

0
newsfragments/3502.minor Normal file
View File

View File

@ -1,3 +1,15 @@
"""
Ported to Python 3.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from future.utils import PY2
if PY2:
# Omit dict so Python 3 changes don't leak into API callers on Python 2.
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, list, object, range, str, max, min # noqa: F401
from past.utils import old_div from past.utils import old_div
import struct import struct
@ -1744,7 +1756,7 @@ class MDMFSlotReadProxy(object):
def _read(self, readvs, force_remote=False): def _read(self, readvs, force_remote=False):
unsatisfiable = list(filter(lambda x: x[0] + x[1] > len(self._data), readvs)) unsatisfiable = [x for x in readvs if x[0] + x[1] > len(self._data)]
# TODO: It's entirely possible to tweak this so that it just # TODO: It's entirely possible to tweak this so that it just
# fulfills the requests that it can, and not demand that all # fulfills the requests that it can, and not demand that all
# requests are satisfiable before running it. # requests are satisfiable before running it.

View File

@ -1,3 +1,14 @@
"""
Ported to Python 3.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from future.utils import PY2
if PY2:
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
from zope.interface import implementer from zope.interface import implementer
from twisted.internet import defer from twisted.internet import defer

View File

@ -1,4 +1,15 @@
from past.builtins import unicode """
Ported to Python 3.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from future.utils import PY2
if PY2:
# Don't import bytes and str, to prevent API leakage
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, dict, list, object, range, max, min # noqa: F401
import time import time
@ -749,9 +760,9 @@ class Retrieve(object):
blockhashes = dict(enumerate(blockhashes)) blockhashes = dict(enumerate(blockhashes))
self.log("the reader gave me the following blockhashes: %s" % \ self.log("the reader gave me the following blockhashes: %s" % \
blockhashes.keys()) list(blockhashes.keys()))
self.log("the reader gave me the following sharehashes: %s" % \ self.log("the reader gave me the following sharehashes: %s" % \
sharehashes.keys()) list(sharehashes.keys()))
bht = self._block_hash_trees[reader.shnum] bht = self._block_hash_trees[reader.shnum]
if bht.needed_hashes(segnum, include_leaf=True): if bht.needed_hashes(segnum, include_leaf=True):
@ -908,7 +919,7 @@ class Retrieve(object):
def notify_server_corruption(self, server, shnum, reason): def notify_server_corruption(self, server, shnum, reason):
if isinstance(reason, unicode): if isinstance(reason, str):
reason = reason.encode("utf-8") reason = reason.encode("utf-8")
storage_server = server.get_storage_server() storage_server = server.get_storage_server()
storage_server.advise_corrupt_share( storage_server.advise_corrupt_share(

View File

@ -1,5 +1,15 @@
"""
Ported to Python 3.
"""
from __future__ import print_function from __future__ import print_function
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from future.utils import PY2
if PY2:
# Doesn't import str to prevent API leakage on Python 2
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, max, min # noqa: F401
from past.builtins import unicode from past.builtins import unicode
import sys, time, copy import sys, time, copy
@ -188,7 +198,7 @@ class ServerMap(object):
def dump(self, out=sys.stdout): def dump(self, out=sys.stdout):
print("servermap:", file=out) print("servermap:", file=out)
for ( (server, shnum), (verinfo, timestamp) ) in self._known_shares.items(): for ( (server, shnum), (verinfo, timestamp) ) in list(self._known_shares.items()):
(seqnum, root_hash, IV, segsize, datalength, k, N, prefix, (seqnum, root_hash, IV, segsize, datalength, k, N, prefix,
offsets_tuple) = verinfo offsets_tuple) = verinfo
print("[%s]: sh#%d seq%d-%s %d-of-%d len%d" % print("[%s]: sh#%d seq%d-%s %d-of-%d len%d" %
@ -226,7 +236,7 @@ class ServerMap(object):
"""Return a dict that maps versionid to sets of (shnum, server, """Return a dict that maps versionid to sets of (shnum, server,
timestamp) tuples.""" timestamp) tuples."""
versionmap = DictOfSets() versionmap = DictOfSets()
for ( (server, shnum), (verinfo, timestamp) ) in self._known_shares.items(): for ( (server, shnum), (verinfo, timestamp) ) in list(self._known_shares.items()):
versionmap.add(verinfo, (shnum, server, timestamp)) versionmap.add(verinfo, (shnum, server, timestamp))
return versionmap return versionmap
@ -245,7 +255,7 @@ class ServerMap(object):
(num_distinct_shares, k, N) tuples.""" (num_distinct_shares, k, N) tuples."""
versionmap = self.make_versionmap() versionmap = self.make_versionmap()
all_shares = {} all_shares = {}
for verinfo, shares in versionmap.items(): for verinfo, shares in list(versionmap.items()):
s = set() s = set()
for (shnum, server, timestamp) in shares: for (shnum, server, timestamp) in shares:
s.add(shnum) s.add(shnum)
@ -271,7 +281,7 @@ class ServerMap(object):
"""Return a string describing which versions we know about.""" """Return a string describing which versions we know about."""
versionmap = self.make_versionmap() versionmap = self.make_versionmap()
bits = [] bits = []
for (verinfo, shares) in versionmap.items(): for (verinfo, shares) in list(versionmap.items()):
vstr = self.summarize_version(verinfo) vstr = self.summarize_version(verinfo)
shnums = set([shnum for (shnum, server, timestamp) in shares]) shnums = set([shnum for (shnum, server, timestamp) in shares])
bits.append("%d*%s" % (len(shnums), vstr)) bits.append("%d*%s" % (len(shnums), vstr))
@ -282,7 +292,7 @@ class ServerMap(object):
recoverable.""" recoverable."""
versionmap = self.make_versionmap() versionmap = self.make_versionmap()
recoverable_versions = set() recoverable_versions = set()
for (verinfo, shares) in versionmap.items(): for (verinfo, shares) in list(versionmap.items()):
(seqnum, root_hash, IV, segsize, datalength, k, N, prefix, (seqnum, root_hash, IV, segsize, datalength, k, N, prefix,
offsets_tuple) = verinfo offsets_tuple) = verinfo
shnums = set([shnum for (shnum, server, timestamp) in shares]) shnums = set([shnum for (shnum, server, timestamp) in shares])
@ -298,7 +308,7 @@ class ServerMap(object):
versionmap = self.make_versionmap() versionmap = self.make_versionmap()
unrecoverable_versions = set() unrecoverable_versions = set()
for (verinfo, shares) in versionmap.items(): for (verinfo, shares) in list(versionmap.items()):
(seqnum, root_hash, IV, segsize, datalength, k, N, prefix, (seqnum, root_hash, IV, segsize, datalength, k, N, prefix,
offsets_tuple) = verinfo offsets_tuple) = verinfo
shnums = set([shnum for (shnum, server, timestamp) in shares]) shnums = set([shnum for (shnum, server, timestamp) in shares])
@ -332,7 +342,7 @@ class ServerMap(object):
healths = {} # maps verinfo to (found,k) healths = {} # maps verinfo to (found,k)
unrecoverable = set() unrecoverable = set()
highest_recoverable_seqnum = -1 highest_recoverable_seqnum = -1
for (verinfo, shares) in versionmap.items(): for (verinfo, shares) in list(versionmap.items()):
(seqnum, root_hash, IV, segsize, datalength, k, N, prefix, (seqnum, root_hash, IV, segsize, datalength, k, N, prefix,
offsets_tuple) = verinfo offsets_tuple) = verinfo
shnums = set([shnum for (shnum, server, timestamp) in shares]) shnums = set([shnum for (shnum, server, timestamp) in shares])
@ -667,7 +677,7 @@ class ServermapUpdater(object):
ds = [] ds = []
for shnum,datav in datavs.items(): for shnum,datav in list(datavs.items()):
data = datav[0] data = datav[0]
reader = MDMFSlotReadProxy(ss, reader = MDMFSlotReadProxy(ss,
storage_index, storage_index,

View File

@ -56,7 +56,11 @@ PORTED_MODULES = [
"allmydata.mutable.checker", "allmydata.mutable.checker",
"allmydata.mutable.common", "allmydata.mutable.common",
"allmydata.mutable.filenode", "allmydata.mutable.filenode",
"allmydata.mutable.layout",
"allmydata.mutable.publish", "allmydata.mutable.publish",
"allmydata.mutable.repairer",
"allmydata.mutable.retrieve",
"allmydata.mutable.servermap",
"allmydata.node", "allmydata.node",
"allmydata.storage_client", "allmydata.storage_client",
"allmydata.storage.common", "allmydata.storage.common",