cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brandonwilli...@apache.org
Subject [1/4] git commit: Work around initialization problem
Date Thu, 22 May 2014 14:16:31 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 36cc02ca7 -> 9bd388780
  refs/heads/trunk 5f643ffcc -> 864865da9


Work around initialization problem


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

Branch: refs/heads/trunk
Commit: 36cc02ca76fa11b6b1d2cb24fb068d2a5dfaa842
Parents: 1147ee3
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Thu May 22 16:02:23 2014 +0200
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Thu May 22 16:02:23 2014 +0200

----------------------------------------------------------------------
 .../apache/cassandra/cql3/QueryProcessor.java   | 46 +++++++++++++-------
 1 file changed, 31 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/36cc02ca/src/java/org/apache/cassandra/cql3/QueryProcessor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/QueryProcessor.java b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
index fca9c42..fd6e6ce 100644
--- a/src/java/org/apache/cassandra/cql3/QueryProcessor.java
+++ b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
@@ -82,7 +82,6 @@ public class QueryProcessor implements QueryHandler
     // A map for prepared statements used internally (which we don't want to mix with user
statement, in particular we don't
     // bother with expiration on those.
     private static final ConcurrentMap<String, ParsedStatement.Prepared> internalStatements
= new ConcurrentHashMap<>();
-    private static final QueryState internalQueryState;
 
     static
     {
@@ -95,16 +94,33 @@ public class QueryProcessor implements QueryHandler
                                    .weigher(thriftMemoryUsageWeigher)
                                    .build();
 
-        ClientState state = ClientState.forInternalCalls();
-        try
-        {
-            state.setKeyspace(Keyspace.SYSTEM_KS);
-        }
-        catch (InvalidRequestException e)
+    }
+
+    // Work aound initialization dependency
+    private static enum InternalStateInstance
+    {
+        INSTANCE;
+
+        private final QueryState queryState;
+
+        InternalStateInstance()
         {
-            throw new RuntimeException();
+            ClientState state = ClientState.forInternalCalls();
+            try
+            {
+                state.setKeyspace(Keyspace.SYSTEM_KS);
+            }
+            catch (InvalidRequestException e)
+            {
+                throw new RuntimeException();
+            }
+            this.queryState = new QueryState(state);
         }
-        internalQueryState = new QueryState(state);
+    }
+
+    private static QueryState internalQueryState()
+    {
+        return InternalStateInstance.INSTANCE.queryState;
     }
 
     private QueryProcessor()
@@ -233,8 +249,8 @@ public class QueryProcessor implements QueryHandler
             return prepared;
 
         // Note: if 2 threads prepare the same query, we'll live so don't bother synchronizing
-        prepared = parseStatement(query, internalQueryState);
-        prepared.statement.validate(internalQueryState.getClientState());
+        prepared = parseStatement(query, internalQueryState());
+        prepared.statement.validate(internalQueryState().getClientState());
         internalStatements.putIfAbsent(query, prepared);
         return prepared;
     }
@@ -244,7 +260,7 @@ public class QueryProcessor implements QueryHandler
         try
         {
             ParsedStatement.Prepared prepared = prepareInternal(query);
-            ResultMessage result = prepared.statement.executeInternal(internalQueryState,
makeInternalOptions(prepared, values));
+            ResultMessage result = prepared.statement.executeInternal(internalQueryState(),
makeInternalOptions(prepared, values));
             if (result instanceof ResultMessage.Rows)
                 return UntypedResultSet.create(((ResultMessage.Rows)result).result);
             else
@@ -286,9 +302,9 @@ public class QueryProcessor implements QueryHandler
     {
         try
         {
-            ParsedStatement.Prepared prepared = parseStatement(query, internalQueryState);
-            prepared.statement.validate(internalQueryState.getClientState());
-            ResultMessage result = prepared.statement.executeInternal(internalQueryState,
makeInternalOptions(prepared, values));
+            ParsedStatement.Prepared prepared = parseStatement(query, internalQueryState());
+            prepared.statement.validate(internalQueryState().getClientState());
+            ResultMessage result = prepared.statement.executeInternal(internalQueryState(),
makeInternalOptions(prepared, values));
             if (result instanceof ResultMessage.Rows)
                 return UntypedResultSet.create(((ResultMessage.Rows)result).result);
             else


Mime
View raw message