瀏覽代碼

allow db index creation bypass

Jason Rivard 7 年之前
父節點
當前提交
ae3182b17a

+ 1 - 0
server/src/main/java/password/pwm/AppProperty.java

@@ -84,6 +84,7 @@ public enum AppProperty
     DB_CONNECTIONS_MAX                              ( "db.connections.max" ),
     DB_CONNECTIONS_MAX                              ( "db.connections.max" ),
     DB_CONNECTIONS_TIMEOUT_MS                       ( "db.connections.timeoutMs" ),
     DB_CONNECTIONS_TIMEOUT_MS                       ( "db.connections.timeoutMs" ),
     DB_CONNECTIONS_WATCHDOG_FREQUENCY_SECONDS       ( "db.connections.watchdogFrequencySeconds" ),
     DB_CONNECTIONS_WATCHDOG_FREQUENCY_SECONDS       ( "db.connections.watchdogFrequencySeconds" ),
+    DB_INIT_HALT_ON_INDEX_CREATE_ERROR              ( "db.init.haltOnIndexCreateError" ),
     DB_SCHEMA_KEY_LENGTH                            ( "db.schema.keyLength" ),
     DB_SCHEMA_KEY_LENGTH                            ( "db.schema.keyLength" ),
     DOWNLOAD_FILENAME_STATISTICS_CSV                ( "download.filename.statistics.csv" ),
     DOWNLOAD_FILENAME_STATISTICS_CSV                ( "download.filename.statistics.csv" ),
     DOWNLOAD_FILENAME_USER_REPORT_SUMMARY_CSV       ( "download.filename.reportSummary.csv" ),
     DOWNLOAD_FILENAME_USER_REPORT_SUMMARY_CSV       ( "download.filename.reportSummary.csv" ),

+ 5 - 1
server/src/main/java/password/pwm/util/db/DBConfiguration.java

@@ -53,6 +53,7 @@ public class DBConfiguration implements Serializable
     private final int maxConnections;
     private final int maxConnections;
     private final int connectionTimeout;
     private final int connectionTimeout;
     private final int keyColumnLength;
     private final int keyColumnLength;
+    private final boolean failOnIndexCreation;
 
 
     public byte[] getJdbcDriver( )
     public byte[] getJdbcDriver( )
     {
     {
@@ -94,6 +95,8 @@ public class DBConfiguration implements Serializable
 
 
         final int keyColumnLength = Integer.parseInt( config.readAppProperty( AppProperty.DB_SCHEMA_KEY_LENGTH ) );
         final int keyColumnLength = Integer.parseInt( config.readAppProperty( AppProperty.DB_SCHEMA_KEY_LENGTH ) );
 
 
+        final boolean haltOnIndexCreateError = Boolean.parseBoolean( config.readAppProperty( AppProperty.DB_INIT_HALT_ON_INDEX_CREATE_ERROR ) );
+
         return new DBConfiguration(
         return new DBConfiguration(
                 config.readSettingAsString( PwmSetting.DATABASE_CLASS ),
                 config.readSettingAsString( PwmSetting.DATABASE_CLASS ),
                 config.readSettingAsString( PwmSetting.DATABASE_URL ),
                 config.readSettingAsString( PwmSetting.DATABASE_URL ),
@@ -105,7 +108,8 @@ public class DBConfiguration implements Serializable
                 strategies,
                 strategies,
                 maxConnections,
                 maxConnections,
                 connectionTimeout,
                 connectionTimeout,
-                keyColumnLength
+                keyColumnLength,
+                haltOnIndexCreateError
         );
         );
     }
     }
 }
 }

+ 11 - 2
server/src/main/java/password/pwm/util/db/DatabaseUtil.java

@@ -42,6 +42,8 @@ class DatabaseUtil
 
 
     private static final PwmLogger LOGGER = PwmLogger.forClass( DatabaseUtil.class );
     private static final PwmLogger LOGGER = PwmLogger.forClass( DatabaseUtil.class );
 
 
+    private static final String INDEX_NAME_SUFFIX = "_IDX";
+
     private DatabaseUtil( )
     private DatabaseUtil( )
     {
     {
     }
     }
@@ -166,7 +168,7 @@ class DatabaseUtil
         }
         }
 
 
         {
         {
-            final String indexName = table.toString() + "_IDX";
+            final String indexName = table.toString() + INDEX_NAME_SUFFIX;
             final String sqlString = "CREATE index " + indexName
             final String sqlString = "CREATE index " + indexName
                     + " ON " + table.toString()
                     + " ON " + table.toString()
                     + " (" + DatabaseService.KEY_COLUMN + ")";
                     + " (" + DatabaseService.KEY_COLUMN + ")";
@@ -186,7 +188,14 @@ class DatabaseUtil
             {
             {
                 final String errorMsg = "error creating new index " + indexName + ": " + ex.getMessage();
                 final String errorMsg = "error creating new index " + indexName + ": " + ex.getMessage();
                 final ErrorInformation errorInformation = new ErrorInformation( PwmError.ERROR_DB_UNAVAILABLE, errorMsg );
                 final ErrorInformation errorInformation = new ErrorInformation( PwmError.ERROR_DB_UNAVAILABLE, errorMsg );
-                throw new DatabaseException( errorInformation );
+                if ( dbConfiguration.isFailOnIndexCreation() )
+                {
+                    throw new DatabaseException ( errorInformation );
+                }
+                else
+                {
+                    LOGGER.warn( errorInformation.toDebugStr() );
+                }
             }
             }
             finally
             finally
             {
             {

+ 1 - 0
server/src/main/resources/password/pwm/AppProperty.properties

@@ -75,6 +75,7 @@ db.jdbcLoadStrategy=AppPathFileLoader,Classpath
 db.connections.max=5
 db.connections.max=5
 db.connections.timeoutMs=30000
 db.connections.timeoutMs=30000
 db.connections.watchdogFrequencySeconds=30
 db.connections.watchdogFrequencySeconds=30
+db.init.haltOnIndexCreateError=false
 db.schema.keyLength=128
 db.schema.keyLength=128
 download.filename.statistics.csv=Statistics.csv
 download.filename.statistics.csv=Statistics.csv
 download.filename.reportSummary.csv=UserReportSummary.csv
 download.filename.reportSummary.csv=UserReportSummary.csv