phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tdsi...@apache.org
Subject phoenix git commit: PHOENIX-2149 MAX Value of Sequences not honored when closing Connection between calls to NEXT VALUE FOR (Jan Fernando)
Date Mon, 27 Jul 2015 20:23:40 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.4-HBase-1.1 d24de0af4 -> 1b9c7ea9a


PHOENIX-2149 MAX Value of Sequences not honored when closing Connection between calls to NEXT
VALUE FOR (Jan Fernando)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/1b9c7ea9
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/1b9c7ea9
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/1b9c7ea9

Branch: refs/heads/4.4-HBase-1.1
Commit: 1b9c7ea9ababf0700e8e7081c399bdfe7ad926d5
Parents: d24de0a
Author: Thomas D'Silva <tdsilva@salesforce.com>
Authored: Mon Jul 27 13:15:17 2015 -0700
Committer: Thomas D'Silva <tdsilva@salesforce.com>
Committed: Mon Jul 27 13:23:35 2015 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/SequenceIT.java  | 33 ++++++++++++++++++++
 .../org/apache/phoenix/schema/Sequence.java     |  3 +-
 2 files changed, 34 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/1b9c7ea9/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java
index 6f2ec82..6e45a63 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java
@@ -54,6 +54,7 @@ import com.google.common.collect.Lists;
 
 public class SequenceIT extends BaseClientManagedTimeIT {
     private static final String NEXT_VAL_SQL = "SELECT NEXT VALUE FOR foo.bar FROM SYSTEM.\"SEQUENCE\"";
+    private static final String SELECT_NEXT_VALUE_SQL = "SELECT NEXT VALUE FOR %s FROM SYSTEM.\"SEQUENCE\"";
     private static final long BATCH_SIZE = 3;
    
     private Connection conn;
@@ -1147,6 +1148,38 @@ public class SequenceIT extends BaseClientManagedTimeIT {
         assertEquals(1, rs.getLong("metric_val"));
         assertFalse(rs.next());
     }
+    
+    @Test
+    /**
+     * Test to validate that the bug discovered in PHOENIX-2149 has been fixed. There was
an issue
+     * whereby, when closing connections and returning sequences we were not setting the
limit
+     * reached flag correctly and this was causing the max value to be ignored as the LIMIT_REACHED_FLAG
+     * value was being unset from true to false.
+     */
+    public void testNextValuesForSequenceClosingConnections() throws Exception {
+
+        // Create Sequence
+        nextConnection();
+        conn.createStatement().execute("CREATE SEQUENCE seqtest.closeconn START WITH 4990
MINVALUE 4990 MAXVALUE 5000 CACHE 10");
+        nextConnection();
+        
+        // Call NEXT VALUE FOR 1 time more than available values in the Sequence. We expected
the final time
+        // to throw an error as we will have reached the max value
+        try {
+            long val = 0L;
+            for (int i = 0; i <= 11; i++) {
+                ResultSet rs = conn.createStatement().executeQuery(String.format(SELECT_NEXT_VALUE_SQL,
"seqtest.closeconn"));
+                rs.next();
+                val = rs.getLong(1);
+                nextConnection();
+            }
+            fail("Expect to fail as we have arrived at the max sequence value " + val);
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.SEQUENCE_VAL_REACHED_MAX_VALUE.getErrorCode(),
+                e.getErrorCode());
+            assertTrue(e.getNextException() == null);
+        }
+    }
 
     private void insertEvent(long id, String userId, long val) throws SQLException {
         PreparedStatement stmt = conn.prepareStatement("UPSERT INTO events VALUES(?,?,?)");

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1b9c7ea9/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
index aeba58b..83e5363 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
@@ -227,8 +227,7 @@ public class Sequence {
         Map<byte[], List<Cell>> familyMap = append.getFamilyCellMap();
         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)
+        		(Cell)KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES,
PhoenixDatabaseMetaData.LIMIT_REACHED_FLAG_BYTES, value.timestamp, PBoolean.INSTANCE.toBytes(value.limitReached))
                 ));
         return append;
     }


Mime
View raw message