Skip to content

Commit

Permalink
Merge pull request #895 from tahoe-lafs/3502.mutable-python-3-part-2
Browse files Browse the repository at this point in the history
Port allmydata.mutable to Python 3, part 2/2

Fixes ticket:3502
  • Loading branch information
itamarst committed Nov 20, 2020
2 parents cf74d92 + 38275cb commit 729a5a0
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 14 deletions.
Empty file added newsfragments/3502.minor
Empty file.
14 changes: 13 additions & 1 deletion src/allmydata/mutable/layout.py
Original file line number Diff line number Diff line change
@@ -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

import struct
Expand Down Expand Up @@ -1744,7 +1756,7 @@ def _build_verinfo(ignored):


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
# fulfills the requests that it can, and not demand that all
# requests are satisfiable before running it.
Expand Down
11 changes: 11 additions & 0 deletions src/allmydata/mutable/repairer.py
Original file line number Diff line number Diff line change
@@ -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 twisted.internet import defer
Expand Down
19 changes: 15 additions & 4 deletions src/allmydata/mutable/retrieve.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -749,9 +760,9 @@ def _validate_block(self, results, segnum, reader, server, started):

blockhashes = dict(enumerate(blockhashes))
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" % \
sharehashes.keys())
list(sharehashes.keys()))
bht = self._block_hash_trees[reader.shnum]

if bht.needed_hashes(segnum, include_leaf=True):
Expand Down Expand Up @@ -908,7 +919,7 @@ def _decrypt_segment(self, segment_and_salt):


def notify_server_corruption(self, server, shnum, reason):
if isinstance(reason, unicode):
if isinstance(reason, str):
reason = reason.encode("utf-8")
storage_server = server.get_storage_server()
storage_server.advise_corrupt_share(
Expand Down
28 changes: 19 additions & 9 deletions src/allmydata/mutable/servermap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
"""
Ported to Python 3.
"""
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

import sys, time, copy
Expand Down Expand Up @@ -188,7 +198,7 @@ def get_last_update(self):
def dump(self, out=sys.stdout):
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,
offsets_tuple) = verinfo
print("[%s]: sh#%d seq%d-%s %d-of-%d len%d" %
Expand Down Expand Up @@ -226,7 +236,7 @@ def make_versionmap(self):
"""Return a dict that maps versionid to sets of (shnum, server,
timestamp) tuples."""
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))
return versionmap

Expand All @@ -245,7 +255,7 @@ def shares_available(self):
(num_distinct_shares, k, N) tuples."""
versionmap = self.make_versionmap()
all_shares = {}
for verinfo, shares in versionmap.items():
for verinfo, shares in list(versionmap.items()):
s = set()
for (shnum, server, timestamp) in shares:
s.add(shnum)
Expand All @@ -271,7 +281,7 @@ def summarize_versions(self):
"""Return a string describing which versions we know about."""
versionmap = self.make_versionmap()
bits = []
for (verinfo, shares) in versionmap.items():
for (verinfo, shares) in list(versionmap.items()):
vstr = self.summarize_version(verinfo)
shnums = set([shnum for (shnum, server, timestamp) in shares])
bits.append("%d*%s" % (len(shnums), vstr))
Expand All @@ -282,7 +292,7 @@ def recoverable_versions(self):
recoverable."""
versionmap = self.make_versionmap()
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,
offsets_tuple) = verinfo
shnums = set([shnum for (shnum, server, timestamp) in shares])
Expand All @@ -298,7 +308,7 @@ def unrecoverable_versions(self):
versionmap = self.make_versionmap()

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,
offsets_tuple) = verinfo
shnums = set([shnum for (shnum, server, timestamp) in shares])
Expand Down Expand Up @@ -332,7 +342,7 @@ def unrecoverable_newer_versions(self):
healths = {} # maps verinfo to (found,k)
unrecoverable = set()
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,
offsets_tuple) = verinfo
shnums = set([shnum for (shnum, server, timestamp) in shares])
Expand Down Expand Up @@ -667,7 +677,7 @@ def _done_processing(ignored=None):

ds = []

for shnum,datav in datavs.items():
for shnum,datav in list(datavs.items()):
data = datav[0]
reader = MDMFSlotReadProxy(ss,
storage_index,
Expand Down
4 changes: 4 additions & 0 deletions src/allmydata/util/_python3.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@
"allmydata.mutable.checker",
"allmydata.mutable.common",
"allmydata.mutable.filenode",
"allmydata.mutable.layout",
"allmydata.mutable.publish",
"allmydata.mutable.repairer",
"allmydata.mutable.retrieve",
"allmydata.mutable.servermap",
"allmydata.node",
"allmydata.storage_client",
"allmydata.storage.common",
Expand Down

0 comments on commit 729a5a0

Please sign in to comment.