Skip to content

Commit

Permalink
CCBC-122 Try to switch another server from backup list on timeout
Browse files Browse the repository at this point in the history
Change-Id: I039dc7074cb47369cc0b9ead4330c71329966e6e
Reviewed-on: http://review.couchbase.org/22449
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
  • Loading branch information
avsej authored and trondn committed Nov 12, 2012
1 parent 72b94a9 commit d20654a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,9 +784,9 @@ static void lcb_instance_reset_stream_state(lcb_t instance)
instance->n_http_uri_sent = 0;
}

static int lcb_switch_to_backup_node(lcb_t instance,
lcb_error_t error,
const char *reason)
int lcb_switch_to_backup_node(lcb_t instance,
lcb_error_t error,
const char *reason)
{
if (instance->backup_nodes == NULL) {
/* No known backup nodes */
Expand Down
4 changes: 3 additions & 1 deletion src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,9 @@ extern "C" {
lcb_error_t lcb_error_handler(lcb_t instance,
lcb_error_t error,
const char *errinfo);

int lcb_switch_to_backup_node(lcb_t instance,
lcb_error_t error,
const char *reason);
int lcb_server_purge_implicit_responses(lcb_server_t *c,
lcb_uint32_t seqno,
hrtime_t delta);
Expand Down
8 changes: 6 additions & 2 deletions src/wait.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ static void initial_connect_timeout_handler(lcb_socket_t sock,
void *arg)
{
lcb_t instance = arg;
lcb_error_handler(instance, LCB_CONNECT_ERROR,
"Could not connect to server within allotted time");

/* try to switch to backup node and just return on success */
if (lcb_switch_to_backup_node(instance, LCB_CONNECT_ERROR,
"Could not connect to server within allotted time") != -1) {
return;
}

if (instance->sock != INVALID_SOCKET) {
/* Do we need to delete the event? */
Expand Down
16 changes: 16 additions & 0 deletions tests/mock-unit-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,19 @@ TEST_F(MockUnitTest, testDoubleFreeError)
ASSERT_GT(rv.cas2, 0);
ASSERT_NE(rv.cas1, rv.cas2);
}

TEST_F(MockUnitTest, testBrokenFirstNodeInList)
{
MockEnvironment *mock = MockEnvironment::getInstance();
lcb_create_st options;
mock->makeConnectParams(options, NULL);
std::string nodes = options.v.v0.host;
nodes = "1.2.3.4;" + nodes;
options.v.v0.host = nodes.c_str();

lcb_t instance;
ASSERT_EQ(LCB_SUCCESS, lcb_create(&instance, &options));
lcb_set_timeout(instance, 200000); /* 200 ms */
ASSERT_EQ(LCB_SUCCESS, lcb_connect(instance));
lcb_destroy(instance);
}

0 comments on commit d20654a

Please sign in to comment.