Uploaded image for project: 'Phoenix'
  1. Phoenix
  2. PHOENIX-2149

MAX Value of Sequences not honored when closing Connection between calls to NEXT VALUE FOR

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.4.0
    • Fix Version/s: 4.5.1
    • Component/s: None
    • Labels:

      Description

      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.

          @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);
              }
          }
      

        Attachments

        1. PHOENIX-2149.patch
          4 kB
          Jan Fernando
        2. PHOENIX-2149-v2.patch
          4 kB
          Thomas D'Silva

          Activity

            People

            • Assignee:
              jfernando_sfdc Jan Fernando
              Reporter:
              jfernando_sfdc Jan Fernando
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: