-
Notifications
You must be signed in to change notification settings - Fork 297
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
Development
: Fix hazelcast issue on server shutdown
#9602
Conversation
WalkthroughThe Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (1)
src/main/java/de/tum/cit/aet/artemis/core/service/feature/FeatureToggleService.java (1)
19-19
: Ensure consistent and appropriate logging levels for Hazelcast inactivity.Currently, the code logs an error message when the Hazelcast instance is inactive in several methods. If Hazelcast being inactive can occur during normal shutdown or expected scenarios, consider logging at a
WARN
level instead ofERROR
to reflect the severity appropriately.Apply this diff to adjust the logging level:
- log.error("Failed to get features in FeatureToggleService as Hazelcast instance is not active any more."); + log.warn("Hazelcast instance is inactive; cannot retrieve features.");Repeat for other similar log statements.
Also applies to: 51-53, 122-123, 140-141, 157-158, 174-175
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
- src/main/java/de/tum/cit/aet/artemis/core/service/feature/FeatureToggleService.java (7 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/java/de/tum/cit/aet/artemis/core/service/feature/FeatureToggleService.java (1)
Pattern
src/main/java/**/*.java
: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports
🔇 Additional comments (3)
src/main/java/de/tum/cit/aet/artemis/core/service/feature/FeatureToggleService.java (3)
60-60
: Verify the use of@EventListener(ApplicationReadyEvent.class)
for theinit()
method.Changing the initialization from
@PostConstruct
to@EventListener(ApplicationReadyEvent.class)
alters when thefeatures
map is initialized. Ensure that all dependencies on thefeatures
map are unaffected by this change and that no feature checks occur before the application is fully ready.
151-159
:⚠️ Potential issueAssess the handling of empty results in
enabledFeatures()
method when Hazelcast is inactive.Returning an empty list when the Hazelcast instance is inactive might lead callers to believe that no features are enabled, potentially causing unintended behavior. Consider whether it's appropriate to return an empty list or if an exception should be raised to alert the system of the Hazelcast state.
Use this script to identify how the returned list from
enabledFeatures()
is used:#!/bin/bash # Description: Find all usages of enabledFeatures and examine the handling of an empty list # Search for all calls to enabledFeatures rg -A 2 'enabledFeatures\('
133-142
:⚠️ Potential issueReview the error handling and return values in
isFeatureEnabled()
method.When the Hazelcast instance is not active, the method logs an error and returns
false
. Consider whether returningfalse
accurately reflects the feature's status or if it might mask a deeper issue. You might want to throw an exception or notify the caller in a different way to handle this scenario appropriately.Run the following script to check how
isFeatureEnabled()
is used across the codebase and whether callers handle afalse
value as an indication of Hazelcast being inactive:
src/main/java/de/tum/cit/aet/artemis/core/service/feature/FeatureToggleService.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/feature/FeatureToggleService.java
Outdated
Show resolved
Hide resolved
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.
Went over some courses on Artemis on TS3. No problems were found!
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.
I think defining the logged name dynamically is a cleaner approach, but if you disagree I do not mind - I guess that is rather opinionated and does not need to be changed for my approve 🤷
A small change request: please generalize the check hazelcastInstance != null && hazelcastInstance.getLifecycleService().isRunning()
in a simple method, so adjustments would be easier in the future :)
src/main/java/de/tum/cit/aet/artemis/core/service/feature/FeatureToggleService.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/feature/FeatureToggleService.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/feature/FeatureToggleService.java
Outdated
Show resolved
Hide resolved
52337bc
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
src/main/java/de/tum/cit/aet/artemis/core/service/feature/FeatureToggleService.java (1)
140-140
: Standardize error message format across methods.The error messages have slight inconsistencies in their format. Consider standardizing them:
- log.error("Failed to check if feature is enabled in FeatureToggleService as Hazelcast instance is not active any more."); + log.error("Failed to check if feature is enabled in {} as Hazelcast instance is not active anymore.", FeatureToggleService.class.getSimpleName()); - log.error("Failed to retrieve enabled features update in FeatureToggleService as Hazelcast instance is not active any more."); + log.error("Failed to retrieve enabled features in {} as Hazelcast instance is not active anymore.", FeatureToggleService.class.getSimpleName()); - log.error("Failed to retrieve disabled features update in FeatureToggleService as Hazelcast instance is not active any more."); + log.error("Failed to retrieve disabled features in {} as Hazelcast instance is not active anymore.", FeatureToggleService.class.getSimpleName());Also applies to: 157-157, 174-174
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
- src/main/java/de/tum/cit/aet/artemis/core/service/feature/FeatureToggleService.java (7 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/java/de/tum/cit/aet/artemis/core/service/feature/FeatureToggleService.java (1)
Pattern
src/main/java/**/*.java
: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports
🔇 Additional comments (4)
src/main/java/de/tum/cit/aet/artemis/core/service/feature/FeatureToggleService.java (4)
60-60
: LGTM! Good improvement in initialization timing.The change from
@PostConstruct
to@EventListener(ApplicationReadyEvent.class)
ensures that initialization occurs after the application is fully ready, which is more appropriate for Hazelcast initialization.
84-87
: LGTM! Well-structured feature management methods.The changes improve safety through proper error handling and the use of Optional. The parameter rename in updateFeatureToggles enhances clarity by avoiding shadowing.
Also applies to: 96-99, 108-112
179-181
: LGTM! Good extraction of Hazelcast state check.The helper method effectively reduces code duplication and improves maintainability. It's used consistently throughout the class.
Line range hint
45-181
: Consider implementing state recovery mechanism.While the current implementation handles Hazelcast unavailability gracefully, consider implementing a state recovery mechanism when Hazelcast becomes available again. This could help maintain feature toggle consistency across service restarts or temporary network issues.
Let's check if there's any existing recovery mechanism:
src/main/java/de/tum/cit/aet/artemis/core/service/feature/FeatureToggleService.java
Show resolved
Hide resolved
|
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.
Thanks for the changes, approve code
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.
tested on ts5 with different courses and faced no errors
Checklist
General
Server
Motivation and Context
This PR fixes an issue that happens at server shutdown
Steps for Testing
Prerequisites:
Testserver States
Note
These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.
Review Progress
Performance Review
Code Review
Manual Tests
Performance Tests
Test Coverage
Screenshots
Summary by CodeRabbit
New Features
Improvements
Bug Fixes