Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | Couchbase | Couchbase Server 1.8.x

Replication and server down, PHP. Can not get/store data

1 reply [Last post]
  • Login or register to post comments
Mon, 07/02/2012 - 02:07
Nox
Offline
Joined: 07/02/2012
Groups: None

Hi,

I have a 2 node 1.8.0 couchbasesystem.
CentOS 6.2
The bucket is "default" as a couchbase type that is replicated to 1 copy.
Using PHP to connect to cluster. From following SDK:
http://packages.couchbase.com/clients/php/php-ext-couchbase-1.0.4-centos...

My theory is to replace memcached for a better solution with replication and to remove a SPOF. If this is possible with couchbase.

I'm connection to server 1.
When both servers are up and running its 100% working with both read and write.

If I turn server 2 off(shutdown service on centos) the result is different. Only 50% of the read/write will work.
I do not make a failover or rebalance.(the failover should occur anyway after 30 sec but it might need 3 servers to do that?).

First Question is, do I need 3+ servers to have a 100% working replication? I need 100% uptime of the data. My thought is that since I have two servers the first server would use the replica items when server two is turned off.

Some code I try to test with:

Case 1:
If server two is off. Following code will not work.

$cb = new Couchbase("192.168.0.1:8091");
$i=94;
$cb->set("a_$i", $i);
var_dump($cb->get("a_$i"));

It will result in:
PHP Warning: Couchbase::set(): Failed to store a value to server: Connection failure

If server two is up, it will work as intended(192.168.0.1 is ip for server 1). If I change $i to for example 83 it will work since it wants to position it on server 1.

Case 2:
If I do a loop.

$cb = new Couchbase("192.168.0.1:8091");
for($i=1;$i<=100;$i++) {
echo "---------$i--------\n";
$cb->set("a_$i", $i);
var_dump($cb->get("a_$i"));
echo "-----------------\n";
}

This will result in having approx 50% of the keys written/read correct. Why does it even try to write on server two, since the couchbasecluster knows its down. It seems it reports all servers of the cluster no matter what state they are in.

Have I missunderstood it all or am I doing something wrong?
All help is appreciated!

Top
  • Login or register to post comments
Thu, 07/05/2012 - 20:42
mikew
Offline
Joined: 03/14/2011
Groups:

>> First Question is, do I need 3+ servers to have a 100% working replication?

No, you only need two servers to have everything replicated. When one of your servers goes down though you need to manually push the failover button on the server that went down in order to activate the replicas on the remaining servers. In order to setup auto failover (which is what I think you want) you need at least 3 servers.

Also, in your example your most likely connecting to moxi (port 11211) and moxi will redirect your requests to the correct server so all of the operations you do should work. If your client is connected to the server that went down then this is a problem as you mentioned. The best thing to do here would be to keep a pool of connections, one to each server, and when one fails just try one of the other ones.

Let me know if you have any other questions or if I missed anything.

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker