Modified: 
cassandra/trunk/src/java/org/apache/cassandra/db/migration/RenameColumnFamily.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/migration/RenameColumnFamily.java?rev=980554&r1=980553&r2=980554&view=diff
==============================================================================
--- 
cassandra/trunk/src/java/org/apache/cassandra/db/migration/RenameColumnFamily.java
 (original)
+++ 
cassandra/trunk/src/java/org/apache/cassandra/db/migration/RenameColumnFamily.java
 Thu Jul 29 19:53:36 2010
@@ -38,6 +38,8 @@ import java.util.List;
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
+
 public class RenameColumnFamily extends Migration
 {
     private static final Serializer serializer = new Serializer();
@@ -84,8 +86,12 @@ public class RenameColumnFamily extends 
     private KSMetaData makeNewKeyspaceDefinition(KSMetaData ksm)
     {
         CFMetaData oldCfm = ksm.cfMetaData().get(oldName);
-        KSMetaData temp = ksm.withoutColumnFamily(oldName);
-        return temp.withColumnFamily(CFMetaData.rename(oldCfm, newName));
+        List<CFMetaData> newCfs = new 
ArrayList<CFMetaData>(ksm.cfMetaData().values());
+        newCfs.remove(oldCfm);
+        assert newCfs.size() == ksm.cfMetaData().size() - 1;
+        CFMetaData newCfm = CFMetaData.rename(oldCfm, newName);
+        newCfs.add(newCfm);
+        return new KSMetaData(ksm.name, ksm.strategyClass, 
ksm.replicationFactor, newCfs.toArray(new CFMetaData[newCfs.size()]));
     }
 
     @Override

Modified: 
cassandra/trunk/src/java/org/apache/cassandra/db/migration/RenameKeyspace.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/migration/RenameKeyspace.java?rev=980554&r1=980553&r2=980554&view=diff
==============================================================================
--- 
cassandra/trunk/src/java/org/apache/cassandra/db/migration/RenameKeyspace.java 
(original)
+++ 
cassandra/trunk/src/java/org/apache/cassandra/db/migration/RenameKeyspace.java 
Thu Jul 29 19:53:36 2010
@@ -69,11 +69,25 @@ public class RenameKeyspace extends Migr
             throw new ConfigurationException("Keyspace already exists.");
         
         // clone the ksm, replacing thename.
-        KSMetaData newKsm = oldKsm.withName(newName); 
+        KSMetaData newKsm = rename(oldKsm, newName, false); 
         
         rm = makeDefinitionMutation(newKsm, oldKsm, newVersion);
     }
     
