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

Hotfix/The Correct Bundle Update behavior #602

Merged
merged 8 commits into from
Aug 3, 2023

Conversation

PengZheng
Copy link
Contributor

@PengZheng PengZheng commented Aug 1, 2023

This PR implements the correct bundle update behavior when updating from a different bundle location.
Previously if the bundle at that location is older than the bundle in cache, bundle extraction will be skipped, which will fail
the newly added TEST_F(CelixBundleContextBundlesTestSuite, ForceUpdateUsingBundleFromDifferentLocation).
This PR will always update the bundle cache if the external bundle comes from a different location, which is the behavior we advertise in the API documentation.

 * This will do the following:
 *  - unload the bundle with the specified bundle id;
 *  - reload the bundle from the specified location with the specified bundle id;
 *  - start the bundle, if it was previously active.

This PR also improves startup speed when starting with a clean cache.
Previously the framework will traverse the cache directory once for each newly installed bundles (with unknown bundle id).
celix_bundleCache_updateIdForLocationLookupMap could be invoked by celix_bundleCache_create.
But that would lead to unnecessary disk load when the launcher is just used to create bundle cache.

@PengZheng PengZheng added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 1, 2023
@codecov-commenter
Copy link

codecov-commenter commented Aug 2, 2023

Codecov Report

Merging #602 (1f68bad) into master (072cba2) will increase coverage by 0.02%.
The diff coverage is 96.66%.

❗ Current head 1f68bad differs from pull request most recent head 9a0709b. Consider uploading reports for the commit 9a0709b to get more accurate results

@@            Coverage Diff             @@
##           master     #602      +/-   ##
==========================================
+ Coverage   79.68%   79.70%   +0.02%     
==========================================
  Files         256      256              
  Lines       34686    34686              
==========================================
+ Hits        27640    27647       +7     
+ Misses       7046     7039       -7     
Files Changed Coverage Δ
libs/framework/src/bundle.c 71.94% <0.00%> (+1.17%) ⬆️
libs/framework/src/bundle_archive.c 100.00% <100.00%> (ø)
libs/framework/src/celix_bundle_cache.c 98.46% <100.00%> (+0.46%) ⬆️
libs/framework/src/framework.c 84.89% <100.00%> (+0.02%) ⬆️

... and 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@PengZheng PengZheng changed the title Avoid unnecessary cache directory traversal during bundle install Hotfix/The Correct Bundle Update Semantics Aug 2, 2023
@PengZheng PengZheng removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 2, 2023
@PengZheng PengZheng requested a review from pnoltes August 2, 2023 12:16
@PengZheng PengZheng changed the title Hotfix/The Correct Bundle Update Semantics Hotfix/The Correct Bundle Update Behaviour Aug 2, 2023
@PengZheng PengZheng changed the title Hotfix/The Correct Bundle Update Behaviour Hotfix/The Correct Bundle Update behavior Aug 2, 2023
Copy link
Contributor

@pnoltes pnoltes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small remarks, but LGTM

fw_logCode(archive->fw->logger, CELIX_LOG_LEVEL_ERROR, status, "Failed to stat bundle archive directory '%s'", archive->resourceCacheRoot);
return status;
}
// assert(status == 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented-out code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

celixThreadMutex_unlock(&cache->mutex);
(void) bundleArchive_destroy(archive);
return status;
bundleArchive_destroy(archive);
}

/**
* Update location->bundle id lookup map.
*/
static void celix_bundleCache_updateIdForLocationLookupMap(celix_bundle_cache_t* cache) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed that the char* bundleStateProperties = celix_utils_writeOrCreateString(..) string at line 261 is never freed with celix_utils_freeStringIfNotEqual

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}

long celix_bundleCache_findBundleIdForLocation(celix_bundle_cache_t* cache, const char* location) {
long bndId = -1;
celixThreadMutex_lock(&cache->mutex);
if (!cache->locationToBundleIdLookupMapLoaded) {
celix_bundleCache_updateIdForLocationLookupMap(cache);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes of course, this is only needed once.

@PengZheng PengZheng merged commit 2eae9c2 into master Aug 3, 2023
@PengZheng PengZheng deleted the hotfix/framework-startup-optimization branch August 3, 2023 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants