apache / apache/pekko-projection
Managing Slick DB resources
- Dominant language
- Scala
- Stars
- 27
- Forks
- 16
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 15
Description
### Discussed in https://github.com/apache/pekko-projection/discussions/168
Originally posted by **pjfanning** June 13, 2024
When you call [databaseConfig.db](https://github.com/slick/slick/blob/b878d45556fb6b4799e62a5d3c08364def51a89f/slick/src/main/scala/slick/basic/DatabaseConfig.scala#L15-L18), you are expected to close that db instance.
pekko-projection-slick has never bothered to do this.
It appears that pekko-projection-slick users create their own databaseConfig and it is left to them (at the moment) to know about and implement the `databaseConfig.db.close()` call. Have a look at [SlickProjectionSpec](https://github.com/apache/pekko-projection/blob/bb4e88a18d425c2ff66449fc323a87f36217f21b/slick/src/test/scala/org/apache/pekko/projection/slick/SlickProjectionSpec.scala) to see how this test spec creates a databaseConfig and then in `afterAll` it calls `databaseConfig.db.close()`
If we were to take responsibility for closing the databaseConfig.db instances, there are some problems:
* there is no lifecycle that we can rely on, we are probably left with adding a shutdown hook or something like that
* There are a lot of functions in [SlickProjection](https://github.com/apache/pekko-projection/blob/bb4e88a18d425c2ff66449fc323a87f36217f21b/slick/src/main/scala/org/apache/pekko/projection/slick/SlickProjection.scala) that call `createOffsetStore` and this `createOffsetStore` calls `databaseConfig.db` - potentially create a new db instance that needs managing. If you call `databaseConfig.db` more than once on the same databaseConfig instance, you should get the same db instance (they are lazily created and reused).
This is my opinion - I think we should not change anything and just document that users need to look after their own databaseConfig lifecycle.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with SlickProjectionSpec and SlickProjection.scala, then review the linked Slick DatabaseConfig.db lifecycle guidance. Document that pekko-projection-slick users are responsible for closing their own databaseConfig.db instance, including the relevant lifecycle consideration. Done means the responsibility and cleanup expectation are clearly documented for users.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- database
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100