我正在嘗試Couchbase。我寫了一些代碼(在couchbase文檔的幫助下)。當我有服務器時,讀寫工作非常好。無法運行具有多個節點的couchbase羣集
當我把第2個服務器,我不能寫/或讀取...連接很長
我在做什麼錯了(它與1個服務器超快)?
該代碼顯然工作。當我在EC2上添加節點時,這是我做的事情?所有的港口都是開放的(向全世界)。當我加入集羣時,重新平衡就沒問題。
例子:我的羣集啓動並運行(在這裏與EC2 5個節點):
這是我的日誌:
連接:
2014-07-04 17:25:20.600 INFO net.spy.memcached.auth.AuthThread: Authenticated to /54.247.158.182:11210
2014-07-04 17:25:20.811 INFO com.couchbase.client.vbucket.provider.BucketConfigurationProvider: Could bootstrap through carrier publication.
寫:
2014-07-04 17:25:20.817 INFO com.couchbase.client.CouchbaseConnection: Added {QA sa=/10.57.35.15:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2014-07-04 17:25:20.818 INFO com.couchbase.client.CouchbaseConnection: Added {QA sa=/10.250.110.205:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2014-07-04 17:25:20.818 INFO com.couchbase.client.CouchbaseConnection: Added {QA sa=/10.250.153.230:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2014-07-04 17:25:20.819 INFO com.couchbase.client.CouchbaseConnection: Added {QA sa=/10.59.13.200:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2014-07-04 17:25:20.819 INFO com.couchbase.client.CouchbaseConnection: Added {QA sa=/10.65.51.132:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
閱讀:
2014-07-04 17:25:30.820 INFO com.couchbase.client.vbucket.provider.BucketConfigurationProvider: Could bootstrap through carrier publication.
2014-07-04 17:25:45.847 INFO com.couchbase.client.CouchbaseClient: CouchbaseConnectionFactory{bucket='Users', nodes=[http://54.247.158.182:8091/pools], order=RANDOM, opTimeout=2500, opQueue=16384, opQueueBlockTime=10000, obsPollInt=10, obsPollMax=500, obsTimeout=5000, viewConns=10, viewTimeout=75000, viewWorkers=1, configCheck=10, reconnectInt=1100, failureMode=Redistribute, hashAlgo=NATIVE_HASH, authWaitTime=2500}
Connected to CouchbaseConnectionFactory{bucket='Users', nodes=[http://54.247.158.182:8091/pools], order=RANDOM, opTimeout=2500, opQueue=16384, opQueueBlockTime=10000, obsPollInt=10, obsPollMax=500, obsTimeout=5000, viewConns=10, viewTimeout=75000, viewWorkers=1, configCheck=10, reconnectInt=1100, failureMode=Redistribute, hashAlgo=NATIVE_HASH, authWaitTime=2500}
2014-07-04 17:26:10.908 INFO com.couchbase.client.CouchbaseClient: viewmode property isn't defined. Setting viewmode to production mode
2014-07-04 17:26:10.989 INFO com.couchbase.client.CouchbaseConnection: Node for key "user101" is not active (yet). Queueing up for retry and checking for stale configuration.
2014-07-04 17:26:11.362 INFO com.couchbase.client.CouchbaseConnection: Node for key "user101" is not active (yet). Queueing up for retry and checking for stale configuration.
2014-07-04 17:26:12.363 INFO com.couchbase.client.CouchbaseConnection: Node for key "user101" is not active (yet). Queueing up for retry and checking for stale configuration.
2014-07-04 17:26:13.365 INFO com.couchbase.client.CouchbaseConnection: Node for key "user101" is not active (yet). Queueing up for retry and checking for stale configuration.
2014-07-04 17:26:13.490 WARN net.spy.memcached.MemcachedConnection: handling node for operation is not set
java.lang.RuntimeException: Timed out waiting for operation
at net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:142)
at com.t2s.injector.Injector.insertData(Injector.java:71)
at com.t2s.injector.Injector.main(Injector.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: net.spy.memcached.internal.CheckedOperationTimeoutException: Timed out waiting for operation - failing node: <unknown>
at net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:167)
at net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:140)
... 7 more
2014-07-04 17:27:27.995 INFO com.couchbase.client.CouchbaseConnection: Reconnecting due to failure to connect to {QA sa=10.250.110.205/10.250.110.205:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}
java.net.ConnectException: Connexion terminée par expiration du délai d'attente
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:735)
at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:677)
at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:436)
at com.couchbase.client.CouchbaseConnection.run(CouchbaseConnection.java:324)
java.lang.RuntimeException: Timed out waiting for operation
at com.couchbase.client.internal.HttpFuture.get(HttpFuture.java:75)
at com.couchbase.client.CouchbaseClient.getView(CouchbaseClient.java:430)
at com.t2s.injector.Injector.queryView(Injector.java:85)
at com.t2s.injector.Injector.main(Injector.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.util.concurrent.TimeoutException: Timed out waiting for operation
at com.couchbase.client.internal.HttpFuture.waitForAndCheckOperation(HttpFuture.java:93)
at com.couchbase.client.internal.HttpFuture.get(HttpFuture.java:82)
at com.couchbase.client.internal.HttpFuture.get(HttpFuture.java:72)
... 8 more
2014-07-04 17:27:53.249 WARN com.couchbase.client.CouchbaseConnection: Closing, and reopening {QA sa=10.250.110.205/10.250.110.205:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}, attempt 1.
2014-07-04 17:27:53.249 INFO com.couchbase.client.CouchbaseConnection: Reconnecting due to failure to connect to {QA sa=10.250.153.230/10.250.153.230:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}
java.net.ConnectException: Connexion terminée par expiration du délai d'attente
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:735)
at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:677)
at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:436)
at com.couchbase.client.CouchbaseConnection.run(CouchbaseConnection.java:324)
2014-07-04 17:28:08.534 INFO com.couchbase.client.ViewConnection: I/O reactor terminated
Java代碼:
包com.t2s.injector;
import com.couchbase.client.CouchbaseClient;
import com.couchbase.client.protocol.views.Query;
import com.couchbase.client.protocol.views.View;
import com.couchbase.client.protocol.views.ViewResponse;
import com.couchbase.client.protocol.views.ViewRow;
import com.google.gson.Gson;
import com.t2s.injector.data.User;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
public class Injector {
public static void main(String[] args) throws Exception {
System.out.println("Starting...");
try {
CouchbaseClient client = createClient("Users", "54.247.158.182");//, "54.74.200.186");
try {
insertData(client);
} catch (Exception e) {
e.printStackTrace();
}
try {
queryView(client, "users", "by_firstname");
} catch (Exception e) {
e.printStackTrace();
}
// Shutting down properly
client.shutdown(5, TimeUnit.SECONDS);
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
private static CouchbaseClient createClient(String bucket, String... ips) throws URISyntaxException, IOException {
// (Subset) of nodes in the cluster to establish a connection
Integer port = 8091;
List<URI> nodes = new ArrayList<>();
for (String ip : ips) {
nodes.add(new URI("http://" + ip + ":" + port + "/pools"));
}
// Password of the bucket (empty) string if none
String password = "";
// Connect to the Cluster
CouchbaseClient client = new CouchbaseClient(nodes, bucket, password);
System.out.println("Connected to " + client);
return client;
}
private static void insertData(CouchbaseClient client) throws InterruptedException, ExecutionException {
Gson gson = new Gson();
User user1 = new User("John", "Doe");
User user2 = new User("Matt", "Ingenthron");
User user3 = new User("Michael", "Nitschinger");
client.set("user101", gson.toJson(user1)).get();
client.set("user201", gson.toJson(user2)).get();
client.set("user301", gson.toJson(user3)).get();
}
private static void queryView(CouchbaseClient client, String designDoc, String viewName) {
/*
function (doc, meta) {
if(doc.firstname) {
emit(doc.firstname, doc.lastname);
}
}
*/
// 1: Load the View infos
View view = client.getView(designDoc, viewName);
// 2: Create a Query object to customize the Query
Query query = new Query();
query.setIncludeDocs(true); // Include the full document body
// 3: Actually Query the View and return the results
ViewResponse response = client.query(view, query);
// 4: Iterate over the Data and print out the full document
for (ViewRow row : response) {
System.out.println(row.getId() + ": " + row.getDocument());
}
}
}
我正在使用企業版 –