Page MenuHomePhabricator

[services] Tunnelbroker - Database function that removes messages by a batch using messageIDs and receiver DeviceID.
ClosedPublic

Authored by max on Jul 7 2022, 7:43 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Nov 2, 2:37 PM
Unknown Object (File)
Sat, Nov 2, 2:37 PM
Unknown Object (File)
Sat, Nov 2, 2:37 PM
Unknown Object (File)
Sat, Nov 2, 2:37 PM
Unknown Object (File)
Sat, Nov 2, 2:36 PM
Unknown Object (File)
Sat, Nov 2, 2:33 PM
Unknown Object (File)
Mon, Oct 21, 3:39 AM
Unknown Object (File)
Sun, Oct 20, 3:01 PM

Details

Summary

We need effectively remove messages in a batch from the DynamoDB database using a composite key (messageID + toDeviceID). For this task, we can use the inner BatchWriteItem function from ENG-1302 and delete items by batches instead of 1 by 1.

Linear task: ENG-1361

Test Plan

Run test introduced in D4478

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

max held this revision as a draft.
tomek added 1 blocking reviewer(s): karol.
tomek added inline comments.
services/tunnelbroker/src/Database/DatabaseManager.cpp
224–226 ↗(On Diff #14283)

Why do you prepend the name with cur?

max marked an inline comment as done.

Rebased on parents changes. cur* variable were changed to current*.

services/tunnelbroker/src/Database/DatabaseManager.cpp
224–226 ↗(On Diff #14283)

Why do you prepend the name with cur?

It's shorthand for 'current'. I've changed it to currentWriteRequest instead.

Please fix the typo in this diff's title:

[services] Tunnelbroker - Database function that removes messages in a batch using the composite key and batchWrite
services/tunnelbroker/src/Database/DatabaseManager.cpp
216–227 ↗(On Diff #14386)

Maybe we could create deleteRequest before the for loop? And inside of that loop, we could just change the message id. That would result in a lot fewer allocations, right?

Curious for your perspective

This revision now requires changes to proceed.Jul 11 2022, 3:34 AM
max added inline comments.
services/tunnelbroker/src/Database/DatabaseManager.cpp
216–227 ↗(On Diff #14386)

Maybe we could create deleteRequest before the for loop? And inside of that loop, we could just change the message id. That would result in a lot fewer allocations, right?

Curious for your perspective

There is a reason why I've put it inside the loop and we re-create it every loop:
If we have the Aws::DynamoDB::Model::DeleteRequest deleteRequest outside of the loop and then use deleteRequest.AddKey(...) inside the loop we will always delete only the first key-value because AddKey(...) uses emplace to populate an inner map. In this case, the only first kay-value pair will be inserted because emplace will ignore the next key inserts (because the key already exists in the map from the previous loop).

We can possibly use it outside of the loop if we have the ability to clear the inner map, but SDK doesn't have a such method.

In another way, we can use SetKey(...) instead of AddKey(...), but this changes don't provide any improvement in this case.

max retitled this revision from [services] Tunnelbroker - Database function that remove messages in a batch using the composite key and batchWrite to [services] Tunnelbroker - Database function that removes messages by a batch using messageIDs and receiver DeviceID..
max edited the summary of this revision. (Show Details)
max marked an inline comment as done.
In D4476#128010, @karol-bisztyga wrote:

Please fix the typo in this diff's title:

[services] Tunnelbroker - Database function that removes messages in a batch using the composite key and batchWrite

Thanks for catching it!

This revision is now accepted and ready to land.Jul 19 2022, 2:19 AM
This revision was landed with ongoing or failed builds.Jul 25 2022, 6:45 AM
This revision was automatically updated to reflect the committed changes.