Bucket cant be accessed when using N1QL

Hi All,

I encountered a problem that the bucket is inaccessible when using N1QL(either JAVA API and neither CQB), but it is accessible when using bucket.get(). Interestingly, the bucket is visible when using the web portal, and so does the document in the bucket.

The error message got from the server is “code”: 12003, “msg”: "Keyspace not found keyspace XXXX.

The bucket is password protected, and I am not sure about if this causes the problem as I have googled something form the internet, stating that due to the password,

In addition, I use the cbq and got the same error code and message.

My development is listed in below

JAVA JDK 1.7
JAVA SDK 2.1
Couchbase 4.0 and this is installed on the ubuntu system

Can somebody pitch a help? Many thanks.

What is your bucket name? may be you can try to using bucket_name to escape special characters.

There is no special characters.

There are two buckets in the couchbase with the name ChartFlow and ChartFlowPhoto. I was trying to use N1QL to create index on it, but it still got the problem.

In quote of “may be you can try to using bucket_name to escape special characters.”, do you recommend me that I should use bucket_ChartFlow and bucket_ChartFlowPhoto?

Many thanks

sorry, My mistake, I means you may be can try using `bucket-name`.
what the result of execute

SELECT * FROM system:keyspaces;

in cbq?

This is result from your sentence. It seems that the databases I need are not returned.

{
“requestID”: “1ab6bf40-cde9-4ba5-990b-09bcc5423585”,
“signature”: {
"": ""
},
“results”: [
{
“keyspaces”: {
“datastore_id”: “http://127.0.0.1:8091”,
“id”: “travel-sample”,
“name”: “travel-sample”,
“namespace_id”: “default”
}
},
{
“keyspaces”: {
“datastore_id”: “http://127.0.0.1:8091”,
“id”: “default”,
“name”: “default”,
“namespace_id”: “default”
}
}
],
“status”: “success”,
“metrics”: {
“elapsedTime”: “1.096691626s”,
“executionTime”: “1.089245551s”,
“resultCount”: 2,
“resultSize”: 450
}
}

How do you create the bucket? Using Couchbase Console, or by some SDK?

Yes, I used them both. That is saying, I used CBQ and JAVA SDK to employ the same sentence to retrive the document.

The java code is listed below.

this.env = DefaultCouchbaseEnvironment
.builder()
.connectTimeout(20000)
.queryEnabled(true)
.kvTimeout(20000)
.sslEnabled(false)
.build();

this.serviceURL = “192.168.80.151”;
this.buckName1 = “bucket1”;
this.buckName2 = “bucket2”;
this.buckPswd1 = “1234”;
this.buckPswd2 = “1234”;

this.cluster = CouchbaseCluster.create( this.env , this.serviceURL );
this.bucket1 = cluster.openBucket( this.buckName1 , this.buckPswd1);
this.bucket2 = cluster.openBucket( this.buckName2 , this.buckPswd2);

// below it never gets a right answer form the couchbase server
QueryResult queryResult = bucket1.query( statements.get(0) );

Iterator rows = queryResult.rows();

while( rows.hasNext() ){
def archiveInstanceContent = new JSONObject( rows.next().toString() );
arrayOfChartFlowInstances.push( archiveInstanceContent );
}

The actual exection is in the QueryResult queryResult = bucket1.query( statements.get(0) );. I taked it out the statements.get(0) and put it into the CBQ, and got the same error code saying that bucket1 or bucket2 are missing from the name space.

if you are using n1ql in java sdk instead of bucket.query ,you should use bucket.n1qlQuery and also check java sdk, it has to be above 2.1.5

Hi

is there any n1qlQuery function in the bucket?

I have download the lastest API and there is such a function.

Many thanks.

i guess you got the solution?

Sorry. There is typo in it.

There is no such a function, and the publem is still there.

Remove the password from the bucket and then try it out, I hope it works :slight_smile:

1 Like

Yes, it works in such a way. But I not sure that we should sacrifice the security to get this?

So how are you passing the password in the n1ql query.? I tried it sometime before but didn’t find a way .! Please share some code.

I guess there is no way to pass the password in N1QL.

we use the virtual network to hide the couchbase from the public, and leave the no password on the bucket.
:stuck_out_tongue_winking_eye:

I’m also facing the same problem with N1ql queries now. Weird thing is that it was working fine till the last restart of the server and suddenly it started throwing this error.

I’m launching cbq tool with this param : -engine="http://user:password@host:8093/

N1ql query throws an error that the keyspace not found. If I remove the authentication, it works fine. But what do I do get it working again with authentication?

I got same problem. After restart, it suddenly failed with error code: 12003 keyspace not found. I tried in Query GUI (I use CB 4.5 Beta), same problem. If I remove the password, everything works. So this is not a problem in java code.

Hello, I have seen this problem a few times, but I’ve had trouble reproducing it, and it always went away after server restart. How consistently are you able to reproduce it? You might be able to help us debug it.

For me, when the bucket had a password, it would not appear in the list of ‘select * from system:keyspaces’, but if I removed the password, it would appear again. Do you see that?

Thank you!

When running queries against protected buckets, you can’t access/perform any operation on the bucket unless the query has the bucket auth credentials. There are 2 ways for the query engine to get this information.

  • It can either use the user credentials (Administrator password)
  • or the protected bucket credentials.

If it contains the user credentials, for example Administrator password, then it will be able to discover all the authenticated buckets in /pools.

This means that query is a trusted service but query clients aren’t, therefore, for the clients to access the protected buckets they need provide the right credentials.

Let’s say that your cluster’s Administrator password is “c_password” and your “default” bucket has a password of “b_password”.

There are 2 ways to allow access / see the buckets when querying

Using the new cbq shell in Couchbase 4.5 :

  • Using –u –p
    $ ./cbq –e=couchbase://127.0.0.1 –u=Administrator -p=c_password
    cbq > select * from system:keyspaces;
    (This will list all buckets including protected buckets)

  • Using –creds
    $ ./cbq –e=couchbase://127.0.0.1
    cbq > select * from system:keyspaces;
    (This will list only non protected buckets)

    cbq > \SET -creds default:b_password;
    (This will list all buckets including protected bucket default)

Using the rest api:

  • Using the admin credentials :
    curl -v http://localhost:8093/query/service -d ‘statement=select * from system:keyspaces&creds=[{“user”:“Administrator”, “pass”:“c_password”}]’

  • Using bucket credentials :
    curl -v http://localhost:8093/query/service -d ‘statement=select * from system:keyspaces&creds=[{“user”:“default”, “pass”:“b_password”}]’

Thanks

Hi Isha,

I don’t believe this issue relates to credentials. I’ve spent all day with versions 4.0 and 4.5, and in every case “select * from system:keyspaces” returns the name of every bucket, whether or not it has a password, whether from cbq or the 4.5 query workbench. Furthermore, when I try to access a password-protected bucket without credentials, the error I see is 10000 - Authorization Failed.

In contrast, with the behavior that I and the users above experienced, a password-protected bucket no longer shows up in ‘select * from system:keyspaces’, and referring to it yields error 12003 - Keyspace not found.

So I think we have a real bug here, we just need to figure out how to reproduce it. Perhaps one of the people above can provide log files.

-Eben