Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-27568

Skip repository initialization if MongoDB database is already set up

    XMLWordPrintable

    Details

    • Release Notes Summary:
      The MongoDB indexes are only creating on first startup/database initialization.
    • Backlog priority:
      800
    • Sprint:
      nxplatform 11.1.12
    • Story Points:
      2

      Description

      If one changes an existing index in MongoDB database, the startup will fail with the following error

      ERROR [localhost-startStop-1] [org.nuxeo.runtime.model.impl.RegistrationInfoImpl] Component service:org.nuxeo.ecm.core.repository.RepositoryServiceComponent notification of application started failed: Command failed with error 85: 'Index with name: ecm:id_1 already exists with different options' on server aca-test-shard-00-02-achgr.azure.mongodb.net:27017. The full response is { "ok" : 0.0, "errmsg" : "Index with name: ecm:id_1 already exists with different options", "code" : 85, "codeName" : "IndexOptionsConflict" }
      com.mongodb.MongoCommandException: Command failed with error 85: 'Index with name: ecm:id_1 already exists with different options' on server aca-test-shard-00-02-achgr.azure.mongodb.net:27017. The full response is { "ok" : 0.0, "errmsg" : "Index with name: ecm:id_1 already exists with different options", "code" : 85, "codeName" : "IndexOptionsConflict" }
      	at com.mongodb.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:115)
      	at com.mongodb.connection.CommandProtocol.execute(CommandProtocol.java:114)
      	at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:168)
      	at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:289)
      	at com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:176)
      	at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:216)
      	at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:199)
      	at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:171)
      	at com.mongodb.operation.CreateIndexesOperation$1.call(CreateIndexesOperation.java:117)
      	at com.mongodb.operation.CreateIndexesOperation$1.call(CreateIndexesOperation.java:112)
      	at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:232)
      	at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:223)
      	at com.mongodb.operation.CreateIndexesOperation.execute(CreateIndexesOperation.java:112)
      	at com.mongodb.operation.CreateIndexesOperation.execute(CreateIndexesOperation.java:67)
      	at com.mongodb.Mongo.execute(Mongo.java:827)
      	at com.mongodb.Mongo$2.execute(Mongo.java:810)
      	at com.mongodb.DBCollection.createIndex(DBCollection.java:1541)
      	at com.mongodb.DBCollection.createIndex(DBCollection.java:1527)
      	at org.nuxeo.ecm.core.storage.mongodb.MongoDBRepository.initRepository(MongoDBRepository.java:558)
      	at org.nuxeo.ecm.core.storage.mongodb.MongoDBRepository.<init>(MongoDBRepository.java:199)
      	at org.nuxeo.ecm.core.storage.mongodb.MongoDBRepositoryFactory.call(MongoDBRepositoryFactory.java:37)
      	at org.nuxeo.ecm.core.storage.dbs.DBSCachingRepositoryFactory.call(DBSCachingRepositoryFactory.java:39)
      	at org.nuxeo.ecm.core.repository.RepositoryService.doGetRepository(RepositoryService.java:169)
      	at org.nuxeo.ecm.core.repository.RepositoryService.getSession(RepositoryService.java:208)
      	at org.nuxeo.ecm.core.api.local.LocalSession.createSession(LocalSession.java:127)
      	at org.nuxeo.ecm.core.api.local.LocalSession.<init>(LocalSession.java:84)
      	at org.nuxeo.ecm.core.api.CoreSessionServiceImpl.createCoreSession(CoreSessionServiceImpl.java:43)
      	at org.nuxeo.ecm.core.api.CoreInstance.openCoreSession(CoreInstance.java:171)
      	at org.nuxeo.ecm.core.api.CoreInstance.openCoreSession(CoreInstance.java:71)
      	at org.nuxeo.ecm.core.api.UnrestrictedSessionRunner.runUnrestricted(UnrestrictedSessionRunner.java:129)
      	at org.nuxeo.ecm.core.repository.RepositoryService.openRepository(RepositoryService.java:127)
      	at org.nuxeo.ecm.core.repository.RepositoryService.initRepositories(RepositoryService.java:98)
      	at org.nuxeo.runtime.transaction.TransactionHelper.lambda$runInTransaction$2(TransactionHelper.java:539)
      	at org.nuxeo.runtime.transaction.TransactionHelper.runInTransaction(TransactionHelper.java:559)
      	at org.nuxeo.runtime.transaction.TransactionHelper.runInTransaction(TransactionHelper.java:539)
      	at org.nuxeo.ecm.core.repository.RepositoryService.applicationStarted(RepositoryService.java:87)
      	at org.nuxeo.runtime.model.impl.RegistrationInfoImpl.notifyApplicationStarted(RegistrationInfoImpl.java:332) 

      It's related to MongoDBRepository#initRepository which recreates the indexes at each startup. If an existing index is of a different kind (simple index VS unique index for example), the call to the "createIndex" method will throw an exception.

      The problem can easily be worked around by detecting that the database was already initialized. The code below could be put at the beginning of the method instead of calling it after the indexes creation.

              // check root presence
              if (coll.count(Filters.eq(idKey, getRootId())) > 0) {
                  return;
              }
      

      —> we will move index creation code so that it's executed only once, at initial repository creation time

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 hour
                  1h