Repository: AlexPikalov/cdrs (language: rust)

Issue:
USE statement
attempting something like ``conn.query("USE chubber")?;`` doesn't work for future queries (``Server(CDRSError { error_code: 8704, message: CString { string: "No keyspace has been specified. USE a keyspace, or explicitly specify keyspace.tablename" }, additional_info: Invalid(SimpleError) })`` when trying ``conn.query("SELECT * FROM table;")?;``) and having to write ``keyspace.table`` for every operation gets repetitive.

i notice that there are no docs (or functions like connect_keyspace), so are you already aware of this?


Discussion / hints:
I guess this maybe the same problem with proposed load balancing mechanism as with PREPARE statement in https://github.com/AlexPikalov/cdrs/issues/245

There is a a family of similar problems with current load balancer caused by a fact that on a new request it will pick up a new connection from a connection pool (the pool of connections to a node). Because of that the query `SELECT` is being executed on a next connection/session that doesn't have a name space used.

Until the problem with a load balancer is solved you can try to set a maximal size of a connection pool to `1`. In example https://github.com/AlexPikalov/cdrs/blob/master/examples/crud_operations.rs#L23 you would have instead

```rust
let node = NodeTcpConfigBuilder::new("127.0.0.1:9042", NoneAuthenticator {}).max_size(1).build()
```
ive already tried that, and the error prevails... sorry for not specifying
Do you use a single- or a multi-node cluster?
single node? heres my code:
```rust
let auth = PasswordAuthenticator::new(&cfg.cassandra_user, &cfg.cassandra_pass);
let node = NodeTcpConfigBuilder::new(&cfg.cassandra_url, auth).max_size(1).build();
let conn = session::new_lz4(&ClusterTcpConfig(vec![node]), RoundRobin::new())?;
```
I've just recorded a r2d2 Pool state between calls. This is what I've got

```
POOL State { connections: 1, idle_connections: 1 }
POOL State { connections: 0, idle_connections: 0 }
...
```

Seems there is a problem with getting connections back to the Pool. I'll investigate it further and will keep you updated in this thread.

Fix patch:
diff --git a/src/cluster/ssl_connection_pool.rs b/src/cluster/ssl_connection_pool.rs
index 8881c90..b769d15 100644
--- a/src/cluster/ssl_connection_pool.rs
+++ b/src/cluster/ssl_connection_pool.rs
@@ -74,6 +74,6 @@ impl<A: Authenticator + 'static + Send + Sync> ManageConnection for SslConnectio
   }
 
   fn has_broken(&self, conn: &mut Self::Connection) -> bool {
-    conn.borrow().is_alive()
+    !conn.borrow().is_alive()
   }
 }
diff --git a/src/cluster/tcp_connection_pool.rs b/src/cluster/tcp_connection_pool.rs
index 8680338..6985df5 100644
--- a/src/cluster/tcp_connection_pool.rs
+++ b/src/cluster/tcp_connection_pool.rs
@@ -64,7 +64,7 @@ impl<A: Authenticator + 'static + Send + Sync> ManageConnection for TcpConnectio
   }
 
   fn has_broken(&self, conn: &mut Self::Connection) -> bool {
-    conn.borrow().is_alive()
+    !conn.borrow().is_alive()
   }
 }
 
@@ -122,13 +122,11 @@ pub fn startup<'b, T: CDRSTransport + 'static, A: Authenticator + 'static + Size
     }
 
     let auth_token_bytes = session_authenticator.get_auth_token().into_cbytes();
-    try!(
-      transport.borrow_mut().write(
-        Frame::new_req_auth_response(auth_token_bytes)
-          .into_cbytes()
-          .as_slice()
-      )
-    );
+    try!(transport.borrow_mut().write(
+      Frame::new_req_auth_response(auth_token_bytes)
+        .into_cbytes()
+        .as_slice()
+    ));
     try!(parse_frame(transport, compression));
 
     return Ok(());


Test patch: