[
https://issues.apache.org/jira/browse/OAK-8917?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17045679#comment-17045679
]
Olivier Jolit commented on OAK-8917:
------------------------------------
Hello,
I did indeed reproduce without my custom security provider, I reproduce with
the {{OpenSecurityProvider}}.
I actually wrote a main that reproduces this behavior quite simply. I give it
below with the [^effective-pom.xml]and the [^output] attached.
{code:java}
import org.apache.jackrabbit.api.JackrabbitRepository;
import org.apache.jackrabbit.oak.Oak;
import org.apache.jackrabbit.oak.jcr.Jcr;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDataSourceFactory;
import
org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentNodeStoreBuilder;
import org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler;
import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
import org.apache.jackrabbit.oak.spi.state.NodeStore;
import javax.jcr.Repository;
public class CreateRepositoryConflicts {
public static final String host = "xxx";
public static final String db = "xxx";
public static final String password = "xxx";
public static final String port = "xxx";
private static Repository repository;
private static NodeStore nodeStore;
public static void main(String[] args) {
System.out.println("Creating OAK repository first time");
createRepository();
shutdown();
System.out.println("Creating OAK repository second time");
createRepository();
shutdown();
}
public static void createRepository() {
String schema = "oak";
String user = "oak";
String sqlDriverClassName = "org.postgresql.Driver";
SecurityProvider openSecurityProvider = new OpenSecurityProvider();
nodeStore = RDBDocumentNodeStoreBuilder.newRDBDocumentNodeStoreBuilder()
.setRDBConnection(RDBDataSourceFactory.forJdbcUrl("jdbc:postgresql://" + host +
":" + port + "/" + db + "?currentSchema= " + schema, user, password,
sqlDriverClassName)).build();
repository = new Jcr(new
Oak(nodeStore)).with(openSecurityProvider).createRepository();
}
public static void shutdown() {
if (repository instanceof JackrabbitRepository) {
System.out.println("Shutting down JCR...");
try {
((JackrabbitRepository) repository).shutdown();
} catch (Throwable e) {
System.out.println("Could not close JCR repo: " +
e.getMessage());
e.printStackTrace();
}
}
if (nodeStore instanceof DocumentNodeStore) {
System.out.println("Disposing NodeStore...");
try {
((DocumentNodeStore) nodeStore).dispose();
} catch (Throwable e) {
System.out.println("Could not dispose NodeStore: " +
e.getMessage());
e.printStackTrace();
}
}
}
}
{code}
> Thousands ConflitException on .createRepository()
> -------------------------------------------------
>
> Key: OAK-8917
> URL: https://issues.apache.org/jira/browse/OAK-8917
> Project: Jackrabbit Oak
> Issue Type: Bug
> Components: core
> Affects Versions: 1.24.0
> Reporter: Olivier Jolit
> Priority: Minor
> Attachments: effective-pom.xml, output
>
>
> I use OAK in my Spring Boot application to store user content (bookmarks).
> Users will write to OAK via REST calls.
> So I create a repository (in a Spring Bean) on my application startup with:
> {code:java}
> public OakBookmarkService() {
> RDBDocumentNodeStoreBuilder.newRDBDocumentNodeStoreBuilder()
>
> .setRDBConnection(RDBDataSourceFactory.forJdbcUrl("jdbc:postgresql://" + host
> + ":" + port + "/" + db + "?currentSchema= " + schema, user, password,
> sqlDriverClassName)).build()
> SecurityProvider securityProvider = new
> BookmarksSecurityProvider(rolesProvider);
> ThreeWayConflictHandler threeWayConflictHandler = new
> BookmarkConflictHandler();
> repository = new Jcr(new
> Oak(store)).with(securityProvider).with(threeWayConflictHandler).createRepository();
>
> ...
> }{code}
> The issue I have is that this creation of the repository throws thousands of
> ConflitExceptions like:
> {code:java}
> The node 1:/jcr:system already existed in revision
> r170631ac223-0-1 (older than base r17063a941e2-0-1), commit revision:
> r17063a95314-0-1 {code}
> Which prevent my application from starting.
> Deleting all the tables in my PostgreSQL database between each startup of my
> server fixes this issue but is obviously not expected. So it seems to me that
> OAK tries to recreate the default nodes in the database even though they
> already exist.
> I see in the documentation
> ([https://jackrabbit.apache.org/oak/docs/construct.html]) that I need to
> logout and dispose of the node store after each use. Do I have to do this
> when the server stops ? How to ensure this is done even when the server
> crashes in this case ?
> Or should I create the node store at the beginning of each REST call and
> dispose of it at the end every time ? For now I only create a session and
> close it for each call and am assuming creating the store each time is too
> expensive.
> Also, my conflict handler (that always returns Resolution.OURS for now) does
> not seem to be called in this scenario, which surprises me.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)