Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 46
[ECO-5056] use server-provided GC grace period for garbage collection#1158
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
5 commits
Select commit
Hold shift + click to select a range
b56b9fc
[ECO-5056] use server-provided GC grace period for garbage collection
sacOO7 8f1c5e2
[ECO-5056] Updated test helper getMockObjectsAdapter with static mocck
sacOO7 5d6d3bc
[ECO-5056] Added test for getObjects when liveobjects plugin is not i…
sacOO7 ed77613
[ECO-5056] Refactored HelpersTest.kt assertions with concrete types
sacOO7 06a2157
[ECO-5056] Updated retrieveObjectsGCGracePeriod to return gcperiod ev…
sacOO7 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
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
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
2 changes: 2 additions & 0 deletions
2 lib/src/main/java/io/ably/lib/transport/ConnectionManager.java
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
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: 23 additions & 0 deletions
23 lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java
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
14 changes: 14 additions & 0 deletions
14 liveobjects/src/main/kotlin/io/ably/lib/objects/Helpers.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
19 changes: 16 additions & 3 deletions
19 liveobjects/src/main/kotlin/io/ably/lib/objects/ObjectsPool.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 |
|---|---|---|
| @@ -14,6 +14,9 @@ import java.util.concurrent.ConcurrentHashMap | ||
| internal object ObjectsPoolDefaults { | ||
| const val GC_INTERVAL_MS = 1000L * 60 * 5 // 5 minutes | ||
| /** | ||
| * The SDK will attempt to use the `objectsGCGracePeriod` value provided by the server in the `connectionDetails` | ||
| * object of the `CONNECTED` event. | ||
| * If the server does not provide this value, the SDK will fall back to this default value. | ||
| * Must be > 2 minutes to ensure we keep tombstones long enough to avoid the possibility of receiving an operation | ||
| * with an earlier serial that would not have been applied if the tombstone still existed. | ||
| * | ||
| @@ -49,10 +52,19 @@ internal class ObjectsPool( | ||
| private val gcScope = CoroutineScope(Dispatchers.Default + SupervisorJob()) | ||
| private var gcJob: Job // Job for the garbage collection coroutine | ||
| @Volatile private var gcGracePeriod = ObjectsPoolDefaults.GC_GRACE_PERIOD_MS | ||
| private var gcPeriodSubscription: ObjectsSubscription | ||
| init { | ||
| // RTO3b - Initialize pool with root object | ||
| pool[ROOT_OBJECT_ID] = DefaultLiveMap.zeroValue(ROOT_OBJECT_ID, realtimeObjects) | ||
| // Start garbage collection coroutine | ||
| // Start garbage collection coroutine with server-provided grace period if available | ||
| gcPeriodSubscription = realtimeObjects.adapter.onGCGracePeriodUpdated { period -> | ||
| period?.let { | ||
| gcGracePeriod = it | ||
| Log.i(tag, "Using objectsGCGracePeriod from server: $gcGracePeriod ms") | ||
| } ?: Log.i(tag, "Server did not provide objectsGCGracePeriod, using default: $gcGracePeriod ms") | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| gcJob = startGCJob() | ||
| } | ||
| @@ -123,9 +135,9 @@ internal class ObjectsPool( | ||
| */ | ||
| private fun onGCInterval() { | ||
| pool.entries.removeIf { (_, obj) -> | ||
| if (obj.isEligibleForGc()) { true } // Remove from pool | ||
| if (obj.isEligibleForGc(gcGracePeriod)) { true } // Remove from pool | ||
| else { | ||
| obj.onGCInterval() | ||
| obj.onGCInterval(gcGracePeriod) | ||
| false // Keep in pool | ||
| } | ||
| } | ||
| @@ -152,6 +164,7 @@ internal class ObjectsPool( | ||
| * Should be called when the pool is no longer needed. | ||
| */ | ||
| fun dispose() { | ||
| gcPeriodSubscription.unsubscribe() | ||
| gcJob.cancel() | ||
| gcScope.cancel() | ||
| pool.clear() | ||
29 changes: 24 additions & 5 deletions
29 liveobjects/src/main/kotlin/io/ably/lib/objects/type/BaseRealtimeObject.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
2 changes: 1 addition & 1 deletion
2 liveobjects/src/main/kotlin/io/ably/lib/objects/type/livecounter/DefaultLiveCounter.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: 2 additions & 2 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
5 changes: 2 additions & 3 deletions
5 liveobjects/src/main/kotlin/io/ably/lib/objects/type/livemap/LiveMapEntry.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
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.