Uploaded image for project: 'Ranger'
  1. Ranger
  2. RANGER-3576

service creation is failing intermittently due to DB unique key constraint violation

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.0.0, 2.1.0, 3.0.0, 2.2.0, 2.3.0
    • 3.0.0, 2.3.0
    • Ranger
    • None

    Description

      Parallel service creation with the same users in the service config or default policies may fail with following error. 

      Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "x_user_uk_user_name"
        Detail: Key (user_name)=(rangerlookup) already exists.
          at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2532)
          at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2267)
          at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:312)
          at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:448)
          at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:369)
          at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:153)
          at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:119)
          at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:410)
          at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:898)
          ... 144 more
      2022-01-04 20:15:45,422 ERROR org.apache.ranger.biz.XUserMgr: Error creating user: rangerlookup
      javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.7.v20200504-69f2c2b80d): org.eclipse.persistence.exceptions.DatabaseException
      Internal Exception: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "x_user_uk_user_name"
        Detail: Key (user_name)=(rangerlookup) already exists.
      Error Code: 0
      Call: INSERT INTO x_user (ID, ADDED_BY_ID, CREATE_TIME, CRED_STORE_ID, DESCR, IS_VISIBLE, USER_NAME, OTHER_ATTRIBUTES, STATUS, UPDATE_TIME, UPD_BY_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
          bind => [11 parameters bound]
          at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:980)
          at jdk.internal.reflect.GeneratedMethodAccessor91.invoke(Unknown Source)
          at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.base/java.lang.reflect.Method.invoke(Method.java:566)
          at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:301)
          at com.sun.proxy.$Proxy26.flush(Unknown Source)
          at org.apache.ranger.common.db.BaseDao.create(BaseDao.java:90)
          at org.apache.ranger.service.AbstractBaseResourceService.createResource(AbstractBaseResourceService.java:258)
          at org.apache.ranger.biz.XUserMgr.createServiceConfigUser(XUserMgr.java:2535)
          at org.apache.ranger.biz.XUserMgr$$FastClassBySpringCGLIB$$57c6d473.invoke(<generated>)
          at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
          at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:737)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
          at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
          at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:283)
          at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
          at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:672)
          at org.apache.ranger.biz.XUserMgr$$EnhancerBySpringCGLIB$$886cf35.createServiceConfigUser(<generated>)
          at org.apache.ranger.biz.ServiceDBStore.createDefaultPolicyUsersAndGroups(ServiceDBStore.java:3321)
          at org.apache.ranger.biz.ServiceDBStore.populateDefaultPolicies(ServiceDBStore.java:3236)
          at org.apache.ranger.biz.ServiceDBStore.createDefaultPolicies(ServiceDBStore.java:3139)
          at org.apache.ranger.biz.ServiceDBStore.createService(ServiceDBStore.java:1545)
          at org.apache.ranger.rest.ServiceREST.createService(ServiceREST.java:767) 

      Note: Issue is intermittent and difficult to reproduce manually.

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            pradeep Pradeep Agrawal
            pradeep Pradeep Agrawal
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment