Skip to content

Commit

Permalink
CCBC-1126: Ensure KV connection select bucket when needed
Browse files Browse the repository at this point in the history
Change-Id: Ia86165edf0e2dfc20ad6a4bba1fa7540c711717b
Reviewed-on: http://review.couchbase.org/119594
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Tested-by: Build Bot <build@couchbase.com>
  • Loading branch information
avsej committed Dec 20, 2019
1 parent 3c4ff95 commit 15683f8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/bucketconfig/bc_cccp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ lcb_STATUS CccpProvider::schedule_next_request(lcb_STATUS err, bool can_rollover
lcb_log(LOGARGS(this, TRACE), "Re-Issuing CCCP Command on server struct %p (" LCB_HOST_FMT ")", (void *)server,
LCB_HOST_ARG(this->parent->settings, next_host));
timer.rearm(settings().config_node_timeout);
if (settings().bucket && settings().bucket[0] != '\0' && config && config->vbc->bname == NULL) {
if (settings().bucket && settings().bucket[0] != '\0' && !server->selected_bucket) {
instance->select_bucket(cmdcookie, server);
}
instance->request_config(cmdcookie, server);
Expand All @@ -167,7 +167,7 @@ lcb_STATUS CccpProvider::schedule_next_request(lcb_STATUS err, bool can_rollover

lcb_STATUS CccpProvider::mcio_error(lcb_STATUS err)
{
if (err != LCB_ERR_UNSUPPORTED_OPERATION && err != LCB_ERR_UNSUPPORTED_OPERATION) {
if (err != LCB_ERR_UNSUPPORTED_OPERATION) {
lcb_log(LOGARGS(this, ERR), LOGFMT "Could not get configuration: %s", LOGID(this), lcb_strerror_short(err));
}

Expand Down
1 change: 1 addition & 0 deletions src/getconfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static void ext_callback_proxy(mc_PIPELINE *pl, mc_PACKET *req, lcb_STATUS rc, c
switch (res->opcode()) {
case PROTOCOL_BINARY_CMD_SELECT_BUCKET:
lcb::clconfig::select_status(rd->cookie, rc);
server->selected_bucket = 1;
break;
case PROTOCOL_BINARY_CMD_GET_CLUSTER_CONFIG:
lcb::clconfig::cccp_update(rd->cookie, rc, res->value(), res->vallen(), &server->get_host());
Expand Down
3 changes: 2 additions & 1 deletion src/mcserver/mcserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ void Server::handle_connected(lcbio_SOCKET *sock, lcb_STATUS err, lcbio_OSERR sy
mutation_tokens = sessinfo->has_feature(PROTOCOL_BINARY_FEATURE_MUTATION_SEQNO);
new_durability = sessinfo->has_feature(PROTOCOL_BINARY_FEATURE_SYNC_REPLICATION) &&
sessinfo->has_feature(PROTOCOL_BINARY_FEATURE_ALT_REQUEST_SUPPORT);
selected_bucket = sessinfo->selected_bucket();
}

lcbio_CTXPROCS procs;
Expand Down Expand Up @@ -902,7 +903,7 @@ static void buf_done_cb(mc_PIPELINE *pl, const void *cookie, void *, void *)
Server::Server(lcb_INSTANCE *instance_, int ix)
: mc_PIPELINE(), state(S_CLEAN), io_timer(lcbio_timer_new(instance_->iotable, this, timeout_server)),
instance(instance_), settings(lcb_settings_ref2(instance_->settings)), compsupport(0), jsonsupport(0),
mutation_tokens(0), new_durability(-1), connctx(NULL), curhost(new lcb_host_t())
mutation_tokens(0), new_durability(-1), selected_bucket(0), connctx(NULL), curhost(new lcb_host_t())
{
mcreq_pipeline_init(this);
flush_start = (mcreq_flushstart_fn)server_connect;
Expand Down
3 changes: 3 additions & 0 deletions src/mcserver/mcserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ class Server : public mc_PIPELINE
/** Whether new durability is supported */
short new_durability;

/** Whether bucket has been selected */
short selected_bucket;

lcbio_CTX *connctx;
lcb::io::ConnectionRequest *connreq;

Expand Down
8 changes: 7 additions & 1 deletion src/mcserver/negotiate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ static int sasl_get_password(cbsasl_conn_t *conn, void *context, int id, cbsasl_
return SASL_OK;
}

SessionInfo::SessionInfo()
SessionInfo::SessionInfo() : selected(false)
{
lcbio_PROTOCTX::id = LCBIO_PROTOCTX_SESSINFO;
lcbio_PROTOCTX::dtor = (void (*)(lcbio_PROTOCTX *))cleanup_negotiated;
Expand Down Expand Up @@ -626,6 +626,7 @@ void SessionRequestImpl::handle_read(lcbio_CTX *ioctx)
case PROTOCOL_BINARY_CMD_SELECT_BUCKET: {
if (status == PROTOCOL_BINARY_RESPONSE_SUCCESS) {
completed = true;
info->selected = true;
} else if (status == PROTOCOL_BINARY_RESPONSE_EACCESS) {
set_error(LCB_ERR_BUCKET_NOT_FOUND,
"Provided credentials not allowed for bucket or bucket does not exist", &resp);
Expand Down Expand Up @@ -736,6 +737,11 @@ SessionInfo *SessionInfo::get(lcbio_SOCKET *sock)
return static_cast< SessionInfo * >(lcbio_protoctx_get(sock, LCBIO_PROTOCTX_SESSINFO));
}

bool SessionInfo::selected_bucket() const
{
return selected;
}

bool SessionInfo::has_feature(uint16_t feature) const
{
return std::find(server_features.begin(), server_features.end(), feature) != server_features.end();
Expand Down
2 changes: 2 additions & 0 deletions src/mcserver/negotiate.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,15 @@ class SessionInfo : public lcbio_PROTOCTX
* @return true if supported, false otherwise
*/
bool has_feature(uint16_t feature) const;
bool selected_bucket() const;

private:
SessionInfo();
friend class lcb::SessionRequestImpl;

std::string mech;
std::vector< uint16_t > server_features;
bool selected;
};

} // namespace lcb
Expand Down

0 comments on commit 15683f8

Please sign in to comment.