RFC: Change Storage::clear_prefix
, DefaultChildStorage::clear_prefix
and DefaultChildStorage::storage_kill
#588
Labels
Proposal
We would like to add the third version of the
clear_prefix
function for the top trie and child trie:We also would like to add the third version of
storage_kill
for the child trie:To make the function better understandable, here the high level rust representation of the function:
The important changes being here the introduction
maybe_cursor
and the change of the return value toMultiRemovalResults
.DefaultChildStorage::storage_kill
only differs in the way that it doesn't provide anyprefix
toclear_prefix
, besides that the implementation is exactly the same.Implementation of
clear_prefix
Clear keys from the state and the overlay of the currently modified keys that are starting with
prefix
. If there is nomaybe_limit
set, all keys under the givenprefix
are deleted. Ifmaybe_limit
is set, in maximumlimit
keys are being deleted from the state. The keys that are deleted in the overlay aren't counted towards the limit. Ifmaybe_cursor
is given, the implementation needs to seek the givencursor
and start the iteration withcursor
(or the first key in lexicographical order aftercursor
if not present). ReturnsMultiRemovalResults
to inform the caller about the operation.Examples
Let's assume our state looks like this (only showing keys, as values are not important):
The overlay of currently modified keys looks like this (again only keys):
clear_prefix("A", None, None)
:Expected result:
MultiRemovalResults { maybe_cursors: None, state: 0, unique: 1, loops: 1 }
Keys deleted:
[ A ]
clear_prefix("C", None, None)
:Expected result:
MultiRemovalResults { maybe_cursors: None, state: 2, unique: 6, loops: 5 }
Keys deleted:
[ C, CA, CB, CC, CD, CE ]
clear_prefix("C", Some(2), None)
:Expected result:
MultiRemovalResults { maybe_cursors: Some("CB"), state: 2, unique: 5, loops: 2 }
Keys deleted:
[ C, CA, CB, CD, CE ]
clear_prefix("C", Some(2), Some("CB"))
:Expected result:
MultiRemovalResults { maybe_cursors: Some("CD"), state: 1, unique: 4, loops: 2 }
Keys deleted:
[ CB, CC, CD, CE ]
clear_prefix("F", None, None)
:Expected result:
MultiRemovalResults { maybe_cursors: None, state: 0, unique: 1, loops: 0 }
Keys deleted:
[ F ]
Motivation
Currently multiple calls to
clear_prefix
in the same context with the same set of parameters always leads to the same keys being deleted. It is assumed that seeking for a particular key is cheaper than taking all deleted keys for a given prefix from the overlay than to ignore them in subsequent calls toclear_prefix
. So, addingmaybe_cursor
to move the accounting of already deleted keys to the runtime that should know best any way what was already deleted instead of letting the host guess on what should be deleted next.The text was updated successfully, but these errors were encountered: