You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2011/06/30 17:20:15 UTC
svn commit: r1141567 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/sql/catalog/
testing/org/apache/derbyTesting/functionTests/tests/lang/
Author: rhillegas
Date: Thu Jun 30 15:20:14 2011
New Revision: 1141567
URL: http://svn.apache.org/viewvc?rev=1141567&view=rev
Log:
DERBY-4437: Change default length of preallocated ranges for sequences and identities and make this default easy to configure.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceRange.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AutoIncrementTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceGeneratorTest.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceRange.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceRange.java?rev=1141567&r1=1141566&r2=1141567&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceRange.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceRange.java Thu Jun 30 15:20:14 2011
@@ -38,12 +38,10 @@ public class SequenceRange implemen
///////////////////////////////////////////////////////////////////////////////////
/**
- * Default number of values to pre-allocate. In the future, we may want to provide
- * something more sophisticated. For instance, we might want to make Derby tune
- * this number per sequence generator or give the user the power to override Derby's
- * decision.
+ * Default number of values to pre-allocate. This is the size of the preallocation range
+ * used by other databases. See DERBY-4437.
*/
- private static final int DEFAULT_PREALLOCATION_COUNT = 5;
+ private static final int DEFAULT_PREALLOCATION_COUNT = 20;
///////////////////////////////////////////////////////////////////////////////////
//
@@ -51,6 +49,8 @@ public class SequenceRange implemen
//
///////////////////////////////////////////////////////////////////////////////////
+ private int _rangeSize;
+
///////////////////////////////////////////////////////////////////////////////////
//
// CONSTRUCTOR
@@ -58,7 +58,17 @@ public class SequenceRange implemen
///////////////////////////////////////////////////////////////////////////////////
/** <p>0-arg constructore needed to satisfy the SequencePreallocator contract.</p> */
- public SequenceRange() {}
+ public SequenceRange()
+ {
+ this( DEFAULT_PREALLOCATION_COUNT );
+ }
+
+ public SequenceRange( int rangeSize )
+ {
+ if ( rangeSize <= 0 ) { rangeSize = DEFAULT_PREALLOCATION_COUNT; }
+
+ _rangeSize = rangeSize;
+ }
///////////////////////////////////////////////////////////////////////////////////
//
@@ -72,7 +82,7 @@ public class SequenceRange implemen
String sequenceName
)
{
- return DEFAULT_PREALLOCATION_COUNT;
+ return _rangeSize;
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java?rev=1141567&r1=1141566&r2=1141567&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java Thu Jun 30 15:20:14 2011
@@ -447,17 +447,36 @@ public abstract class SequenceUpdater im
if ( className == null ) { return new SequenceRange(); }
try {
+ // If the property value was a number rather than a class name, then
+ // use that as the default size for preallocated ranges.
+ if ( isNumber( className ) )
+ {
+ return new SequenceRange( Integer.parseInt( className ) );
+ }
+
return (SequencePreallocator) Class.forName( className ).newInstance();
}
catch (ClassNotFoundException e) { throw missingAllocator( propertyName, className, e ); }
catch (ClassCastException e) { throw missingAllocator( propertyName, className, e ); }
catch (InstantiationException e) { throw missingAllocator( propertyName, className, e ); }
catch (IllegalAccessException e) { throw missingAllocator( propertyName, className, e ); }
+ catch (NumberFormatException e) { throw missingAllocator( propertyName, className, e ); }
}
private StandardException missingAllocator( String propertyName, String className, Exception e )
{
return StandardException.newException( SQLState.LANG_UNKNOWN_SEQUENCE_PREALLOCATOR, e, propertyName, className );
}
+ private boolean isNumber( String text )
+ {
+ int length = text.length();
+
+ for ( int i = 0; i < length; i++ )
+ {
+ if ( !Character.isDigit( text.charAt( i ) ) ) { return false; }
+ }
+
+ return true;
+ }
/** Get the time we wait for a lock, in milliseconds--overridden by unit tests */
protected int getLockTimeout()
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java?rev=1141567&r1=1141566&r2=1141567&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java Thu Jun 30 15:20:14 2011
@@ -3006,7 +3006,7 @@ public final class AlterTableTest extend
"where c.referenceid = t.tableid and t.tablename='D3175'");
JDBC.assertUnorderedResultSet(rs, new String[][]{
{"X", "1", "VARCHAR(12)", null, null, null, null, "D3175", "T", "R"},
- {"ID", "2", "INTEGER NOT NULL", "GENERATED_BY_DEFAULT", "7", "1", "1", "D3175", "T", "R"}
+ {"ID", "2", "INTEGER NOT NULL", "GENERATED_BY_DEFAULT", "22", "1", "1", "D3175", "T", "R"}
});
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AutoIncrementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AutoIncrementTest.java?rev=1141567&r1=1141566&r2=1141567&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AutoIncrementTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AutoIncrementTest.java Thu Jun 30 15:20:14 2011
@@ -226,7 +226,7 @@ public class AutoIncrementTest extends B
String[][]expectedRows=new String[][]{{"0","0"},{"1","2"},{"2","4"},{"33","6"}};
JDBC.assertFullResultSet(rs,expectedRows);
rs = s.executeQuery("select COLUMNNAME, AUTOINCREMENTVALUE, AUTOINCREMENTSTART, AUTOINCREMENTINC from sys.syscolumns where COLUMNNAME = 'AIS'");
- expectedRows=new String[][]{{"AIS","10","0","2"}};
+ expectedRows=new String[][]{{"AIS","40","0","2"}};
JDBC.assertFullResultSet(rs,expectedRows);
}
@@ -383,7 +383,7 @@ public class AutoIncrementTest extends B
expectedRows=new String[][]{{"1","1"},{"2","2"},{"3","3"}};
JDBC.assertFullResultSet(rs,expectedRows);
rs=s.executeQuery("select b.tablename, a.autoincrementvalue, a.autoincrementstart, a.autoincrementinc from sys.syscolumns a, sys.systables b where a.referenceid=b.tableid and a.columnname ='S1' and b.tablename = 'TAB1'");
- expectedRows=new String[][]{{"TAB1","6","1","1"}};
+ expectedRows=new String[][]{{"TAB1","21","1","1"}};
JDBC.assertFullResultSet(rs,expectedRows);
s.executeUpdate("create table tab2 (lvl int, s1 bigint generated always as identity)");
s.executeUpdate("create trigger tab1_after2 after insert on tab3 referencing new as newrow for each row insert into tab2 (lvl) values 1,2,3");
@@ -944,7 +944,7 @@ public class AutoIncrementTest extends B
expectedRows=new String[][]{{"2","2"},{"2","9999"}};
JDBC.assertFullResultSet(rs,expectedRows);
rs=s.executeQuery("select COLUMNNAME, AUTOINCREMENTVALUE, AUTOINCREMENTSTART, AUTOINCREMENTINC from sys.syscolumns where COLUMNNAME = 'REC11'");
- expectedRows=new String[][]{{"REC11","12","2","2"}};
+ expectedRows=new String[][]{{"REC11","42","2","2"}};
JDBC.assertFullResultSet(rs,expectedRows);
assertStatementError("42837",s,"alter table restartt1 alter column c12 RESTART WITH 2");
assertStatementError("42X49",s,"alter table restartt1 alter column rec11 RESTART WITH 2.20");
@@ -979,7 +979,7 @@ public class AutoIncrementTest extends B
assertStatementError("23505",s,"insert into t1lock(c12) values(3)");
rs=s.executeQuery("select COLUMNNAME, AUTOINCREMENTVALUE, AUTOINCREMENTSTART, AUTOINCREMENTINC from sys.syscolumns where COLUMNNAME = 'LOCKC11'");
//Utilities.showResultSet(rs);
- expectedRows=new String[][]{{"LOCKC11","6","1","1"}};
+ expectedRows=new String[][]{{"LOCKC11","21","1","1"}};
JDBC.assertFullResultSet(rs,expectedRows);
rs=s.executeQuery("select * from t1lock");
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceGeneratorTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceGeneratorTest.java?rev=1141567&r1=1141566&r2=1141567&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceGeneratorTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SequenceGeneratorTest.java Thu Jun 30 15:20:14 2011
@@ -61,7 +61,7 @@ public class SequenceGeneratorTest exte
///////////////////////////////////////////////////////////////////////////////////
// number of pre-allocated values in a sequence generator
- private static final long ALLOCATION_COUNT = 5L;
+ private static final long ALLOCATION_COUNT = 20L;
private static final int TWEAKED_ALLOCATION_COUNT = 7;
private static final String TEST_DBO = "TEST_DBO";
@@ -190,12 +190,16 @@ public class SequenceGeneratorTest exte
assertEquals( -2147483648L, updater.getValueOnDisk().longValue() );
- vetBumping( updater, -2147483648L, -2147483643L );
- vetBumping( updater, -2147483647L, -2147483643L );
- vetBumping( updater, -2147483646L, -2147483643L );
- vetBumping( updater, -2147483645L, -2147483643L );
- vetBumping( updater, -2147483644L, -2147483643L );
- vetBumping( updater, -2147483643L, -2147483638L );
+ long initialValue = (long) Integer.MIN_VALUE;
+ long expectedValueOnDisk = initialValue + ALLOCATION_COUNT;
+
+ for ( long i = 0; i < ALLOCATION_COUNT; i++ )
+ {
+ vetBumping( updater, initialValue + i, expectedValueOnDisk );
+ }
+ expectedValueOnDisk += ALLOCATION_COUNT;
+
+ vetBumping( updater, initialValue + ALLOCATION_COUNT, expectedValueOnDisk );
vetBoundaries( Short.MAX_VALUE, Short.MIN_VALUE );
vetBoundaries( Integer.MAX_VALUE, Integer.MIN_VALUE );
@@ -338,7 +342,7 @@ public class SequenceGeneratorTest exte
long actualValueOnDisk = updater.getValueOnDisk().longValue();
println( "Expected value = " + expectedValue + " vs actual value = " + actualValue );
- println( " Expected value on disk = " + expectedValue + " vs actual value on disk = " + actualValueOnDisk );
+ println( " Expected value on disk = " + expectedValueOnDisk + " vs actual value on disk = " + actualValueOnDisk );
assertEquals( expectedValue, actualValue );
assertEquals( expectedValueOnDisk, actualValueOnDisk );
@@ -584,6 +588,72 @@ public class SequenceGeneratorTest exte
);
}
+ /**
+ * <p>
+ * Test overriding the default length of sequence/identity ranges.
+ * </p>
+ */
+ public void test_09_defaultRangeSize() throws Exception
+ {
+ Connection conn = openUserConnection( TEST_DBO );
+ long number;
+
+ goodStatement( conn, "create sequence seq_09_01\n" );
+ number = 30L;
+ goodStatement
+ (
+ conn,
+ "call syscs_util.syscs_set_database_property( 'derby.language.sequence.preallocator', '" + number + "')"
+ );
+ vetBumping( conn, TEST_DBO, "SEQ_09_01", Integer.MIN_VALUE, Integer.MIN_VALUE + number );
+
+ // 0 results in the usual default
+ goodStatement( conn, "create sequence seq_09_02\n" );
+ number = 0L;
+ goodStatement
+ (
+ conn,
+ "call syscs_util.syscs_set_database_property( 'derby.language.sequence.preallocator', '" + number + "')"
+ );
+ vetBumping( conn, TEST_DBO, "SEQ_09_02", Integer.MIN_VALUE, Integer.MIN_VALUE + ALLOCATION_COUNT );
+
+ // negative numbers result in Missing Allocator exception
+ goodStatement( conn, "create sequence seq_09_03\n" );
+ number = -1L;
+ goodStatement
+ (
+ conn,
+ "call syscs_util.syscs_set_database_property( 'derby.language.sequence.preallocator', '" + number + "')"
+ );
+ expectExecutionError( conn, MISSING_ALLOCATOR, "values ( next value for seq_09_03 )" );
+
+ // If the value doesn't fit in an int, we also get a Missing Allocator exception
+ goodStatement( conn, "create sequence seq_09_04\n" );
+ number = Long.MAX_VALUE - 1L;
+ goodStatement
+ (
+ conn,
+ "call syscs_util.syscs_set_database_property( 'derby.language.sequence.preallocator', '" + number + "')"
+ );
+ expectExecutionError( conn, MISSING_ALLOCATOR, "values ( next value for seq_09_04 )" );
+
+ // out of range values will stifle preallocation
+ goodStatement( conn, "create sequence seq_09_05 as smallint\n" );
+ number = ((long) 3 * Short.MAX_VALUE);
+ goodStatement
+ (
+ conn,
+ "call syscs_util.syscs_set_database_property( 'derby.language.sequence.preallocator', '" + number + "')"
+ );
+ vetBumping( conn, TEST_DBO, "SEQ_09_05", Short.MIN_VALUE, Short.MIN_VALUE + 1 );
+
+ goodStatement
+ (
+ conn,
+ "call syscs_util.syscs_set_database_property( 'derby.language.sequence.preallocator', null )"
+ );
+ }
+
///////////////////////////////////////////////////////////////////////////////////
//
// MINIONS