void Session::broadcast_keyspace_change(const std::string& keyspace, const IOWorker* calling_io_worker) { // This can run on an IO worker thread. This is thread-safe because the IO workers // vector never changes after initialization and IOWorker::set_keyspace() uses // a lock. This also means that calling "USE <keyspace>" frequently is an // anti-pattern. for (IOWorkerVec::iterator it = io_workers_.begin(), end = io_workers_.end(); it != end; ++it) { if (*it == calling_io_worker) continue; (*it)->set_keyspace(keyspace); } set_keyspace(keyspace); }
Statement::Statement(const Prepared* prepared) : RoutableRequest(CQL_OPCODE_EXECUTE) , AbstractData(prepared->result()->column_count()) , query_or_id_(sizeof(uint16_t) + prepared->id().size()) , flags_(0) , page_size_(-1) { // <id> [short bytes] (or [string]) const std::string& id = prepared->id(); query_or_id_.encode_string(0, id.data(), id.size()); // Inherit settings and keyspace from the prepared statement set_settings(prepared->request_settings()); // If the keyspace wasn't explictly set then attempt to set it using the // prepared statement's result metadata. if (keyspace().empty()) { set_keyspace(prepared->result()->keyspace().to_string()); } }
void IOWorker::broadcast_keyspace_change(const std::string& keyspace) { set_keyspace(keyspace); session_->broadcast_keyspace_change(keyspace, this); }