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

Samarth Jain commented on PHOENIX-2149:
---------------------------------------

[~tdsilva] - was this committed to 4.x branches too? If yes, then hopefully 
this fix was part of our 4.5.1 patch release too. Can you confirm?

> 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: Jan Fernando
>             Fix For: 4.5.1
>
>         Attachments: PHOENIX-2149-v2.patch, PHOENIX-2149.patch
>
>
> 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)

Reply via email to