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

Provides a default listener when no listener is set #3658

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tdwu
Copy link

@tdwu tdwu commented Oct 18, 2022

Provides a default listener when no listener is set. And add parameters to know the exact event source.
Sometimes we need to manage and monitor the database as a server and adjust the database parameters when it happens.

For example, deleteFilesOnDisconnect is automatically set to true on the target node when the cluster is created. This can easily trigger the deletion of data files when the database is closed, resulting in the loss of data files and tables. We can correct the parameters through the listener

@@ -1831,7 +1834,7 @@ public void setEventListenerClass(String className) {
if (cipher != null) {
url += ";CIPHER=" + cipher;
}
eventListener.init(url);
eventListener.init(url, this);
Copy link
Contributor

Choose a reason for hiding this comment

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

THREAD_SAFETY_VIOLATION: Read/Write race. Non-private method Database.setEventListenerClass(...) reads without synchronization from this.eventListener. Potentially races with write in method Database.removeSession(...).
Reporting because another access to the same memory occurs on a background thread, although this access may not.


ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

@sonatype-lift
Copy link
Contributor

sonatype-lift bot commented Oct 18, 2022

⚠️ 222 God Classes were detected by Lift in this project. Visit the Lift web console for more details.

@katzyn
Copy link
Contributor

katzyn commented Oct 18, 2022

Sorry, I think we cannot accept this pull request due to following reasons:

  1. org.h2.api.DatabaseEventListener is a part of API and we cannot change it in incompatible way, at least without a major release (3.0 or something like it).
  2. org.h2.engine.Database is not a part of API and applications should never do anything with it directly. It also may not be referenced from org.h2.api package.
  3. Presence of event listener changes behaviour of database even if it does nothing in its methods, so if someone will set a default, it can break some applications.

For example, deleteFilesOnDisconnect is automatically set to true on the target node when the cluster is created.

Clustering code in H2 was written a long time ago, and, unfortunately, it is implemented in a simple and naive way with significant design flaws. Here you're trying to work around some problem in it, but it will be far better to improve the implementation itself. Please, describe your problem in a new issue, maybe there are better options for its resolution.

@tdwu
Copy link
Author

tdwu commented Oct 19, 2022

Thank you very much for your quick feedback. I can understand what you said. It's necessary for the long-term development of the product and should not affect other people who are using it.

I have a point. On the server side, it provides EventListener class that also runs on the server, but cannot be configured by itself.
Instead, it is set when the client connects, which looks kind of strange. For most servers, it is necessary to configure by themself. (As a server, it is important you can handle somethings by yourself)
So, Can I recreate a PR to add a new feature only to set the default listener by the server? Or can you help implement this feature in your plan?

@grandinj
Copy link
Contributor

You could start the database server from code e.g.
https://h2database.com/html/tutorial.html#using_server
and provide settings like the database event listener there.

Or we could extend
Server.createTcpServe
to pass down an instance of a class that implements DatabaseEventListener.
Since the Server class is part of the public API.

Then your clients can just connect to the server using a URL without any parameters.

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.

None yet

3 participants