Op Some Codes
parent
b837ed1526
commit
c454ae2dc8
|
@ -26,13 +26,17 @@ from tempfile import mkstemp
|
|||
import threading
|
||||
from collections import deque, OrderedDict
|
||||
from hashlib import sha1
|
||||
|
||||
import common
|
||||
from rangelib import RangeSet
|
||||
|
||||
__all__ = ["EmptyImage", "DataImage", "BlockImageDiff"]
|
||||
|
||||
|
||||
class Settings(object):
|
||||
# Stash size cannot exceed cache_size * threshold.
|
||||
cache_size = None
|
||||
stash_threshold = 0.8
|
||||
|
||||
|
||||
def compute_patch(src, tgt, imgdiff=False):
|
||||
srcfd, srcfile = mkstemp(prefix="src-")
|
||||
tgtfd, tgtfile = mkstemp(prefix="tgt-")
|
||||
|
@ -327,7 +331,7 @@ class BlockImageDiff(object):
|
|||
self.ImproveVertexSequence()
|
||||
|
||||
# Ensure the runtime stash size is under the limit.
|
||||
if self.version >= 2 and common.OPTIONS.cache_size is not None:
|
||||
if self.version >= 2 and Settings.cache_size is not None:
|
||||
self.ReviseStashSize()
|
||||
|
||||
# Double-check our work.
|
||||
|
@ -551,14 +555,14 @@ class BlockImageDiff(object):
|
|||
out.append("".join(free_string))
|
||||
stashed_blocks -= free_size
|
||||
|
||||
if self.version >= 2 and common.OPTIONS.cache_size is not None:
|
||||
if self.version >= 2 and Settings.cache_size is not None:
|
||||
# Sanity check: abort if we're going to need more stash space than
|
||||
# the allowed size (cache_size * threshold). There are two purposes
|
||||
# of having a threshold here. a) Part of the cache may have been
|
||||
# occupied by some recovery logs. b) It will buy us some time to deal
|
||||
# with the oversize issue.
|
||||
cache_size = common.OPTIONS.cache_size
|
||||
stash_threshold = common.OPTIONS.stash_threshold
|
||||
cache_size = Settings.cache_size
|
||||
stash_threshold = Settings.stash_threshold
|
||||
max_allowed = cache_size * stash_threshold
|
||||
assert max_stashed_blocks * self.tgt.blocksize < max_allowed, \
|
||||
'Stash size %d (%d * %d) exceeds the limit %d (%d * %.2f)' % (
|
||||
|
@ -608,7 +612,7 @@ class BlockImageDiff(object):
|
|||
|
||||
if self.version >= 2:
|
||||
self._max_stashed_size = max_stashed_blocks * self.tgt.blocksize
|
||||
OPTIONS = common.OPTIONS
|
||||
OPTIONS = Settings
|
||||
if OPTIONS.cache_size is not None:
|
||||
max_allowed = OPTIONS.cache_size * OPTIONS.stash_threshold
|
||||
print("max stashed blocks: %d (%d bytes), "
|
||||
|
@ -636,8 +640,8 @@ class BlockImageDiff(object):
|
|||
|
||||
# Compute the maximum blocks available for stash based on /cache size and
|
||||
# the threshold.
|
||||
cache_size = common.OPTIONS.cache_size
|
||||
stash_threshold = common.OPTIONS.stash_threshold
|
||||
cache_size = Settings.cache_size
|
||||
stash_threshold = Settings.stash_threshold
|
||||
max_allowed = cache_size * stash_threshold / self.tgt.blocksize
|
||||
|
||||
stashed_blocks = 0
|
||||
|
@ -1129,7 +1133,7 @@ class BlockImageDiff(object):
|
|||
return
|
||||
|
||||
pieces = 0
|
||||
cache_size = common.OPTIONS.cache_size
|
||||
cache_size = Settings.cache_size
|
||||
split_threshold = 0.125
|
||||
max_blocks_per_transfer = int(cache_size * split_threshold /
|
||||
self.tgt.blocksize)
|
||||
|
|
12
common.py
12
common.py
|
@ -1,12 +0,0 @@
|
|||
import blockimgdiff
|
||||
|
||||
|
||||
class Options(object):
|
||||
def __init__(self):
|
||||
# Stash size cannot exceed cache_size * threshold.
|
||||
self.cache_size = None
|
||||
self.stash_threshold = 0.8
|
||||
|
||||
|
||||
OPTIONS = Options()
|
||||
DataImage = blockimgdiff.DataImage
|
Loading…
Reference in New Issue