[ 
https://issues.apache.org/jira/browse/CASSANDRA-18264?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17689680#comment-17689680
 ] 

Stefan Miklosovic edited comment on CASSANDRA-18264 at 2/16/23 10:30 AM:
-------------------------------------------------------------------------

[~brandon.williams] Disregard my previous comment please. The readme file in 
triggers' example is a little bit misleading. 

For reference, whole example works like this:

When ant jar is invoked, it will build the jar with AuditTrigger class and it 
will include AuditTrigger.properties from conf directory into that JAR so 
triggers JAR contains that conf file in it.

When I build Cassandra with "ant artifacts", when this trigger jar is put into 
"conf/triggers" and instructions in readme are followed, _this works_. Placing 
that jar anywhere else (like lib/triggers or "triggers" in CASSANDRA_HOME) will 
not work. It truly expects it to be in conf/triggers as mentioned in 
"jvm-server.options". So this is good.

However, when same is done by trying to load this from IDEA simply by starting 
Cassandra from there, this will not work unless I specify 
"-Dcassandra.triggers_dir=/path/to/project/conf/triggers".

I fixed readme for the example as well, rewrote it to asciidoc and fixed what 
should not be there. I also added "install" target which will copy that jar to 
"conf/triggers" and it will be removed from there on "ant clean".

On startup, triggers jar is copied to /tmp/lib/cassandra-"number".jar (number 
being simply "0") and trigger is loaded by CustomClassLoader from there. The 
example expects to read "AuditTrigger.properties" and it reads it from that 
jar. Having properties anywhere but that jar is not helpful.

I would like to ship all these changes at once, when it comes to example, with 
the fix of jar loading itself.

I think that we should treat these examples as subprojects and we should 
include them into the build. The fact that the example was not compiling 
because the code was not updated is supporting this idea. But that might be 
done separately.


was (Author: smiklosovic):
[~brandon.williams] Disregard my previous comment please. The readme file in 
triggers' example is a little bit misleading. 

For reference, whole example works like this:

When ant jar is invoked, it will build the jar with AuditTrigger class and it 
will include AuditTrigger.properties from conf directory into that JAR so 
triggers JAR contains that conf file in it.

I think that we should treat these examples as subprojects and we should 
include them into the build. The fact that the example was not compiling 
because the code was not updated is supporting this idea. But that might be 
done separately.

When I build Cassandra with "ant artifacts", when this trigger jar is put into 
"conf/triggers" and instructions in readme are followed, _this works_. Placing 
that jar anywhere else (like lib/triggers or "triggers" in CASSANDRA_HOME) will 
not work. It truly expects it to be in conf/triggers as mentioned in 
"jvm-server.options". So this is good.

However, when same is done by trying to load this from IDEA simply by starting 
Cassandra from there, this will not work unless I specify 
"-Dcassandra.triggers_dir=/path/to/project/conf/triggers".

I fixed readme for the example as well, rewrote it to asciidoc and fixed what 
should not be there. I also added "install" target which will copy that jar to 
"conf/triggers" and it will be removed from there on "ant clean".

On startup, triggers jar is copied to /tmp/lib/cassandra-{number}.jar (number 
being simply "0") and trigger is loaded by CustomClassLoader from there. The 
example expects to read "AuditTrigger.properties" and it reads it from that 
jar. Having properties anywhere but that jar is not helpful.

I would like to ship all these changes at once, when it comes to example, with 
the fix of jar loading itself.

> CustomClassLoader does not load jars rendering triggers from JARs broken
> ------------------------------------------------------------------------
>
>                 Key: CASSANDRA-18264
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-18264
>             Project: Cassandra
>          Issue Type: Bug
>          Components: Legacy/Core
>            Reporter: Stefan Miklosovic
>            Assignee: Stefan Miklosovic
>            Priority: Normal
>             Fix For: 4.1.x, 4.x
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> A user had to downgrade to 4.0.7 from 4.1.0 because they hit a problem with 
> CustomClassLoader for triggers. 
> User says that in Apache Cassandra 4.1.0 the trigger mechanism does not work, 
> not their trigger, but the possibility of loading any trigger in Cassandra.
> In the Cassandra 4.1.0 version of CustomClassLoader 
> (https://github.com/apache/cassandra/blob/cassandra-4.1/src/java/org/apache/cassandra/triggers/CustomClassLoader.java)
>  the code is changed in such a way that when copying the JAR Cassandra uses 
> java.nio.file.Files, while earlier versions (cassandra 4.0.X or 3.X) used 
> Guava com.google.common.io.Files to copy the JAR file.
> The difference between one and the other is that Guava by default overwrites 
> the file if it already exists and user has permissions to do so, and in Java 
> by default it does not overwrite.
> Copying is done here (1) from inputJar to out. However, the problem is that 
> we are getting temporary file from here (2) and the implementation loops 
> unless it succeeds to create an empty file. (3) - But that fails to copy the 
> file to out because copying does not work when the target file already exists.
> (1) 
> https://github.com/apache/cassandra/blob/cassandra-4.1/src/java/org/apache/cassandra/triggers/CustomClassLoader.java#L86
> (2) 
> https://github.com/apache/cassandra/blob/cassandra-4.1/src/java/org/apache/cassandra/triggers/CustomClassLoader.java#L81
> (3) 
> https://github.com/apache/cassandra/blob/cassandra-4.1/src/java/org/apache/cassandra/io/util/FileUtils.java#L152



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to