You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@phoenix.apache.org by "Jan Fernando (JIRA)" <ji...@apache.org> on 2015/07/26 17:43:04 UTC

[jira] [Commented] (PHOENIX-2149) MAX Value of Sequences not honored when closing Connection between calls to NEXT VALUE FOR

    [ https://issues.apache.org/jira/browse/PHOENIX-2149?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14641996#comment-14641996 ] 

Jan Fernando commented on PHOENIX-2149:
---------------------------------------

I think the bug is caused by the fact we always set the LIMIT_REACHED_FLAG to false when return sequences and therefore clobber the value if it was set to true on the last allocation.

Here's the offending snippet from Sequence.newReturn()

{code}
        familyMap.put(PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, Arrays.<Cell>asList(
        		(Cell)KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.CURRENT_VALUE_BYTES, value.timestamp, PLong.INSTANCE.toBytes(value.currentValue))
        		// set LIMIT_REACHED flag to false since we are returning unused sequence values
        		,(Cell)KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.LIMIT_REACHED_FLAG_BYTES, value.timestamp, PDataType.FALSE_BYTES)
                ));
{code}

> MAX Value of Sequences not honored when closing Connection between calls to NEXT VALUE FOR
> ------------------------------------------------------------------------------------------
>
>                 Key: PHOENIX-2149
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-2149
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 4.4.0
>            Reporter: Jan Fernando
>            Assignee: Thomas D'Silva
>
> There appears to be an issue be related to closing connections between calls to NEXT VALUE FOR that causes the MAX sequence value to be ignored. I have found scenarios when I am allocating sequences near the MAX whereby the MAX is not honored and value greater than the max are returned by NEXT VALUE FOR.
> It appears to be related to the logic to return all sequences on connection close. It looks like if you close the connection between each invocation when you hit the max value instead of the expected error being thrown sequence values continue to be doled out. It looks like for some reason the limit_reached_flag is not being set correctly on the SYSTEM.SEQUENCE table for the sequence in this case.
> I added the test below to SequenceBulkAllocationIT that repros the issue.
> If I either a) remove the nextConnection() call that keeps recycling connections in the test below or b) comment our the code in PhoenixConnection.close() that calls services.removeConnection() the test below starts to pass.
> I wasn't able to repro in Squirrel because I guess it doesn't recycle connections.
> {code}
>     @Test
>     public void testNextValuesForSequenceClosingConnections() throws Exception {
>         final SequenceProperties props =
>                 new SequenceProperties.Builder().incrementBy(1).startsWith(4990).cacheSize(10).minValue(4990).maxValue(5000)
>                         .numAllocated(4989).build();
>         
>         // Create Sequence
>         nextConnection();
>         createSequenceWithMinMax(props);
>         nextConnection();
>         
>         // Try and get next value
>         try {
>             long val = 0L;
>             for (int i = 0; i <= 11; i++) {
>                 ResultSet rs = conn.createStatement().executeQuery(String.format(SELECT_NEXT_VALUE_SQL, "bulkalloc.alpha"));
>                 rs.next();
>                 val = rs.getLong(1);
>                 nextConnection();
>             }
>             fail("Expect to fail as this value is greater than seq max " + val);
>         } catch (SQLException e) {
>             assertEquals(SQLExceptionCode.SEQUENCE_VAL_REACHED_MAX_VALUE.getErrorCode(),
>                 e.getErrorCode());
>             assertTrue(e.getNextException() == null);
>         }
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)