-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Snapshot diff merge operations #142
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation is very clear and easy to follow. Just one note on us skipping a byte at some point in the loop.
src/util/snapshot.cpp
Outdated
bool isInMergeRegion = | ||
mergeIt != mergeRegions.end() && | ||
offset >= mergeIt->second.offset && | ||
offset <= (mergeIt->second.offset + mergeIt->second.length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor point here, I think this should be a <
not a <=
.
If we have a merge region starting at offset 0 with length 3, we want to mark bytes 0,1,2 as dirty and belonging to this merge region. Byte 3 (i.e. 0 + 3) should be out of the region if I am not mistaken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, after having gone through the code, afaict we will only have the case in which offset == mergeIt->second.offset
as then we move the offset
by region.length
.
Maybe we could add an assertion after line 83 like:
if (isDirtyByte && isInMergeRegion) {
assert(offset == mergeIt->second.offset);
...
diffs.emplace_back(diff); | ||
|
||
// Bump the loop variable to the end of this region (note that | ||
// the loop itself will increment onto the next) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I think that offset + length
should point to the first byte after the region, and then the for
increment would skip one byte.
A test that would check this would consist of two consecutive regions with int
s that need to be added. If I am not mistaken that test should now fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, great spot on both of these comments. There was an off-by-one error that meant that the second of two adjacent merge regions would be lost if both had changed. Have added the relevant -1
s and a test.
faabric::util::SnapshotData snap = takeSnapshot(snapKey, 5, false); | ||
|
||
// Set up a couple of ints in the snapshot | ||
int offsetA1 = 5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned earlier, could we have a test where one diff is at offset x
and the other one at offset x + sizeof(int)
?
TEST_CASE_METHOD(SnapshotTestFixture, | ||
"Test edge-cases of snapshot merge regions", | ||
"[util]") | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@csegarragonz here's the test that covers the edge cases
The default merge strategy for snapshot diffs is to overwrite the master with the diffs. This works if each distributed function is writing to different offsets (for example, if each function is writing to a different index in an array), but if they are writing to the same offset, the merging will lose information by overwriting each time.
This PR adds merge operations for summation, subtraction, multiplication, min and max, but this list could be extended in future, primarily focused on in-place reductions.
Applications can set these merge operations at byte-level granularity, e.g. specifying that a 4-byte region at offset
X
should be summed as an integer when merging snapshots.At the moment I've only included integer operations, as these are all that's needed for the current use-case, but again, this could be extended in future.