[PCBC-204] Persistent connections should be indexed on server list contents, not their order. Created: 13/Feb/13  Updated: 14/Feb/13  Resolved: 14/Feb/13

Status: Resolved
Project: Couchbase PHP client library
Component/s: library
Affects Version/s: 1.0.4, 1.1.2
Fix Version/s: 1.1.3
Security Level: Public

Type: Bug Priority: Major
Reporter: Mark Nunberg Assignee: Trond Norbye
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   
In the current state, we simply treat the connection parameter as a string.

An example use case may be of several clients trying to load-balance between various entry points nodes (EPTs). Such a strategy ensures that they aren't all hitting the same node for configuration requests.

However when attempting to use this in conjunction with persistent connections, we have the consequence that each permutation of the "Server List" is treated as a separate key when using persistent connections; therefore something like:

$base_list = array("1.1.1.1", "2.2.2.2", "3.3.3.3", "4.4.4.4");

for ($i = 0; $i < 1000; $i++) {
 $cur_list = $base_list;
 shuffle($cur_list);
 $cb = new Couchbase($cur_list, "", "", "", true);
 $cb->set("foo", "bar");
 // other operations
}

In a nutshell, this code has a "base" set of four servers. In the "normal" initialization code, the list is copied and then shuffled around, so that the first server in the list is always something else. Since the first server in the list ends up becoming the EPT (unless the server is down, in which case the next node is used, etc.) this enables some kind of cheap load balancing.

However this also means the order of the array is different, which means the "canonical connection key" is different, which means that when considering whether an existing connection is available, a new one is created. Since we have 4 servers in the list, there is a potential of having 4*4=16 different client objects per process. These objects will never die.

The solution is then to "deconstruct" the connection string in such a way that the server list itself is always alphabetically sorted. The effective list (When actually connecting) will remain the same, but for indexing purposes, it shall be sorted.
Generated at Thu Nov 20 20:18:03 CST 2014 using JIRA 5.2.4#845-sha1:c9f4cc41abe72fb236945343a1f485c2c844dac9.