Redundant set_keyspace calls?

Apr 20, 2012 at 7:36 PM

I was looking through your Execute code, and notice that you may be sending set_keyspace on every single call, even if the keyspace for the client has not changed between previous calls.

 

In DefaultCluster:

private IClient AcquireClient(string keyspaceName)
        {
            //LOGGER.Debug("Acquiring client from pool.");
            IClient client = this.PoolManager.Borrow();
            if (client != null && keyspaceName != null)
            {
                //LOGGER.Debug("Setting keyspace to client.");
                client.KeyspaceName = keyspaceName;
            }
            return client;
        }

 

Then in DefaultClient that would trigger the sendKeyspace flag since there is no check to see if the incoming value is the same as current:

public override string KeyspaceName
        {
            get 
            { 
                return this.keyspaceName; 
            }
            set 
            { 
                this.keyspaceName = value;
                this.sendKeyspace = !String.IsNullOrEmpty(this.keyspaceName);
            }
        }
 

Which would cauase Execute to make roundtrip set_keyspace again?

if (this.sendKeyspace)
            {
                try
                {
                    this.sendKeyspace = false;
                    this.cassandraClient.set_keyspace(this.keyspaceName);
                }
                catch (Exception ex)
                {
                    throw this.buildException(ex);
                }
            }

            try
            {
                return executionBlock.DynamicInvoke(this.CassandraClient);
            }

Unless i'm reading the flow incorrectly.  Seems like it should only be called the first time and then never again unless keyspace for that client changes from previous execute.

Coordinator
Apr 20, 2012 at 8:49 PM

Brycerg, 

You are reading the code right, I am setting the keyspace each time you execute an action against cassandra. I have tried some time ago to separate connection pools for each keyspace, in order to select a connection based on the keyspace you need to work on. That would be the best approach from my point of view, but I can see I almost revert all the changes since I got lost on the changes.

Your recommendation seems a better solution that setting the keyspace always, since that "set" action actually goes against the cluster. That's seems annoying isn't it? 

I will see if there might be an actual ISSUE created over Cassandra for this matter, or I will try to contact them to gather more information. 

What seems pretty straigt is sending the keyspace within the whole command, and do the whole matter together. 

Thanks for your interested. I will keep you updated.