Uploaded image for project: 'Couchbase Go SDK'
  1. Couchbase Go SDK
  2. GOCBC-890

SearchQueries do not work on non-GCCCP clusters without waiting

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.0
    • Fix Version/s: 2.1.2
    • Component/s: library
    • Labels:
      None
    • Story Points:
      1

      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

      1. Create a single node 6.0.3 cluster running KV and Search.
      2. Load the travel-sample bucket onto the cluster
      3. Create an FTS index, the default (i.e. just click 'Create Index') is sufficient to demonstrate the issue
      4. Run an FTS search from the Go SDK, ensuring to follow the advice in the documentation:

        When using a Couchbase version < 6.5 you must create a valid Bucket connection using cluster.Bucket(name) before you can use Search.

        I have attached an example self-contained reproduction case as main.go, and the logs as no_sleep.log.

      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

        1. main.go
          1.0 kB
        2. no_sleep.log
          3 kB
        3. with_sleep.log
          23 kB

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

            matt.carabine Matt Carabine created issue -
            matt.carabine Matt Carabine made changes -
            Field Original Value New Value
            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|https://docs.couchbase.com/go-sdk/current/howtos/full-text-searching-with-sdk.html]:{quote}When using a Couchbase version < 6.5 you must create a valid Bucket connection using cluster.Bucket(name) before you can use Search.
            {quote} I have attached an example self-contained reproduction case as [^main.go], and the logs as [^no_sleep.log].

            +Expected Results+
            The search results are returned successfully.

            +Actual Results+
            The application panics due to the following error:{noformat}
            panic: failed to get query provider: not connected to cluster | {"query":{"match":"swanky"}}
            {noformat}

            +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.
            +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|https://docs.couchbase.com/go-sdk/current/howtos/full-text-searching-with-sdk.html]:{quote}When using a Couchbase version < 6.5 you must create a valid Bucket connection using cluster.Bucket(name) before you can use Search.
            {quote} I have attached an example self-contained reproduction case as [^main.go], and the logs as [^no_sleep.log].

            +Expected Results+
            The search results are returned successfully.

            +Actual Results+
            The application panics due to the following error:{noformat}
            panic: failed to get query provider: not connected to cluster | {"query":{"match":"swanky"}}
            {noformat}

            +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+
            matt.carabine Matt Carabine made changes -
            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|https://docs.couchbase.com/go-sdk/current/howtos/full-text-searching-with-sdk.html]:{quote}When using a Couchbase version < 6.5 you must create a valid Bucket connection using cluster.Bucket(name) before you can use Search.
            {quote} I have attached an example self-contained reproduction case as [^main.go], and the logs as [^no_sleep.log].

            +Expected Results+
            The search results are returned successfully.

            +Actual Results+
            The application panics due to the following error:{noformat}
            panic: failed to get query provider: not connected to cluster | {"query":{"match":"swanky"}}
            {noformat}

            +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+
            +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|https://docs.couchbase.com/go-sdk/current/howtos/full-text-searching-with-sdk.html]:{quote}When using a Couchbase version < 6.5 you must create a valid Bucket connection using cluster.Bucket(name) before you can use Search.
            {quote} I have attached an example self-contained reproduction case as [^main.go], and the logs as [^no_sleep.log].

            +Expected Results+
            The search results are returned successfully.

            +Actual Results+
            The application panics due to the following error:{noformat}
            panic: failed to get query provider: not connected to cluster | {"query":{"match":"swanky"}}
            {noformat}

            +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+

            Sleep until the cluster is ready, you could implement this using a retry mechanism for this specific error, below is a very basic example without any backoffs etc that you'd maybe want to use:{code}
                    for err != nil && strings.HasPrefix(err.Error(), "failed to get query provider: not connected to cluster") {
                            fmt.Println("Retrying as cluster not ready yet")
                            time.Sleep(100 * time.Millisecond)
                            matchResult, err = cluster.SearchQuery(
                                    "travel-sample-index-hotel-description",
                                    search.NewMatchQuery("swanky"),
                                    &gocb.SearchOptions{
                                            Limit: 10,
                                    },
                            )
                    }{code}
            matt.carabine Matt Carabine made changes -
            Link This issue blocks CBSE-8354 [ CBSE-8354 ]
            charles.dixon Charles Dixon made changes -
            Fix Version/s 2.1.2 [ 16797 ]
            charles.dixon Charles Dixon made changes -
            Assignee Brett Lawson [ brett19 ] Charles Dixon [ charles.dixon ]
            charles.dixon Charles Dixon made changes -
            Status New [ 10003 ] Open [ 1 ]
            charles.dixon Charles Dixon made changes -
            Link This issue relates to GOCBC-879 [ GOCBC-879 ]
            matt.carabine Matt Carabine made changes -
            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|https://docs.couchbase.com/go-sdk/current/howtos/full-text-searching-with-sdk.html]:{quote}When using a Couchbase version < 6.5 you must create a valid Bucket connection using cluster.Bucket(name) before you can use Search.
            {quote} I have attached an example self-contained reproduction case as [^main.go], and the logs as [^no_sleep.log].

            +Expected Results+
            The search results are returned successfully.

            +Actual Results+
            The application panics due to the following error:{noformat}
            panic: failed to get query provider: not connected to cluster | {"query":{"match":"swanky"}}
            {noformat}

            +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+

            Sleep until the cluster is ready, you could implement this using a retry mechanism for this specific error, below is a very basic example without any backoffs etc that you'd maybe want to use:{code}
                    for err != nil && strings.HasPrefix(err.Error(), "failed to get query provider: not connected to cluster") {
                            fmt.Println("Retrying as cluster not ready yet")
                            time.Sleep(100 * time.Millisecond)
                            matchResult, err = cluster.SearchQuery(
                                    "travel-sample-index-hotel-description",
                                    search.NewMatchQuery("swanky"),
                                    &gocb.SearchOptions{
                                            Limit: 10,
                                    },
                            )
                    }{code}
            +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|https://docs.couchbase.com/go-sdk/current/howtos/full-text-searching-with-sdk.html]:{quote}When using a Couchbase version < 6.5 you must create a valid Bucket connection using cluster.Bucket(name) before you can use Search.
            {quote} I have attached an example self-contained reproduction case as [^main.go], and the logs as [^no_sleep.log].

            +Expected Results+
            The search results are returned successfully.

            +Actual Results+
            The application panics due to the following error:{noformat}
            panic: failed to get query provider: not connected to cluster | {"query":{"match":"swanky"}}
            {noformat}

            +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|https://pkg.go.dev/github.com/couchbase/gocb/v2?tab=doc#Bucket.WaitUntilReady].

            For example:{code}
                    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,
                            },
                    ){code}
            charles.dixon Charles Dixon made changes -
            Resolution Fixed [ 1 ]
            Status Open [ 1 ] Resolved [ 5 ]

              People

              Assignee:
              charles.dixon Charles Dixon
              Reporter:
              matt.carabine Matt Carabine
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes

                    PagerDuty