mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-21 02:01:31 +00:00
lazily create DownloadNode upon first read()/get_segment()
This commit is contained in:
parent
abcd6e0e96
commit
2a05aa2d91
@ -31,14 +31,24 @@ class CiphertextFileNode:
|
||||
if history:
|
||||
history.add_download(ds)
|
||||
download_status = ds
|
||||
self._node = DownloadNode(verifycap, storage_broker, secret_holder,
|
||||
terminator, history, download_status)
|
||||
self._terminator = terminator
|
||||
self._history = history
|
||||
self._download_status = download_status
|
||||
self._node = None # created lazily, on read()
|
||||
|
||||
def _maybe_create_download_node(self):
|
||||
if self._node is None:
|
||||
self._node = DownloadNode(self._verifycap, self._storage_broker,
|
||||
self._secret_holder,
|
||||
self._terminator,
|
||||
self._history, self._download_status)
|
||||
|
||||
def read(self, consumer, offset=0, size=None, read_ev=None):
|
||||
"""I am the main entry point, from which FileNode.read() can get
|
||||
data. I feed the consumer with the desired range of ciphertext. I
|
||||
return a Deferred that fires (with the consumer) when the read is
|
||||
finished."""
|
||||
self._maybe_create_download_node()
|
||||
return self._node.read(consumer, offset, size, read_ev)
|
||||
|
||||
def get_segment(self, segnum):
|
||||
@ -56,10 +66,12 @@ class CiphertextFileNode:
|
||||
segment, so that you can call get_segment() before knowing the
|
||||
segment size, and still know which data you received.
|
||||
"""
|
||||
self._maybe_create_download_node()
|
||||
return self._node.get_segment(segnum)
|
||||
|
||||
def get_segment_size(self):
|
||||
# return a Deferred that fires with the file's real segment size
|
||||
self._maybe_create_download_node()
|
||||
return self._node.get_segsize()
|
||||
|
||||
def get_storage_index(self):
|
||||
|
@ -327,6 +327,7 @@ class DownloadTest(_Base, unittest.TestCase):
|
||||
self.c0 = self.g.clients[0]
|
||||
self.load_shares()
|
||||
n = self.c0.create_node_from_uri(immutable_uri)
|
||||
n._cnode._maybe_create_download_node()
|
||||
|
||||
# Cause the downloader to guess a segsize that's too low, so it will
|
||||
# ask for a segment number that's too high (beyond the end of the
|
||||
@ -385,6 +386,7 @@ class DownloadTest(_Base, unittest.TestCase):
|
||||
d = self.c0.upload(u)
|
||||
def _uploaded(ur):
|
||||
n = self.c0.create_node_from_uri(ur.uri)
|
||||
n._cnode._maybe_create_download_node()
|
||||
n._cnode._node._build_guessed_tables(u.max_segment_size)
|
||||
d1 = n.read(con1, 70, 20)
|
||||
#d2 = n.read(con2, 140, 20) # XXX
|
||||
@ -413,6 +415,7 @@ class DownloadTest(_Base, unittest.TestCase):
|
||||
d = self.c0.upload(u)
|
||||
def _uploaded(ur):
|
||||
n = self.c0.create_node_from_uri(ur.uri)
|
||||
n._cnode._maybe_create_download_node()
|
||||
n._cnode._node._build_guessed_tables(u.max_segment_size)
|
||||
d = n.read(con1, 12000, 20)
|
||||
def _read1(ign):
|
||||
@ -620,6 +623,7 @@ class DownloadTest(_Base, unittest.TestCase):
|
||||
d = self.c0.upload(u)
|
||||
def _uploaded(ur):
|
||||
n = self.c0.create_node_from_uri(ur.uri)
|
||||
n._cnode._maybe_create_download_node()
|
||||
n._cnode._node._build_guessed_tables(u.max_segment_size)
|
||||
|
||||
d = download_to_data(n)
|
||||
@ -658,6 +662,7 @@ class DownloadTest(_Base, unittest.TestCase):
|
||||
d = self.c0.upload(u)
|
||||
def _uploaded(ur):
|
||||
n = self.c0.create_node_from_uri(ur.uri)
|
||||
n._cnode._maybe_create_download_node()
|
||||
n._cnode._node._build_guessed_tables(u.max_segment_size)
|
||||
d1 = n.read(con1, 70, 20)
|
||||
#d2 = n.read(con2, 140, 20)
|
||||
@ -805,6 +810,7 @@ class Corruption(_Base, unittest.TestCase):
|
||||
|
||||
def _download(ign, imm_uri, which, expected):
|
||||
n = self.c0.create_node_from_uri(imm_uri)
|
||||
n._cnode._maybe_create_download_node()
|
||||
# for this test to work, we need to have a new Node each time.
|
||||
# Make sure the NodeMaker's weakcache hasn't interfered.
|
||||
assert not n._cnode._node._shares
|
||||
@ -945,6 +951,7 @@ class Corruption(_Base, unittest.TestCase):
|
||||
]
|
||||
def _download(imm_uri):
|
||||
n = self.c0.create_node_from_uri(imm_uri)
|
||||
n._cnode._maybe_create_download_node()
|
||||
# for this test to work, we need to have a new Node each time.
|
||||
# Make sure the NodeMaker's weakcache hasn't interfered.
|
||||
assert not n._cnode._node._shares
|
||||
|
@ -231,6 +231,7 @@ class HungServerDownloadTest(GridTestMixin, ShouldFailMixin, PollMixin,
|
||||
def _reduce_max_outstanding_requests_and_download(ign):
|
||||
self._hang_shares(range(5))
|
||||
n = self.c0.create_node_from_uri(self.uri)
|
||||
n._cnode._maybe_create_download_node()
|
||||
self._sf = n._cnode._node._sharefinder
|
||||
self._sf.max_outstanding_requests = 5
|
||||
self._sf.OVERDUE_TIMEOUT = 1000.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user