Description
Summary
SearchQuery (FTS) ops do not work in the 2.x Go SDK without sleeping for a while beforehand, if the cluster doesn't support GCCCP (i.e. is <6.5.0).
Steps to Reproduce
- Create a single node 6.0.3 cluster running KV and Search.
- Load the travel-sample bucket onto the cluster
- Create an FTS index, the default (i.e. just click 'Create Index') is sufficient to demonstrate the issue
- Run an FTS search from the Go SDK, ensuring to follow the advice in the documentation:
I have attached an example self-contained reproduction case as main.go, and the logs as no_sleep.log.When using a Couchbase version < 6.5 you must create a valid Bucket connection using cluster.Bucket(name) before you can use Search.
Expected Results
The search results are returned successfully.
Actual Results
The application panics due to the following error:
panic: failed to get query provider: not connected to cluster | {"query":{"match":"swanky"}}
|
Analysis
This seems to not work after opening a bucket, then immediately performing a search.
There are 2 ways to get this to work, one is to perform some KV ops on the default collection, which forces the connections to open.
The other is to sleep the calling goroutine for a bit (e.g. 5 seconds), if you sleep then the search works and you don't even need the default collection to be opened.
I've attached logs with the sleep as with_sleep.log to demonstrate the difference.
I suspect there's not appropriate handling within the SearchQuery code to wait for a cluster that's still initializing if the cluster does not support GCCCP.
Workaround
Wait until the bucket object is ready to have operations performed against it, this can be done using the Bucket.WaitUntilReady() API.
For example:
bucket := cluster.Bucket("travel-sample")
|
bucket.WaitUntilReady(30 * time.Second, &gocb.WaitUntilReadyOptions{DesiredState: gocb.ClusterStateOnline})
|
|
matchResult, err := cluster.SearchQuery(
|
"travel-sample-index-hotel-description",
|
search.NewMatchQuery("swanky"),
|
&gocb.SearchOptions{
|
Limit: 10,
|
},
|
)
|
Attachments
Issue Links
- relates to
-
GOCBC-879 Cluster level ops can error in weird ways if used before connections initialized
- Resolved