You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by vj...@apache.org on 2021/06/30 09:35:56 UTC

[phoenix] branch 4.x updated: PHOENIX-6500 Allow 4.16 client to connect to 5.1 server (#1257)

This is an automated email from the ASF dual-hosted git repository.

vjasani pushed a commit to branch 4.x
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/4.x by this push:
     new 6009a3b  PHOENIX-6500 Allow 4.16 client to connect to 5.1 server (#1257)
6009a3b is described below

commit 6009a3b6f8840dcd058792bde7979e1e805e787e
Author: Viraj Jasani <vj...@apache.org>
AuthorDate: Wed Jun 30 15:02:47 2021 +0530

    PHOENIX-6500 Allow 4.16 client to connect to 5.1 server (#1257)
    
    Signed-off-by: Andrew Purtell <ap...@apache.org>
---
 .../org/apache/phoenix/util/MajorMinorVersion.java | 63 ++++++++++++++++++++++
 .../java/org/apache/phoenix/util/MetaDataUtil.java | 23 ++++++--
 2 files changed, 82 insertions(+), 4 deletions(-)

diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/MajorMinorVersion.java b/phoenix-core/src/main/java/org/apache/phoenix/util/MajorMinorVersion.java
new file mode 100644
index 0000000..977ddf9
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/MajorMinorVersion.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.phoenix.util;
+
+/**
+ * A class representing major and minor Phoenix versions.
+ */
+class MajorMinorVersion {
+
+    private final int majorVersion;
+    private final int minorVersion;
+
+    public MajorMinorVersion(int majorVersion, int minorVersion) {
+        this.majorVersion = majorVersion;
+        this.minorVersion = minorVersion;
+    }
+
+    public int getMajorVersion() {
+        return majorVersion;
+    }
+
+    public int getMinorVersion() {
+        return minorVersion;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        MajorMinorVersion version = (MajorMinorVersion) o;
+        if (majorVersion != version.majorVersion) {
+            return false;
+        }
+        return minorVersion == version.minorVersion;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = majorVersion;
+        result = 31 * result + minorVersion;
+        return result;
+    }
+}
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
index d89114b..1eb6ef6 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
@@ -72,6 +72,7 @@ import org.apache.phoenix.schema.types.PInteger;
 import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.types.PSmallint;
 import org.apache.phoenix.schema.types.PUnsignedTinyint;
+import org.apache.phoenix.thirdparty.com.google.common.collect.ImmutableMap;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -101,6 +102,11 @@ public class MetaDataUtil {
 
     public static final byte[] DATA_TABLE_NAME_PROP_BYTES = Bytes.toBytes(DATA_TABLE_NAME_PROP_NAME);
 
+    private static final Map<MajorMinorVersion, MajorMinorVersion> ALLOWED_SERVER_CLIENT_MAJOR_VERSION =
+            ImmutableMap.of(
+                    new MajorMinorVersion(5, 1), new MajorMinorVersion(4, 16)
+            );
+
     // See PHOENIX-3955
     public static final List<String> SYNCED_DATA_TABLE_AND_INDEX_COL_FAM_PROPERTIES = ImmutableList.of(
             HColumnDescriptor.TTL,
@@ -177,13 +183,22 @@ public class MetaDataUtil {
             compatibility.setCompatible(false);
             return compatibility;
         } else if (VersionUtil.encodeMaxMinorVersion(clientMajorVersion) < serverVersion) { // Client major version must at least be up to server major version
-            compatibility.setErrorCode(SQLExceptionCode.INCOMPATIBLE_CLIENT_SERVER_JAR.getErrorCode());
-            compatibility.setCompatible(false);
-            return compatibility;
+            MajorMinorVersion serverMajorMinorVersion = new MajorMinorVersion(
+                    VersionUtil.decodeMajorVersion(serverVersion),
+                    VersionUtil.decodeMinorVersion(serverVersion));
+            MajorMinorVersion clientMajorMinorVersion =
+                    new MajorMinorVersion(clientMajorVersion, clientMinorVersion);
+            if (!clientMajorMinorVersion.equals(
+                    ALLOWED_SERVER_CLIENT_MAJOR_VERSION.get(serverMajorMinorVersion))) {
+                // Incompatible if not whitelisted by ALLOWED_SERVER_CLIENT_MAJOR_VERSION
+                compatibility.setErrorCode(SQLExceptionCode
+                        .INCOMPATIBLE_CLIENT_SERVER_JAR.getErrorCode());
+                compatibility.setCompatible(false);
+                return compatibility;
+            }
         }
         compatibility.setCompatible(true);
         return compatibility;
-
     }
 
     // Given the encoded integer representing the phoenix version in the encoded version value.