-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Make oplock_hold_time_ms configurable #5975
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
Conversation
Make the oplock hold time configurable and drop the default down to 50% of the configured lock timeout to avoid lock expiration between the lease breaker sleep ending and the coroutine actually getting scheduled for execution.
CodSpeed Performance ReportMerging #5975 will not alter performanceComparing Summary
|
Greptile OverviewGreptile SummaryThis PR makes the opportunistic lock hold time configurable via the Key changes:
The change addresses a race condition where the previous 80% threshold could cause locks to expire between the lease breaker sleep ending and coroutine execution. Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant App as Application
participant Env as Environment Variables
participant SMR as StateManagerRedis
participant Lock as Redis Lock
participant LB as Lease Breaker
App->>Env: Read REFLEX_OPLOCK_HOLD_TIME_MS
Env-->>App: Return configured value or 0
App->>SMR: Initialize StateManagerRedis
SMR->>SMR: Call _default_oplock_hold_time_ms()
alt REFLEX_OPLOCK_HOLD_TIME_MS set
SMR->>SMR: Use configured value
else REFLEX_OPLOCK_HOLD_TIME_MS is 0
SMR->>SMR: Calculate lock_expiration // 2
Note over SMR: Default: 50% of lock expiration<br/>(e.g., 5000ms for 10000ms)
end
SMR->>SMR: Validate oplock_hold_time_ms < lock_expiration
alt Validation fails
SMR-->>App: Raise InvalidLockWarningThresholdError
end
App->>SMR: Acquire opportunistic lock
SMR->>Lock: Acquire Redis lock
Lock-->>SMR: Lock acquired
SMR->>LB: Start lease_breaker task
LB->>LB: Calculate lease_break_time<br/>= oplock_hold_time_ms / 1000
Note over LB: Previously: lock_expiration * 0.8 / 1000<br/>Now: configurable oplock_hold_time_ms / 1000
LB->>LB: Sleep for lease_break_time seconds
LB->>Lock: Release lock after sleep
Lock-->>LB: Lock released
LB-->>SMR: Lease breaker completed
|
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.
2 files reviewed, 1 comment
| return environment.REFLEX_OPLOCK_HOLD_TIME_MS.get() or ( | ||
| _default_lock_expiration() // 2 | ||
| ) |
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.
style: Add a comment explaining the time calculation in human-readable terms, e.g., "# Default to 50% of lock expiration (e.g., 5000ms for 10000ms expiration)"
| return environment.REFLEX_OPLOCK_HOLD_TIME_MS.get() or ( | |
| _default_lock_expiration() // 2 | |
| ) | |
| return environment.REFLEX_OPLOCK_HOLD_TIME_MS.get() or ( | |
| _default_lock_expiration() // 2 # Default to 50% of lock expiration (e.g., 5000ms for 10000ms expiration) | |
| ) |
Context Used: Rule from dashboard - When using time-based calculations in code, include comments that explain the time duration in human... (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: reflex/istate/manager/redis.py
Line: 59:61
Comment:
**style:** Add a comment explaining the time calculation in human-readable terms, e.g., "# Default to 50% of lock expiration (e.g., 5000ms for 10000ms expiration)"
```suggestion
return environment.REFLEX_OPLOCK_HOLD_TIME_MS.get() or (
_default_lock_expiration() // 2 # Default to 50% of lock expiration (e.g., 5000ms for 10000ms expiration)
)
```
**Context Used:** Rule from `dashboard` - When using time-based calculations in code, include comments that explain the time duration in human... ([source](https://app.greptile.com/review/custom-context?memory=f12765cb-0537-4be8-81ad-061314e0e5d0))
How can I resolve this? If you propose a fix, please make it concise.
Make the oplock hold time configurable and drop the default down to 50% of the configured lock timeout to avoid lock expiration between the lease breaker sleep ending and the coroutine actually getting scheduled for execution.