Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 46
[AIT-453] feat: add MAP_CLEAR operation support #1198
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
22 changes: 21 additions & 1 deletion
22 liveobjects/src/main/kotlin/io/ably/lib/objects/ObjectMessage.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 22 additions & 1 deletion
23 liveobjects/src/main/kotlin/io/ably/lib/objects/serialization/MsgpackSerialization.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4 liveobjects/src/main/kotlin/io/ably/lib/objects/type/livemap/DefaultLiveMap.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57 liveobjects/src/main/kotlin/io/ably/lib/objects/type/livemap/LiveMapManager.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -32,6 +32,8 @@ internal class LiveMapManager(private val liveMap: DefaultLiveMap): LiveMapChang | ||
| liveMap.createOperationIsMerged = false // RTLM6b | ||
| liveMap.data.clear() | ||
| liveMap.clearTimeserial = objectState.map?.clearTimeserial // RTLM6i | ||
| objectState.map?.entries?.forEach { (key, entry) -> | ||
| liveMap.data[key] = LiveMapEntry( | ||
| isTombstoned = entry.tombstone ?: false, | ||
| @@ -83,6 +85,11 @@ internal class LiveMapManager(private val liveMap: DefaultLiveMap): LiveMapChang | ||
| liveMap.notifyUpdated(update) | ||
| true // RTLM15d5b | ||
| } | ||
| ObjectOperationAction.MapClear -> { | ||
| val update = applyMapClear(serial) // RTLM15d8 | ||
| liveMap.notifyUpdated(update) // RTLM15d8a | ||
| true // RTLM15d8b | ||
| } | ||
| else -> { | ||
| Log.w(tag, "Invalid ${operation.action} op for LiveMap objectId=${objectId}") // RTLM15d4 | ||
| false | ||
| @@ -118,6 +125,14 @@ internal class LiveMapManager(private val liveMap: DefaultLiveMap): LiveMapChang | ||
| mapSet: MapSet, // RTLM7d1 | ||
| timeSerial: String?, // RTLM7d2 | ||
| ): LiveMapUpdate { | ||
| // RTLM7h - skip if operation is older than the last MAP_CLEAR | ||
| val clearSerial = liveMap.clearTimeserial | ||
| if (clearSerial != null && (timeSerial == null || clearSerial >= timeSerial)) { | ||
| Log.v(tag, | ||
| "Skipping MAP_SET for key=\"${mapSet.key}\": op serial $timeSerial <= clear serial $clearSerial; objectId=$objectId") | ||
| return noOpMapUpdate | ||
| } | ||
| val existingEntry = liveMap.data[mapSet.key] | ||
| // RTLM7a | ||
| @@ -170,6 +185,14 @@ internal class LiveMapManager(private val liveMap: DefaultLiveMap): LiveMapChang | ||
| timeSerial: String?, // RTLM8c2 | ||
| timeStamp: Long?, // RTLM8c3 | ||
| ): LiveMapUpdate { | ||
| // RTLM8g - skip if operation is older than the last MAP_CLEAR | ||
| val clearSerial = liveMap.clearTimeserial | ||
| if (clearSerial != null && (timeSerial == null || clearSerial >= timeSerial)) { | ||
| Log.v(tag, | ||
| "Skipping MAP_REMOVE for key=\"${mapRemove.key}\": op serial $timeSerial <= clear serial $clearSerial; objectId=$objectId") | ||
| return noOpMapUpdate | ||
| } | ||
| val existingEntry = liveMap.data[mapRemove.key] | ||
| // RTLM8a | ||
| @@ -212,6 +235,40 @@ internal class LiveMapManager(private val liveMap: DefaultLiveMap): LiveMapChang | ||
| return LiveMapUpdate(mapOf(mapRemove.key to LiveMapUpdate.Change.REMOVED)) | ||
| } | ||
| /** | ||
| * @spec RTLM24 - Applies MAP_CLEAR operation to LiveMap | ||
| */ | ||
| private fun applyMapClear(timeSerial: String?): LiveMapUpdate { | ||
| val clearSerial = liveMap.clearTimeserial | ||
| // RTLM24c - skip if existing clear serial is strictly newer than incoming op serial | ||
| if (clearSerial != null && (timeSerial == null || clearSerial > timeSerial)) { | ||
| Log.v(tag, | ||
| "Skipping MAP_CLEAR: op serial $timeSerial <= current clear serial $clearSerial; objectId=$objectId") | ||
ttypic marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| return noOpMapUpdate | ||
| } | ||
| Log.v(tag, | ||
| "Updating clearTimeserial; previous=$clearSerial, new=$timeSerial; objectId=$objectId") | ||
| liveMap.clearTimeserial = timeSerial // RTLM24d | ||
| val update = mutableMapOf<String, LiveMapUpdate.Change>() | ||
| // RTLM24e - remove all entries whose serial is older than (or equal to missing) the clear serial | ||
| liveMap.data.entries.removeIf { | ||
| val (key, entry) = it | ||
| val entrySerial = entry.timeserial | ||
| if (entrySerial == null || (timeSerial != null && timeSerial > entrySerial)) { | ||
| update[key] = LiveMapUpdate.Change.REMOVED | ||
| true | ||
| } else { | ||
| false | ||
| } | ||
| } | ||
| return LiveMapUpdate(update) | ||
| } | ||
| /** | ||
| * For Lww CRDT semantics (the only supported LiveMap semantic) an operation | ||
| * Should only be applied if incoming serial is strictly greater than existing entry's serial. | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.