+    private static KSMetaData rename(KSMetaData ksm, String newName, boolean 
purgeOldCfs)
+    {
+        // cfs will need to have their tablenames reset. CFMetaData are 
immutable, so new ones get created with the
+        // same ids.
+        List<CFMetaData> newCfs = new 
ArrayList<CFMetaData>(ksm.cfMetaData().size());
+        for (CFMetaData oldCf : ksm.cfMetaData().values())
+        {
+            if (purgeOldCfs)
+                CFMetaData.purge(oldCf);
+            newCfs.add(CFMetaData.renameTable(oldCf, newName));
+        }
+        return new KSMetaData(newName, ksm.strategyClass, 
ksm.replicationFactor, newCfs.toArray(new CFMetaData[newCfs.size()]));
+    }
+
     @Override
     public ICompactSerializer getSerializer()
     {
@@ -88,9 +102,8 @@ public class RenameKeyspace extends Migr
         
         KSMetaData oldKsm = DatabaseDescriptor.getTableDefinition(oldName);
         for (CFMetaData cfm : oldKsm.cfMetaData().values())
-            // remove cf mappings for previous ksname
             CFMetaData.purge(cfm);
-        KSMetaData newKsm = oldKsm.withName(newName);
+        KSMetaData newKsm = rename(oldKsm, newName, true);
         for (CFMetaData cfm : newKsm.cfMetaData().values())
         {
             try

Modified: cassandra/trunk/src/java/org/apache/cassandra/io/SerDeUtils.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/io/SerDeUtils.java?rev=980554&r1=980553&r2=980554&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/io/SerDeUtils.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/io/SerDeUtils.java Thu Jul 29 
19:53:36 2010
@@ -22,8 +22,6 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.util.Map;
-import java.util.HashMap;
 
 import org.apache.avro.Schema;
 import org.apache.avro.io.BinaryDecoder;
@@ -47,22 +45,6 @@ public final class SerDeUtils
     // unbuffered decoders
     private final static DecoderFactory DIRECT_DECODERS = new 
DecoderFactory().configureDirectDecoder(true);
 
-    public static <T> Map<Utf8,T> toAvroMap(Map<String,T> map)
-    {
-        Map<Utf8,T> out = new HashMap<Utf8,T>();
-        for (Map.Entry<String,T> entry : map.entrySet())
-            out.put(new Utf8(entry.getKey()), entry.getValue());
-        return out;
-    }
-
-    public static <T> Map<String,T> fromAvroMap(Map<Utf8,T> map)
-    {
-        Map<String,T> out = new HashMap<String,T>();
-        for (Map.Entry<Utf8,T> entry : map.entrySet())
-            out.put(entry.getKey().toString(), entry.getValue());
-        return out;
-    }
-
        /**
      * Deserializes a single object based on the given Schema.
      * @param schema writer's schema

Modified: 
cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraDaemon.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraDaemon.java?rev=980554&r1=980553&r2=980554&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraDaemon.java 
(original)
+++ cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraDaemon.java 
Thu Jul 29 19:53:36 2010
@@ -189,7 +189,7 @@ public class CassandraDaemon extends org
             protected void afterExecute(Runnable r, Throwable t)
             {
                 super.afterExecute(r, t);
-                cassandraServer.clientState.logout();
+                cassandraServer.logout();
             }
         };
         serverEngine = new CustomTThreadPoolServer(new 
TProcessorFactory(processor),

Modified: 
cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java?rev=980554&r1=980553&r2=980554&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java 
(original)
+++ cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java 
Thu Jul 29 19:53:36 2010
@@ -29,10 +29,7 @@ import org.apache.cassandra.db.migration
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-// importing avro.AccessLevel hides thrift.AccessLevel
-import org.apache.cassandra.avro.AccessLevel;
 import org.apache.cassandra.auth.AllowAllAuthenticator;
-import org.apache.cassandra.auth.AuthenticatedUser;
 import org.apache.cassandra.concurrent.StageManager;
 import org.apache.cassandra.config.ConfigurationException;
 import org.apache.cassandra.config.KSMetaData;
@@ -56,7 +53,6 @@ import org.apache.cassandra.dht.IPartiti
 import org.apache.cassandra.dht.Range;
 import org.apache.cassandra.dht.Token;
 import org.apache.cassandra.scheduler.IRequestScheduler;
-import org.apache.cassandra.service.ClientState;
 import org.apache.cassandra.service.StorageProxy;
 import org.apache.cassandra.service.StorageService;
 import org.apache.thrift.TException;
@@ -69,8 +65,24 @@ public class CassandraServer implements 
     private final static List<ColumnOrSuperColumn> EMPTY_COLUMNS = 
Collections.emptyList();
     private final static List<Column> EMPTY_SUBCOLUMNS = 
Collections.emptyList();
 
-    // thread local state containing session information
-    public final ClientState clientState = new ClientState();
+    // will be set only by login()
+    private ThreadLocal<AccessLevel> loginDone = new 
ThreadLocal<AccessLevel>() 
+    {
+        @Override
+        protected AccessLevel initialValue()
+        {
+            return AccessLevel.NONE;
+        }
+    };
+    /*
+     * Keyspace associated with session
+     */
+    private ThreadLocal<String> keySpace = new ThreadLocal<String>();
+
+    /*
+     * An associated Id for scheduling the requests
+     */
+    private ThreadLocal<String> requestSchedulerId = new ThreadLocal<String>();
 
     /*
      * RequestScheduler to perform the scheduling of incoming requests
@@ -213,16 +225,6 @@ public class CassandraServer implements 
         return thrift_clock;
     }
 
-    private static Map<String,AccessLevel> 
unthriftifyAccessMap(Map<String,org.apache.cassandra.thrift.AccessLevel> map)
-    {
-        Map<String,AccessLevel> out = new HashMap<String,AccessLevel>();
-        if (map == null)
-            return out;
-        for (Map.Entry<String,org.apache.cassandra.thrift.AccessLevel> entry : 
map.entrySet())
-            out.put(entry.getKey(), 
Enum.valueOf(org.apache.cassandra.avro.AccessLevel.class, 
entry.getValue().name()));
-        return out;
-    }
-
     private Map<byte[], List<ColumnOrSuperColumn>> getSlice(List<ReadCommand> 
commands, ConsistencyLevel consistency_level)
     throws InvalidRequestException, UnavailableException, TimedOutException
     {
@@ -264,8 +266,8 @@ public class CassandraServer implements 
         if (logger.isDebugEnabled())
             logger.debug("get_slice");
         
-        clientState.hasKeyspaceAccess(AccessLevel.READONLY);
-        return multigetSliceInternal(clientState.getKeyspace(), 
Arrays.asList(key), column_parent, predicate, consistency_level).get(key);
+        checkKeyspaceAndLoginAuthorized(AccessLevel.READONLY);
+        return multigetSliceInternal(keySpace.get(), Arrays.asList(key), 
column_parent, predicate, consistency_level).get(key);
     }
     
     public Map<byte[], List<ColumnOrSuperColumn>> multiget_slice(List<byte[]> 
keys, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel 
consistency_level)
@@ -274,9 +276,9 @@ public class CassandraServer implements 
         if (logger.isDebugEnabled())
             logger.debug("multiget_slice");
 
-        clientState.hasKeyspaceAccess(AccessLevel.READONLY);
+        checkKeyspaceAndLoginAuthorized(AccessLevel.READONLY);
 
-        return multigetSliceInternal(clientState.getKeyspace(), keys, 
column_parent, predicate, consistency_level);
+        return multigetSliceInternal(keySpace.get(), keys, column_parent, 
predicate, consistency_level);
     }
 
     private Map<byte[], List<ColumnOrSuperColumn>> 
multigetSliceInternal(String keyspace, List<byte[]> keys, ColumnParent 
column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level)
@@ -313,8 +315,8 @@ public class CassandraServer implements 
         if (logger.isDebugEnabled())
             logger.debug("get");
 
-        clientState.hasKeyspaceAccess(AccessLevel.READONLY);
-        String keyspace = clientState.getKeyspace();
+        checkKeyspaceAndLoginAuthorized(AccessLevel.READONLY);
+        String keyspace = keySpace.get();
 
         ThriftValidation.validateColumnPath(keyspace, column_path);
 
@@ -341,7 +343,7 @@ public class CassandraServer implements 
         if (logger.isDebugEnabled())
             logger.debug("get_count");
 
-        clientState.hasKeyspaceAccess(AccessLevel.READONLY);
+        checkKeyspaceAndLoginAuthorized(AccessLevel.READONLY);
 
         return get_slice(key, column_parent, predicate, 
consistency_level).size();
     }
@@ -352,7 +354,7 @@ public class CassandraServer implements 
         if (logger.isDebugEnabled())
             logger.debug("multiget_count");
 
-        clientState.hasKeyspaceAccess(AccessLevel.READONLY);
+        checkKeyspaceAndLoginAuthorized(AccessLevel.READONLY);
 
         Map<byte[], Integer> counts = new HashMap<byte[], Integer>();
         Map<byte[], List<ColumnOrSuperColumn>> columnFamiliesMap = 
multigetSliceInternal(table, keys, column_parent, predicate, consistency_level);
@@ -369,14 +371,14 @@ public class CassandraServer implements 
         if (logger.isDebugEnabled())
             logger.debug("insert");
 
-        clientState.hasKeyspaceAccess(AccessLevel.READWRITE);
+        checkKeyspaceAndLoginAuthorized(AccessLevel.READWRITE);
 
         ThriftValidation.validateKey(key);
-        ThriftValidation.validateColumnParent(clientState.getKeyspace(), 
column_parent);
-        ThriftValidation.validateColumn(clientState.getKeyspace(), 
column_parent, column);
+        ThriftValidation.validateColumnParent(keySpace.get(), column_parent);
+        ThriftValidation.validateColumn(keySpace.get(), column_parent, column);
         IClock cassandra_clock = ThriftValidation.validateClock(column.clock);
 
-        RowMutation rm = new RowMutation(clientState.getKeyspace(), key);
+        RowMutation rm = new RowMutation(keySpace.get(), key);
         try
         {
             rm.add(new QueryPath(column_parent.column_family, 
column_parent.super_column, column.name), column.value, cassandra_clock, 
column.ttl);
@@ -412,7 +414,7 @@ public class CassandraServer implements 
             }
         }
         
-        clientState.hasKeyspaceAccess(needed);
+        checkKeyspaceAndLoginAuthorized(needed);
 
         List<RowMutation> rowMutations = new ArrayList<RowMutation>();
         for (Map.Entry<byte[], Map<String, List<Mutation>>> mutationEntry: 
mutation_map.entrySet())
@@ -427,10 +429,10 @@ public class CassandraServer implements 
 
                 for (Mutation mutation : columnFamilyMutations.getValue())
                 {
-                    
ThriftValidation.validateMutation(clientState.getKeyspace(), cfName, mutation);
+                    ThriftValidation.validateMutation(keySpace.get(), cfName, 
mutation);
                 }
             }
-            
rowMutations.add(RowMutation.getRowMutationFromMutations(clientState.getKeyspace(),
 key, columnFamilyToMutations));
+            
rowMutations.add(RowMutation.getRowMutationFromMutations(keySpace.get(), key, 
columnFamilyToMutations));
         }
 
         doInsert(consistency_level, rowMutations);
@@ -442,14 +444,14 @@ public class CassandraServer implements 
         if (logger.isDebugEnabled())
             logger.debug("remove");
 
-        clientState.hasKeyspaceAccess(AccessLevel.FULL);
+        checkKeyspaceAndLoginAuthorized(AccessLevel.FULL);
 
         ThriftValidation.validateKey(key);
-        ThriftValidation.validateColumnPathOrParent(clientState.getKeyspace(), 
column_path);
+        ThriftValidation.validateColumnPathOrParent(keySpace.get(), 
column_path);
 
         IClock cassandra_clock = ThriftValidation.validateClock(clock);
 
-        RowMutation rm = new RowMutation(clientState.getKeyspace(), key);
+        RowMutation rm = new RowMutation(keySpace.get(), key);
         rm.delete(new QueryPath(column_path), cassandra_clock);
 
         doInsert(consistency_level, Arrays.asList(rm));
@@ -517,8 +519,8 @@ public class CassandraServer implements 
         if (logger.isDebugEnabled())
             logger.debug("range_slice");
 
-        String keyspace = clientState.getKeyspace();
-        clientState.hasKeyspaceAccess(AccessLevel.READONLY);
+        String keyspace = keySpace.get();
+        checkKeyspaceAndLoginAuthorized(AccessLevel.READONLY);
 
         return getRangeSlicesInternal(keyspace, column_parent, range, 
predicate, consistency_level);
     }
@@ -587,11 +589,11 @@ public class CassandraServer implements 
         if (logger.isDebugEnabled())
             logger.debug("scan");
 
-        clientState.hasKeyspaceAccess(AccessLevel.READONLY);
+        checkKeyspaceAndLoginAuthorized(AccessLevel.READONLY);
 
         if (row_predicate.keys != null)
         {
-            Map<byte[], List<ColumnOrSuperColumn>> rowMap = 
multigetSliceInternal(clientState.getKeyspace(), row_predicate.keys, 
column_parent, column_predicate, consistency_level);
+            Map<byte[], List<ColumnOrSuperColumn>> rowMap = 
multigetSliceInternal(keySpace.get(), row_predicate.keys, column_parent, 
column_predicate, consistency_level);
             List<KeySlice> rows = new ArrayList<KeySlice>(rowMap.size());
             for (Map.Entry<byte[], List<ColumnOrSuperColumn>> entry : 
rowMap.entrySet())
             {
@@ -602,12 +604,12 @@ public class CassandraServer implements 
 
         if (row_predicate.key_range != null)
         {
-            return getRangeSlicesInternal(clientState.getKeyspace(), 
column_parent, row_predicate.key_range, column_predicate, consistency_level);
+            return getRangeSlicesInternal(keySpace.get(), column_parent, 
row_predicate.key_range, column_predicate, consistency_level);
         }
 
         if (row_predicate.index_clause != null)
         {
-            return scanIndexInternal(clientState.getKeyspace(), column_parent, 
row_predicate.index_clause, column_predicate, consistency_level);
+            return scanIndexInternal(keySpace.get(), column_parent, 
row_predicate.index_clause, column_predicate, consistency_level);
         }
 
         throw new InvalidRequestException("row predicate must specify keys, 
key_range, or index_clause");
@@ -694,9 +696,47 @@ public class CassandraServer implements 
         return splits;
     }
 
-    public void login(AuthenticationRequest auth_request) throws 
AuthenticationException, AuthorizationException, TException
+    public AccessLevel login(AuthenticationRequest auth_request) throws 
AuthenticationException, AuthorizationException, TException
+    {
+        AccessLevel level;
+        
+        if (keySpace.get() == null)
+        {
+            throw new AuthenticationException("You have not set a specific 
keyspace; please call set_keyspace first");
+        }
+        
+        level = DatabaseDescriptor.getAuthenticator().login(keySpace.get(), 
auth_request);
+        
+        if (logger.isDebugEnabled())
+            logger.debug("login confirmed; new access level is " + level);
+        
+        loginDone.set(level);
+        return level;
+    }
+
+    public void logout()
     {
-        clientState.login(auth_request.getCredentials());
+        keySpace.remove();
+        loginDone.remove();
+
+        if (logger.isDebugEnabled())
+            logger.debug("logout complete");
+    }
+
+    protected void checkKeyspaceAndLoginAuthorized(AccessLevel level) throws 
InvalidRequestException
+    {
+        if (keySpace.get() == null)
+        {
+            throw new InvalidRequestException("You have not assigned a 
keyspace; please use set_keyspace (and login if necessary)");
+        }
+        
+        if (!(DatabaseDescriptor.getAuthenticator() instanceof 
AllowAllAuthenticator))
+        {
+            if (loginDone.get() == null)
+                throw new InvalidRequestException("You have not logged into 
keyspace " + keySpace.get());
+            if (loginDone.get().getValue() < level.getValue())
+                throw new InvalidRequestException("Your credentials are not 
sufficient to perform " + level + " operations");
+        }
     }
 
     /**
@@ -704,7 +744,7 @@ public class CassandraServer implements 
      */
     private void schedule()
     {
-        requestScheduler.queue(Thread.currentThread(), 
clientState.getSchedulingId());
+        requestScheduler.queue(Thread.currentThread(), 
requestSchedulerId.get());
     }
 
     /**
@@ -756,8 +796,7 @@ public class CassandraServer implements 
 
     public String system_add_column_family(CfDef cf_def) throws 
InvalidRequestException, TException
     {
-        clientState.hasBaseAccess(AccessLevel.FULL);
-        
+        checkKeyspaceAndLoginAuthorized(AccessLevel.FULL);
         try
         {
             applyMigrationOnStage(new 
AddColumnFamily(convertToCFMetaData(cf_def)));
@@ -779,11 +818,11 @@ public class CassandraServer implements 
 
     public String system_drop_column_family(String column_family) throws 
InvalidRequestException, TException
     {
-        clientState.hasBaseAccess(AccessLevel.FULL);
+        checkKeyspaceAndLoginAuthorized(AccessLevel.FULL);
         
         try
         {
-            applyMigrationOnStage(new 
DropColumnFamily(clientState.getKeyspace(), column_family, true));
+            applyMigrationOnStage(new DropColumnFamily(keySpace.get(), 
column_family, true));
             return DatabaseDescriptor.getDefsVersion().toString();
         }
         catch (ConfigurationException e)
@@ -802,11 +841,11 @@ public class CassandraServer implements 
 
     public String system_rename_column_family(String old_name, String 
new_name) throws InvalidRequestException, TException
     {
-        clientState.hasBaseAccess(AccessLevel.FULL);
+        checkKeyspaceAndLoginAuthorized(AccessLevel.FULL);
         
         try
         {
-            applyMigrationOnStage(new 
RenameColumnFamily(clientState.getKeyspace(), old_name, new_name));
+            applyMigrationOnStage(new RenameColumnFamily(keySpace.get(), 
old_name, new_name));
             return DatabaseDescriptor.getDefsVersion().toString();
         }
         catch (ConfigurationException e)
@@ -828,7 +867,6 @@ public class CassandraServer implements 
         // IAuthenticator was devised prior to, and without thought for, 
dynamic keyspace creation. As
         // a result, we must choose between letting anyone/everyone create 
keyspaces (which they likely
         // won't even be able to use), or be honest and disallow it entirely 
if configured for auth.
-        // See CASSANDRA-1271 for a proposed solution.
         if (!(DatabaseDescriptor.getAuthenticator() instanceof 
AllowAllAuthenticator))
             throw new InvalidRequestException("Unable to create new keyspace 
while authentication is enabled.");
 
@@ -852,9 +890,7 @@ public class CassandraServer implements 
             KSMetaData ksm = new KSMetaData(
                     ks_def.name, 
                     (Class<? extends 
AbstractReplicationStrategy>)Class.forName(ks_def.strategy_class), 
-                    ks_def.replication_factor,
-                    unthriftifyAccessMap(ks_def.users_access),
-                    unthriftifyAccessMap(ks_def.groups_access),
+                    ks_def.replication_factor, 
                     cfDefs.toArray(new CFMetaData[cfDefs.size()]));
             applyMigrationOnStage(new AddKeyspace(ksm));
             return DatabaseDescriptor.getDefsVersion().toString();
@@ -881,7 +917,7 @@ public class CassandraServer implements 
     
     public String system_drop_keyspace(String keyspace) throws 
InvalidRequestException, TException
     {
-        clientState.hasBaseAccess(AccessLevel.FULL);
+        checkKeyspaceAndLoginAuthorized(AccessLevel.FULL);
         
         try
         {
@@ -904,13 +940,11 @@ public class CassandraServer implements 
 
     public String system_rename_keyspace(String old_name, String new_name) 
throws InvalidRequestException, TException
     {
-        clientState.hasBaseAccess(AccessLevel.FULL);
+        checkKeyspaceAndLoginAuthorized(AccessLevel.FULL);
         
         try
         {
-            RenameKeyspace rename = new RenameKeyspace(old_name, new_name);
-            rename.apply();
-            rename.announce();
+            applyMigrationOnStage(new RenameKeyspace(old_name, new_name));
             return DatabaseDescriptor.getDefsVersion().toString();
         }
         catch (ConfigurationException e)
@@ -967,12 +1001,12 @@ public class CassandraServer implements 
 
     public void truncate(String cfname) throws InvalidRequestException, 
UnavailableException, TException
     {
-        logger.debug("truncating {} in {}", cfname, clientState.getKeyspace());
-        clientState.hasKeyspaceAccess(AccessLevel.READWRITE);
+        logger.debug("truncating {} in {}", cfname, keySpace.get());
+        checkKeyspaceAndLoginAuthorized(AccessLevel.FULL);
         try
         {
             schedule();
-            StorageProxy.truncateBlocking(clientState.getKeyspace(), cfname);
+            StorageProxy.truncateBlocking(keySpace.get(), cfname);
         }
         catch (TimeoutException e)
         {
@@ -995,7 +1029,12 @@ public class CassandraServer implements 
             throw new InvalidRequestException("Keyspace does not exist");
         }
         
-        clientState.setKeyspace(keyspace);
+        // If switching, invalidate previous access level; force a new login.
+        if (keySpace.get() != null && !keySpace.get().equals(keyspace))
+            loginDone.set(AccessLevel.NONE);
+        
+        keySpace.set(keyspace);
+        requestSchedulerId.set(keyspace);
     }
 
     public Map<String, List<String>> check_schema_agreement() throws 
TException, InvalidRequestException

Modified: 
cassandra/trunk/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java?rev=980554&r1=980553&r2=980554&view=diff
==============================================================================
--- 
cassandra/trunk/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java
 (original)
+++ 
cassandra/trunk/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java
 Thu Jul 29 19:53:36 2010
@@ -37,7 +37,9 @@ public class DatabaseDescriptorTest
 {
     protected <D extends SpecificRecord> D serDe(D record) throws IOException
     {
-        return SerDeUtils.<D>deserialize(record.getSchema(), 
SerDeUtils.serialize(record));
+        D actual = SerDeUtils.<D>deserialize(record.getSchema(), 
SerDeUtils.serialize(record));
+        assert actual.equals(record) : actual + " != " + record;
+        return actual;
     }
 
     @Test
@@ -81,9 +83,9 @@ public class DatabaseDescriptorTest
         assert DatabaseDescriptor.getNonSystemTables().size() == 0;
         
         // add a few.
-        AddKeyspace ks0 = new AddKeyspace(new KSMetaData("ks0", 
RackUnawareStrategy.class, 3, null, null));
+        AddKeyspace ks0 = new AddKeyspace(new KSMetaData("ks0", 
RackUnawareStrategy.class, 3));
         ks0.apply();
-        AddKeyspace ks1 = new AddKeyspace(new KSMetaData("ks1", 
RackUnawareStrategy.class, 3, null, null));
+        AddKeyspace ks1 = new AddKeyspace(new KSMetaData("ks1", 
RackUnawareStrategy.class, 3));
         ks1.apply();
         
         assert DatabaseDescriptor.getTableDefinition("ks0") != null;

Modified: cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java?rev=980554&r1=980553&r2=980554&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java Thu Jul 29 
19:53:36 2010
@@ -262,7 +262,7 @@ public class DefsTest extends CleanupHel
     {
         DecoratedKey dk = Util.dk("key0");
         CFMetaData newCf = new CFMetaData("NewKeyspace1", "AddedStandard1", 
ColumnFamilyType.Standard, ClockType.Timestamp, UTF8Type.instance, null, new 
TimestampReconciler(), "A new cf for a new ks", 0, false, 1.0, 0, 864000, 
Collections.<byte[], ColumnDefinition>emptyMap());
-        KSMetaData newKs = new KSMetaData(newCf.tableName, 
RackUnawareStrategy.class, 5, null, null, newCf);
+        KSMetaData newKs = new KSMetaData(newCf.tableName, 
RackUnawareStrategy.class, 5, newCf);
         
         new AddKeyspace(newKs).apply();
         
@@ -414,7 +414,7 @@ public class DefsTest extends CleanupHel
     {
         assert DatabaseDescriptor.getTableDefinition("EmptyKeyspace") == null;
         
-        KSMetaData newKs = new KSMetaData("EmptyKeyspace", 
RackUnawareStrategy.class, 5, null, null);
+        KSMetaData newKs = new KSMetaData("EmptyKeyspace", 
RackUnawareStrategy.class, 5, new CFMetaData[]{});
 
         new AddKeyspace(newKs).apply();
         assert DatabaseDescriptor.getTableDefinition("EmptyKeyspace") != null;


Reply via email to