Skip to content

Commit

Permalink
Python API: send pos and version in spare chunk requests
Browse files Browse the repository at this point in the history
  • Loading branch information
fvennetier committed Mar 26, 2021
1 parent 4bfc5ab commit 1e5b70f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
5 changes: 4 additions & 1 deletion oio/api/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,14 +795,17 @@ def __call__(self):
self._fix_mc_pos(self.first_body, mc_pos)
self._all_chunks.extend(self.first_body)
yield self.first_body
if 'version' not in self.extra_kwargs:
self.extra_kwargs['version'] = self.obj_meta['version']
while True:
mc_pos += 1
# If we are here, we know that the client is still
# listening (he is uploading data). It seems a good idea to
# postpone the deadline.
set_deadline_from_read_timeout(self.extra_kwargs, force=True)
meta, next_body = self.container_client.content_prepare(
self.account, self.container, self.obj_name, size=1,
self.account, self.container, self.obj_name,
position=mc_pos, size=1,
stgpol=self.policy, **self.extra_kwargs)
self.obj_meta['properties'].update(meta.get('properties', {}))
self._fix_mc_pos(next_body, mc_pos)
Expand Down
14 changes: 10 additions & 4 deletions oio/container/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,15 +751,20 @@ def content_locate(self, account=None, reference=None, path=None, cid=None,

@extract_reference_params
def content_prepare(self, account=None, reference=None, path=None,
size=None, cid=None, stgpol=None, content_id=None,
version=None, params=None, **kwargs):
position=0, size=None, cid=None, stgpol=None,
content_id=None, version=None, params=None, **kwargs):
"""
Prepare an upload: get URLs of chunks on available rawx.
:param position: position a the metachunk that must be prepared
:param stgpol: name of the storage policy of the object being uploaded
:param version: version of the object being uploaded. This is required
only on the second and later calls to this method to get coherent
results.
:keyword autocreate: create container if it doesn't exist
"""
uri = self._make_uri('content/prepare')
data = {'size': size}
data = {'size': size, 'position': position}
if stgpol:
data['policy'] = stgpol
data = json.dumps(data)
Expand Down Expand Up @@ -859,7 +864,8 @@ def content_touch(self, account=None, reference=None, path=None, cid=None,
self._direct_request('POST', uri, params=params, **kwargs)

@extract_reference_params
def content_spare(self, account=None, reference=None, path=None, data=None,
def content_spare(self, account=None, reference=None, path=None,
version=None, data=None,
cid=None, stgpol=None, position=None, params=None,
**kwargs):
uri = self._make_uri('content/spare')
Expand Down
9 changes: 5 additions & 4 deletions oio/content/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ def _get_spare_chunk(self, chunks_notin, chunks_broken, position,
for attempt in range(max_attempts):
try:
spare_resp = self.container_client.content_spare(
cid=self.container_id, path=self.content_id,
data=spare_data, stgpol=self.policy, position=position,
cid=self.container_id, path=self.path,
version=self.version, data=spare_data,
stgpol=self.policy, position=position,
**kwargs)
quals = extract_chunk_qualities(
spare_resp.get('properties', {}), raw=True)
Expand Down Expand Up @@ -268,8 +269,8 @@ def move_chunk(self, chunk_id, check_quality=False, dry_run=False,
metapos=current_chunk.metapos).exclude(id=chunk_id).all()

spare_urls, qualities = self._get_spare_chunk(
other_chunks, [current_chunk], check_quality=check_quality,
max_attempts=max_attempts, position=current_chunk.pos, **kwargs)
other_chunks, [current_chunk], position=current_chunk.pos,
check_quality=check_quality, max_attempts=max_attempts, **kwargs)

# Sort chunks by score to try to copy with higher score.
# When scores are close together (e.g. [95, 94, 94, 93, 50]),
Expand Down
3 changes: 2 additions & 1 deletion oio/content/ec.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def rebuild_chunk(self, chunk_id, allow_same_rawx=False, chunk_pos=None,
broken_list = list()
if not allow_same_rawx and chunk_id is not None:
broken_list.append(current_chunk)
spare_url, _quals = self._get_spare_chunk(chunks.all(), broken_list)
spare_url, _quals = self._get_spare_chunk(chunks.all(), broken_list,
position=current_chunk.pos)
new_chunk = Chunk({'pos': current_chunk.pos, 'url': spare_url[0]})

# Regenerate the lost chunk's data, from existing chunks
Expand Down
2 changes: 1 addition & 1 deletion oio/content/plain.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def rebuild_chunk(self, chunk_id, allow_same_rawx=False, chunk_pos=None,
if not allow_same_rawx and chunk_id is not None:
broken_list.append(current_chunk)
spare_urls, _quals = self._get_spare_chunk(
duplicate_chunks, broken_list)
duplicate_chunks, broken_list, position=current_chunk.pos)
spare_url = spare_urls[0]

# Actually create the spare chunk, by duplicating a good one
Expand Down

0 comments on commit 1e5b70f

Please sign in to comment.