I split inserting operations into my DB into two parts like (not the real API, just to show the idea):
startInserting(dbKey: Text, value: Text): Nat
(returnsinsertId
)finishInserting(insertId: Nat): (Text, Text)
(returnsdbKey
+ the partition of the DB where it is stored)
This split into two API calls instead of one is necessary, because the insert functionality of my multi-partition DB requires await
(non-atomic operation). If I had just one API call insert
, this would make impossible to check whether the operation succeed.
Now I have a map of max. 15 entries created by startInserting
that keep information for finishInserting
to finish insert operation.
The bug: Call it 15 times and further inserts are blocked. As a workaround I would allow anybody to call finishInserting
even on insertId
created by another user, but in this way, for the user who called startInserting
the return value of finishInserting
would be lost.
I can’t remove the limit on the maximum number of insert operations, as this would allow an attacker to overflow my memory by calling many startInserting
without finishing them by finishInserting
.
So I don’t know what to do.
A similar situation is met in invoice canister. I don’t remember how they solve the similar problem. I think they remove old created invoices in order to save memory, correct? Should I do the same? How many insertions should I allow in parallel? (is 15 a good number?) If old insertions are removed, then should I in TypeScript code repeat startInserting
if necessary more than once?
I realize that my explanation is clumsy. Please ask questions to understand me.