Skip to content
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

Merged
merged 3 commits into from
Oct 27, 2024

Conversation

BBesrour
Copy link
Member

@BBesrour BBesrour commented Oct 26, 2024

Checklist

General

Server

  • Important: I implemented the changes with a very good performance and prevented too many (unnecessary) and too complex database calls.
  • I strictly followed the principle of data economy for all database calls.
  • I strictly followed the server coding and design guidelines.
  • I added multiple integration tests (Spring) related to the features (with a high test coverage).
  • I added pre-authorization annotations according to the guidelines and checked the course groups for all new REST Calls (security).
  • I documented the Java code using JavaDoc style.

Motivation and Context

This PR fixes an issue that happens at server shutdown

Oct 24 09:34:35 artemis-production-node1.artemis.in.tum.de java[607710]: com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
...
Oct 24 09:34:35 artemis-production-node1.artemis.in.tum.de java[607710]:         at de.tum.cit.aet.artemis.core.service.feature.FeatureToggleService.enabledFeatures(FeatureToggleService.java:112)

Steps for Testing

Prerequisites:

  • 1 Instructor
  1. Navigate through artemis and make sure no error occurs (visiting a course and submitting should be enough)

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

  • I (as a reviewer) confirm that the client changes (in particular related to REST calls and UI responsiveness) are implemented with a very good performance even for very large courses with more than 2000 students.
  • I (as a reviewer) confirm that the server changes (in particular related to database calls) are implemented with a very good performance even for very large courses with more than 2000 students.

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Performance Tests

  • Test 1
  • Test 2

Test Coverage

Screenshots

Summary by CodeRabbit

  • New Features

    • Enhanced error handling and control flow for feature toggles.
    • Introduced a safer method for accessing feature states.
  • Improvements

    • Updated initialization to occur after application readiness.
    • Added lifecycle checks for feature status methods to ensure operations are performed only when the system is active.
  • Bug Fixes

    • Improved logging and error handling for inactive Hazelcast instances.

@BBesrour BBesrour self-assigned this Oct 26, 2024
@BBesrour BBesrour requested a review from a team as a code owner October 26, 2024 20:09
@github-actions github-actions bot added server Pull requests that update Java code. (Added Automatically!) core Pull requests that affect the corresponding module labels Oct 26, 2024
Copy link

coderabbitai bot commented Oct 26, 2024

Walkthrough

The FeatureToggleService class has been modified to improve error handling and control flow concerning the lifecycle of the Hazelcast instance. Key changes include the introduction of a new method getFeatures() for safer access to the features map, updates to the init() method to use @EventListener, and revisions to several methods to ensure operations are only performed when the Hazelcast instance is active. These modifications aim to reduce exceptions related to the instance's state.

Changes

File Change Summary
src/main/java/de/tum/cit/aet/artemis/core/service/feature/FeatureToggleService.java - Added method private Optional<Map<Feature, Boolean>> getFeatures().
- Updated method signature of updateFeatureToggles(final Map<Feature, Boolean> features) to updateFeatureToggles(final Map<Feature, Boolean> updatedFeatures).
- Modified init() to use @EventListener(ApplicationReadyEvent.class).
- Updated enableFeature(), disableFeature(), updateFeatureToggles(), sendUpdate(), isFeatureEnabled(), enabledFeatures(), and disabledFeatures() to incorporate lifecycle checks for the Hazelcast instance.

Possibly related PRs

Suggested labels

tests, bugfix

Suggested reviewers

  • krusche
  • ole-ve
  • dfuchss

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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 of ERROR 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

📥 Commits

Files that changed from the base of the PR and between 6e1c562 and 95645e3.

📒 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 the init() method.

Changing the initialization from @PostConstruct to @EventListener(ApplicationReadyEvent.class) alters when the features map is initialized. Ensure that all dependencies on the features map are unaffected by this change and that no feature checks occur before the application is fully ready.


151-159: ⚠️ Potential issue

Assess 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 issue

Review 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 returning false 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 a false value as an indication of Hazelcast being inactive:

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 26, 2024
SimonEntholzer
SimonEntholzer previously approved these changes Oct 26, 2024
Copy link

@HawKhiem HawKhiem left a 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!

Copy link
Contributor

@florian-glombik florian-glombik left a 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 :)

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Files that changed from the base of the PR and between 95645e3 and 52337bc.

📒 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:

Copy link

⚠️ Unable to deploy to test servers ⚠️

Testserver "artemis-test3.artemis.cit.tum.de" is already in use by PR #9603.

@github-actions github-actions bot added the deployment-error Added by deployment workflows if an error occured label Oct 27, 2024
Copy link
Contributor

@florian-glombik florian-glombik left a 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

@florian-glombik florian-glombik removed the deployment-error Added by deployment workflows if an error occured label Oct 27, 2024
@asliayk asliayk temporarily deployed to artemis-test5.artemis.cit.tum.de October 27, 2024 13:56 — with GitHub Actions Inactive
Copy link
Contributor

@asliayk asliayk left a 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

@krusche krusche added this to the 7.6.4 milestone Oct 27, 2024
@krusche krusche merged commit efe7c16 into develop Oct 27, 2024
51 of 56 checks passed
@krusche krusche deleted the bugfix/fix-hazelcast-errors-on-shutdown branch October 27, 2024 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Pull requests that affect the corresponding module ready for review server Pull requests that update Java code. (Added Automatically!)
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

7 participants