|
@@ -195,6 +195,9 @@ class Repository:
|
|
|
# segment_n PUT A, segment_x DELETE A
|
|
|
# After the "DELETE A" in segment_x the shadow index will contain "A -> [n]".
|
|
|
# .delete() is updating this index, it is persisted into "hints" file and is later used by .compact_segments().
|
|
|
+ # We need the entries in the shadow_index to not accidentally drop the "DELETE A" when we compact segment_x
|
|
|
+ # only (and we do not compact segment_n), because DELETE A is still needed then because PUT A will be still
|
|
|
+ # there. Otherwise chunk A would reappear although it was previously deleted.
|
|
|
self.shadow_index = {}
|
|
|
self._active_txn = False
|
|
|
self.lock_wait = lock_wait
|
|
@@ -960,6 +963,7 @@ class Repository:
|
|
|
in_index = self.index[key]
|
|
|
self.compact[in_index.segment] += header_size(tag) + size
|
|
|
self.segments[in_index.segment] -= 1
|
|
|
+ self.shadow_index.setdefault(key, []).append(in_index.segment)
|
|
|
except KeyError:
|
|
|
pass
|
|
|
self.index[key] = NSIndexEntry(segment, offset, size)
|
|
@@ -977,6 +981,7 @@ class Repository:
|
|
|
# is already gone, then it was already compacted.
|
|
|
self.segments[in_index.segment] -= 1
|
|
|
self.compact[in_index.segment] += header_size(tag) + in_index.size
|
|
|
+ self.shadow_index.setdefault(key, []).append(in_index.segment)
|
|
|
elif tag == TAG_COMMIT:
|
|
|
continue
|
|
|
else:
|
|
@@ -1299,11 +1304,11 @@ class Repository:
|
|
|
except KeyError:
|
|
|
pass
|
|
|
else:
|
|
|
- # note: doing a delete first will do some bookkeeping.
|
|
|
- # we do not want to update the shadow_index here, because
|
|
|
- # we know already that we will PUT to this id, so it will
|
|
|
- # be in the repo index (and we won't need it in the shadow_index).
|
|
|
- self._delete(id, in_index.segment, in_index.offset, in_index.size, update_shadow_index=False)
|
|
|
+ # this put call supersedes a previous put to same id.
|
|
|
+ # it is essential to do a delete first to get correct quota bookkeeping
|
|
|
+ # and also a correctly updated shadow_index, so that the compaction code
|
|
|
+ # does not wrongly resurrect an old PUT by dropping a DEL that is still needed.
|
|
|
+ self._delete(id, in_index.segment, in_index.offset, in_index.size)
|
|
|
segment, offset = self.io.write_put(id, data)
|
|
|
self.storage_quota_use += header_size(TAG_PUT2) + len(data)
|
|
|
self.segments.setdefault(segment, 0)
|
|
@@ -1327,16 +1332,15 @@ class Repository:
|
|
|
in_index = self.index.pop(id)
|
|
|
except KeyError:
|
|
|
raise self.ObjectNotFound(id, self.path) from None
|
|
|
- # if we get here, there is an object with this id in the repo,
|
|
|
- # we write a DEL here that shadows the respective PUT.
|
|
|
- # after the delete, the object is not in the repo index any more,
|
|
|
- # for the compaction code, we need to update the shadow_index in this case.
|
|
|
- self._delete(id, in_index.segment, in_index.offset, in_index.size, update_shadow_index=True)
|
|
|
+ self._delete(id, in_index.segment, in_index.offset, in_index.size)
|
|
|
|
|
|
- def _delete(self, id, segment, offset, size, *, update_shadow_index):
|
|
|
+ def _delete(self, id, segment, offset, size):
|
|
|
# common code used by put and delete
|
|
|
- if update_shadow_index:
|
|
|
- self.shadow_index.setdefault(id, []).append(segment)
|
|
|
+ # because we'll write a DEL tag to the repository, we must update the shadow index.
|
|
|
+ # this is always true, no matter whether we are called from put() or delete().
|
|
|
+ # the compaction code needs this to not drop DEL tags if they are still required
|
|
|
+ # to keep a PUT in an earlier segment in the "effectively deleted" state.
|
|
|
+ self.shadow_index.setdefault(id, []).append(segment)
|
|
|
self.segments[segment] -= 1
|
|
|
self.compact[segment] += header_size(TAG_PUT2) + size
|
|
|
segment, size = self.io.write_delete(id)
|