问题
I am not able to Create primary index on couchbase using groovy script. Below are the lines of code I used:-
@Grab('com.couchbase.client:java-client:2.2.6')
import java.util.concurrent.CountDownLatch;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.document.json.JsonObject;
import com.couchbase.client.java.CouchbaseCluster
import com.couchbase.client.java.query.N1qlQuery;
import com.couchbase.client.java.query.N1qlQueryResult;
import com.couchbase.client.java.query.N1qlQueryRow;
import com.couchbase.client.java.query.SimpleN1qlQuery;
import com.couchbase.client.java.env.CouchbaseEnvironment;
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder().connectTimeout(10000).build();
def cluster = CouchbaseCluster.create(env, IPADDRESS);
def bucket = cluster.openBucket(BUCKET_NAME, BUCKET_PASSWORD);
log.info "Connection done"
String queryString = "CREATE PRIMARY INDEX `PrimInd` ON BUCKET_NAME"
bucket.query(N1qlQuery.simple(queryString))
log.info "Primary index created"
It gives me error as below :-
java.lang.RuntimeException: java.util.concurrent.TimeoutException at this line:-
bucket.query(N1qlQuery.simple(queryString))
Connection is being done properly and same query works in couchbase server. So, I think there is problem with my code.
Could you please help me on this?
回答1:
In the Couchbase Java client, the query()
method delegates to a Blocking
API which uses JavaRx under the covers. The source code for the Blocking API states:
If an error happens inside the
Observable
, it will be raised as anException
. If the timeout kicks in, aTimeoutException
nested in aRuntimeException
is thrown to be fully compatible with theObservable.timeout(long, TimeUnit)
behavior.
You're experiencing a TimeoutException
nested in a RuntimeException
, hence the root cause is that your query is timing out.
DefaultCouchbaseEnvironment
defaults to a queryTimeout (the timeout used for N1qlQuery queries) of 75 milli-seconds. You can change this default with the environment builder:
def env = DefaultCouchbaseEnvironment.builder()
.connectTimeout(10000)
.queryTimeout(10000) // This is the query timeout
.build()
来源:https://stackoverflow.com/questions/48986045/unable-to-create-primary-index-on-couchbase-using-groovy-script