[ 
https://issues.apache.org/jira/browse/KNOX-2738?focusedWorklogId=762183&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-762183
 ]

ASF GitHub Bot logged work on KNOX-2738:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 26/Apr/22 08:59
            Start Date: 26/Apr/22 08:59
    Worklog Time Spent: 10m 
      Work Description: zeroflag opened a new pull request, #567:
URL: https://github.com/apache/knox/pull/567

   ## What changes were proposed in this pull request?
   
   Starting multiple knox instances can cause token state service 
initialization failures when they try to create the same database tables.
   
   ```
   ERROR knox.gateway (TokenStateServiceFactory.java:createService(63)) - Error 
while initiatalizing 
org.apache.knox.gateway.services.token.impl.JDBCTokenStateService: Error while 
initiating JDBCTokenStateService: org.postgresql.util.PSQLException: ERROR: 
relation "knox_tokens" already exists
   ```
   
   To fix this issue I added a `IF NOT EXISTS` clause to the create table 
statement. This is unfortunately not supported by Derby (which is only used for 
unit testing), so I replaced derby with hsql.
   
   ## How was this patch tested?
   
   I tested manually with both mysql and postgres.
   
   Postgres gateway-site config:
   
   ```xml
   
       <property>
           <name>gateway.service.tokenstate.impl</name>
           
<value>org.apache.knox.gateway.services.token.impl.JDBCTokenStateService</value>
       </property>
        <property>
           <name>gateway.database.type</name>
           <value>postgresql</value>
       </property>
       <property>
           <name>gateway.database.connection.url</name>
           
<value>jdbc:postgresql://localhost:5432/postgres?user=postgres</value>
       </property>
   ```
   
   ```bash
   $ docker run --name posttest -d -p 5432:5432 -e 
POSTGRES_HOST_AUTH_METHOD=trust postgres:alpine
   ```
   
   ```bash
      $ docker exec -it posttest psql -U postgres
   
   
      postgres=# select * from knox_tokens;
                  token_id               |  issue_time   |  expiration   | 
max_lifetime  
   
--------------------------------------+---------------+---------------+---------------
    ad4953c9-38dd-4214-8ce1-e3b873a81f13 | 1650961012152 | 1650964612097 | 
1651565812152
    d37f744c-ef5b-4086-a9b7-6c1c0640e596 | 1650961013088 | 1650964613065 | 
1651565813088
    058b4e5c-642c-42fc-9e5a-9d23a56256d5 | 1650961026745 | 1650964626709 | 
1651565826745
   (3 rows)
   ```
   
   MySql gateway-site config:
   
   ```xml
       <property>
           <name>gateway.service.tokenstate.impl</name>
           
<value>org.apache.knox.gateway.services.token.impl.JDBCTokenStateService</value>
       </property>
        <property>
           <name>gateway.database.type</name>
           <value>mysql</value>
       </property>
        <property>
           <name>gateway.database.name</name>
           <value>mysql</value>
       </property>
        <property>
           <name>gateway.database.host</name>
           <value>localhost</value>
       </property>
        <property>
           <name>gateway.database.port</name>
           <value>3306</value>
       </property>
   ```
   
   ```bash
   ./bin/knoxcli.sh create-alias gateway_database_user --value root
   ./bin/knoxcli.sh create-alias gateway_database_password  --value password
   
   $ docker exec -it mysql1 mysql -u root -p
   ```
   
   




Issue Time Tracking
-------------------

            Worklog Id:     (was: 762183)
    Remaining Estimate: 0h
            Time Spent: 10m

> On Fresh install JDBCTokenStateService initiation failed
> --------------------------------------------------------
>
>                 Key: KNOX-2738
>                 URL: https://issues.apache.org/jira/browse/KNOX-2738
>             Project: Apache Knox
>          Issue Type: Bug
>            Reporter: Attila Magyar
>            Assignee: Attila Magyar
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> Knox intermittently failed to start due to a race condition between multiple 
> knox instances when creating database tables.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to