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

Adding cleaning up of the resources owned by the terminology service. #1391

Merged
merged 8 commits into from
Jun 26, 2023

Conversation

piotrszul
Copy link
Collaborator

Resolves #1283.

…(e.g. connection pool and cache manager) at the JVM shutdown.
@codecov
Copy link

codecov bot commented Mar 29, 2023

Codecov Report

Patch coverage: 82.05% and project coverage change: -0.02 ⚠️

Comparison is base (248bf18) 85.54% compared to head (062e8f2) 85.53%.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1391      +/-   ##
============================================
- Coverage     85.54%   85.53%   -0.02%     
  Complexity      139      139              
============================================
  Files           338      339       +1     
  Lines          7784     7806      +22     
  Branches        517      519       +2     
============================================
+ Hits           6659     6677      +18     
- Misses          835      840       +5     
+ Partials        290      289       -1     
Impacted Files Coverage Δ
...java/au/csiro/pathling/fhir/TerminologyClient.java 84.00% <25.00%> (-7.31%) ⬇️
...java/au/csiro/pathling/utilities/ObjectHolder.java 76.19% <62.50%> (-9.53%) ⬇️
...va/au/csiro/pathling/utilities/ResourceCloser.java 93.75% <93.75%> (ø)
.../csiro/pathling/fhir/DefaultTerminologyClient.java 89.28% <100.00%> (ø)
...o/pathling/terminology/BaseTerminologyService.java 66.66% <100.00%> (-3.34%) ⬇️
...athling/terminology/DefaultTerminologyService.java 100.00% <100.00%> (ø)
.../terminology/DefaultTerminologyServiceFactory.java 90.00% <100.00%> (ø)
...terminology/caching/CachingTerminologyService.java 100.00% <100.00%> (ø)
...ogy/caching/InMemoryCachingTerminologyService.java 100.00% <100.00%> (ø)
...y/caching/PersistentCachingTerminologyService.java 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@piotrszul piotrszul self-assigned this Mar 29, 2023
Copy link
Member

@johngrimes johngrimes 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 your work on this @piotrszul!

I've added come comments, would you mind taking a look?

* @author Piotr Szul
*/
@Slf4j
public class ResourceHolder implements Closeable {
Copy link
Member

Choose a reason for hiding this comment

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

I think this class should be called something that is a bit more specific and communicates its purpose - perhaps CloseableResourceHolder?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think that 'Resource' implies an object, which lifecycle needs to me managed (in particular that needs to be closes).
This is based on the semantics of the try-with-resource Statement (see: https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html)
So I would leave it as is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed to ResourceCloser.

* @param <T> the type of the resource
* @return the resource
*/
protected <T extends Closeable> T registerResource(@Nonnull final T resource) {
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps this could be renamed to registerCloseableResource?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See above.

log.debug("Closing {} resources for: {}", resourcesToClose.size(), this);
synchronized (resourcesToClose) {
for (Closeable closeable : resourcesToClose) {
log.debug("Closing resource: {} in: {}", closeable, this);
Copy link
Member

Choose a reason for hiding this comment

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

Should I be seeing this logging if I use a Python script with something like the following?

spark = (
    SparkSession.builder
    .config("spark.jars", find_jar())
    .getOrCreate()
)

pc = PathlingContext.create(
        spark,
        terminology_server_url="https://r4.ontoserver.csiro.au/fhir",
        cache_override_expiry=2_628_000,
        cache_storage_type="disk",
        cache_storage_path=".local/tx-cache"
)

pc.spark.sparkContext.setLogLevel("DEBUG")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, at the end:

23/06/20 14:34:43 INFO ShutdownHookManager: Shutdown hook called
23/06/20 14:34:43 INFO ShutdownHookManager: Deleting directory /private/var/folders/x5/cw9kr5ld00g595qv0gg7lxrw00cjzw/T/spark-17e8a874-d7f2-44cb-bb94-d8f8b83df7c9
23/06/20 14:34:43 INFO ShutdownHookManager: Deleting directory /private/var/folders/x5/cw9kr5ld00g595qv0gg7lxrw00cjzw/T/spark-5c43a9fb-16b2-4554-b414-a79937f7c20e
23/06/20 14:34:43 INFO ShutdownHookManager: Deleting directory /private/var/folders/x5/cw9kr5ld00g595qv0gg7lxrw00cjzw/T/spark-17e8a874-d7f2-44cb-bb94-d8f8b83df7c9/pyspark-a21b3294-186f-45e2-af3f-02f5c0291829
23/06/20 14:34:43 DEBUG ResourceHolder: Closing 2 resources for: au.csiro.pathling.terminology.caching.InMemoryCachingTerminologyService@6aeae867
23/06/20 14:34:43 DEBUG ResourceHolder: Closing resource: org.apache.http.impl.client.InternalHttpClient@6487e431 in: au.csiro.pathling.terminology.caching.InMemoryCachingTerminologyService@6aeae867
23/06/20 14:34:43 DEBUG PoolingHttpClientConnectionManager: Connection manager is shutting down
23/06/20 14:34:43 DEBUG DefaultManagedHttpClientConnection: http-outgoing-0: Close connection
23/06/20 14:34:43 DEBUG PoolingHttpClientConnectionManager: Connection manager shut down
23/06/20 14:34:43 DEBUG ResourceHolder: Closing resource: DefaultCacheManager DefaultCacheManager in: au.csiro.pathling.terminology.caching.InMemoryCachingTerminologyService@6aeae867
23/06/20 14:34:43 DEBUG DefaultCacheManager: Stopping cache manager DefaultCacheManager
23/06/20 14:34:43 DEBUG CacheImpl: Stopping cache lookup on DefaultCacheManager
23/06/20 14:34:43 DEBUG CacheImpl: Stopping cache org.infinispan.CONFIG on DefaultCacheManager
23/06/20 14:34:43 DEBUG CacheImpl: Stopping cache validate-code on DefaultCacheManager
23/06/20 14:34:43 DEBUG CacheImpl: Stopping cache translate on DefaultCacheManager
23/06/20 14:34:43 DEBUG CacheImpl: Stopping cache subsumes on DefaultCacheManager
23/06/20 14:34:43 DEBUG DefaultCacheManager: Stopped cache manager DefaultCacheManager
23/06/20 14:34:43 DEBUG FileSystem: FileSystem.close() by method: org.apache.hadoop.fs.FilterFileSystem.close(FilterFileSystem.java:529)); Key: (szu004 (auth:SIMPLE))@file://; URI: file:///; Object Identity Hash: 597778cb
23/06/20 14:34:43 DEBUG FileSystem: FileSystem.close() by method: org.apache.hadoop.fs.RawLocalFileSystem.close(RawLocalFileSystem.java:759)); Key: null; URI: file:///; Object Identity Hash: 77576ebb
23/06/20 14:34:43 DEBUG ShutdownHookManager: Completed shutdown in 0.122 seconds; Timeouts: 0
23/06/20 14:34:43 DEBUG ShutdownHookManager: ShutdownHookManager completed shutdown.

@johngrimes johngrimes added the bug Something isn't working label May 3, 2023
@johngrimes johngrimes added this to the v6.2.0 milestone May 3, 2023
Base automatically changed from release/6.2.0 to main May 23, 2023 03:29
… the JVM shutdown hook.

Removed unnecessary debug logging.
@johngrimes johngrimes modified the milestones: v6.2.0, v6.2.2 Jun 26, 2023
@johngrimes johngrimes merged commit 062e8f2 into main Jun 26, 2023
32 checks passed
@johngrimes johngrimes deleted the issue/1283 branch June 26, 2023 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Repeated sessions using the same disk cache location can cause corruption
2 participants