cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [04/10] cassandra git commit: Prepare legacy auth statements if tables initialised after node startup (follow-up)
Date Fri, 11 Nov 2016 11:35:48 GMT
Prepare legacy auth statements if tables initialised after node startup (follow-up)

Patch by Alex Petrov; reviewed by Sam Tunnicliffe for CASSANDRA-12813

Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/5e4198ff
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/5e4198ff
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/5e4198ff

Branch: refs/heads/trunk
Commit: 5e4198ffdad57aebd7c4b3a8cc01a7ce88eac99c
Parents: 2e21cac
Author: Alex Petrov <oleksandr.petrov@gmail.com>
Authored: Thu Nov 10 14:07:38 2016 +0100
Committer: Sam Tunnicliffe <sam@beobal.com>
Committed: Fri Nov 11 11:21:39 2016 +0000

----------------------------------------------------------------------
 .../cassandra/auth/CassandraRoleManager.java    | 23 +++++++++++++++-----
 1 file changed, 17 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/5e4198ff/src/java/org/apache/cassandra/auth/CassandraRoleManager.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/auth/CassandraRoleManager.java b/src/java/org/apache/cassandra/auth/CassandraRoleManager.java
index dbae1ba..a90b297 100644
--- a/src/java/org/apache/cassandra/auth/CassandraRoleManager.java
+++ b/src/java/org/apache/cassandra/auth/CassandraRoleManager.java
@@ -163,9 +163,8 @@ public class CassandraRoleManager implements IRoleManager
         // to be added.
         if (Schema.instance.getCFMetaData(AuthKeyspace.NAME, "users") != null)
         {
-             legacySelectUserStatement = (SelectStatement) prepare("SELECT * FROM %s.%s WHERE
name = ?",
-                                                                   AuthKeyspace.NAME,
-                                                                   LEGACY_USERS_TABLE);
+            legacySelectUserStatement = prepareLegacySelectUserStatement();
+
             scheduleSetupTask(new Callable<Void>()
             {
                 public Void call() throws Exception
@@ -459,6 +458,13 @@ public class CassandraRoleManager implements IRoleManager
         }
     }
 
+    private SelectStatement prepareLegacySelectUserStatement()
+    {
+        return (SelectStatement) prepare("SELECT * FROM %s.%s WHERE name = ?",
+                                         AuthKeyspace.NAME,
+                                         LEGACY_USERS_TABLE);
+    }
+
     private CQLStatement prepare(String template, String keyspace, String table)
     {
         try
@@ -500,9 +506,14 @@ public class CassandraRoleManager implements IRoleManager
             // If it exists, try the legacy users table in case the cluster
             // is in the process of being upgraded and so is running with mixed
             // versions of the authn schema.
-            return (Schema.instance.getCFMetaData(AuthKeyspace.NAME, "users") != null)
-                    ? getRoleFromTable(name, legacySelectUserStatement, LEGACY_ROW_TO_ROLE)
-                    : getRoleFromTable(name, loadRoleStatement, ROW_TO_ROLE);
+            if (Schema.instance.getCFMetaData(AuthKeyspace.NAME, "users") == null)
+                return getRoleFromTable(name, loadRoleStatement, ROW_TO_ROLE);
+            else
+            {
+                if (legacySelectUserStatement == null)
+                    prepareLegacySelectUserStatement();
+                return getRoleFromTable(name, legacySelectUserStatement, LEGACY_ROW_TO_ROLE);
+            }
         }
         catch (RequestExecutionException | RequestValidationException e)
         {


Mime
View raw message