Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-47572

[BAR] udf is not excluded during restore using --exclude-data option

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 7.0.1
    • 7.0.2
    • query
    • Centos7
      7.0.1-5956-enterprise
    • Untriaged
    • 1
    • Unknown

    Description

      To repro:

      • create bucket1 and bucket2
      • create scope/collections:
        • create scope bucket1.scope1;
        • create scope bucket2.scope2;
        • create collection bucket1.scope1.collection1;
        • create collection bucket2.scope2.collection2;
      • create UDF:
        • CREATE FUNCTION func1() { 0 };
        • CREATE FUNCTION default:bucket1.scope1.func1() { 0 };
        • CREATE FUNCTION default:bucket2.scope2.func1() { 0 };
      • Check system cat:
        • select f.identity.name, f.identity.type, f.identity.`scope` from system:functions as f;
      • Backup:
        • ./cbbackupmgr config -a /backup-1 -r my_backup
        • ./cbbackupmgr backup -a /backup-1 -r my_backup -c http://localhost:8091 -u Administrator -p password
      • Drop functions:
        • drop function default:bucket1.scope1.func1;
        • drop function default:bucket2.scope2.func1;
      • Restore with exclude
        • ./cbbackupmgr restore -a /backup-1 -r my_backup -c http://localhost:8091 -u Administrator -p password --exclude-data bucket2.scope2.collection2
        • or
        • ./cbbackupmgr restore -a /backup-1 -r my_backup -c http://localhost:8091 -u Administrator -p password --exclude-data bucket2.scope2
      • Check system cat:
        • select f.identity.name, f.identity.type, f.identity.`scope` from system:functions as f;

      Post restore I still see both func1 for scope1 and scope2 present:

      cbq> select f.identity.name, f.identity.type, f.identity.`scope` from system:functions as f;
      {
          "requestID": "f5a86000-9744-4410-ac02-881a9ecfacc4",
          "signature": {
              "name": "json",
              "scope": "json",
              "type": "json"
          },
          "results": [
          {
              "name": "func1",
              "scope": "scope2",
              "type": "scope"
          },
          {
              "name": "func1",
              "scope": "scope1",
              "type": "scope"
          },
          {
              "name": "func1",
              "type": "global"
          } 

      Attachments

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

        Activity

          james.lee James Lee added a comment -

          Hi Pierre Regazzoni,

          I don't believe this is an issue with 'cbbackupmgr', from what I can see (from my local reproduction) it's behaving as defined. By this I mean that we're 'POST'ing the Query UDF payload to the Query service with the query parameters 'exclude=scope' (please note that the filtering/remapping should be happening at the service level).

          The following steps are those which I used to reproduce:
          1) Spin up a single node cluster running KV + Index + N1QL
          2) Load the 'travel-sample' bucket
          3) Create a scope level function using e.g. '{{CREATE FUNCTION default:`travel-sample`.inventory.to_meters(...)

          { args[0] * 0.3048 }

          ;}}'
          4) Perform a backup
          4a) Validate that we see the function definition in the backup bucket directory (should be in a 'query.json' file)
          5) Delete the 'travel-sample' bucket
          6) Perform a restore using the '--auto-create-buckets' and '--exclude-data travel-sample.inventory' flags

          We should see a failure such as the one below:

          500 Status Code

          Error restoring cluster: internal server error executing 'POST' request to '/api/v1/bucket/travel-sample/backup': {"caller":"admin_accounting_endpoint:1208","code":1040,"icause":"Invalid function name default:travel-sample.inventory.to_meters - cause: Scope not found in CB datastore default:travel-sample.inventory","key":"service.io.request.bad_value","message":"Error processing UDF restore body"}
          

          This is because Query is attempting to use a scope which 'cbbackupmgr' didn't bother creating (since it wasn't going to be used). In theory this is the same behavior observed by Pierre Regazzoni i.e. no filtering is taking place.

          To validate that we're behaving as expected, I captured a PCAP of the HTTP traffic, in which we see the following requests:

          HTTP Requests

          1	0.000000	::1	::1	HTTP/JSON	559	39800	9499	POST /api/v1/bucket/travel-sample/backup?exclude=inventory HTTP/1.1 , JavaScript Object Notation (application/json)
          2	0.000942	::1	::1	HTTP/JSON	559	39802	9499	POST /api/v1/bucket/travel-sample/backup?exclude=inventory HTTP/1.1 , JavaScript Object Notation (application/json)
          3	0.001604	::1	::1	HTTP/JSON	559	39804	9499	POST /api/v1/bucket/travel-sample/backup?exclude=inventory HTTP/1.1 , JavaScript Object Notation (application/json)
          

          We see three separate requests since each failed with a 500 status code (which is retried by our REST client). In each case, we can see we're correctly indicating that we're not transferring any data for the 'inventory' scope.

          Removing 'tools' and assigning to 'query'.

          Thanks,
          James

          james.lee James Lee added a comment - Hi Pierre Regazzoni , I don't believe this is an issue with ' cbbackupmgr ', from what I can see (from my local reproduction) it's behaving as defined. By this I mean that we're ' POST 'ing the Query UDF payload to the Query service with the query parameters ' exclude=scope ' (please note that the filtering/remapping should be happening at the service level). The following steps are those which I used to reproduce: 1) Spin up a single node cluster running KV + Index + N1QL 2) Load the ' travel-sample ' bucket 3) Create a scope level function using e.g. '{{CREATE FUNCTION default:`travel-sample`.inventory.to_meters(...) { args[0] * 0.3048 } ;}}' 4) Perform a backup 4a) Validate that we see the function definition in the backup bucket directory (should be in a ' query.json ' file) 5) Delete the ' travel-sample ' bucket 6) Perform a restore using the ' --auto-create-buckets ' and ' --exclude-data travel-sample.inventory ' flags We should see a failure such as the one below: 500 Status Code Error restoring cluster: internal server error executing 'POST' request to '/api/v1/bucket/travel-sample/backup': {"caller":"admin_accounting_endpoint:1208","code":1040,"icause":"Invalid function name default:travel-sample.inventory.to_meters - cause: Scope not found in CB datastore default:travel-sample.inventory","key":"service.io.request.bad_value","message":"Error processing UDF restore body"} This is because Query is attempting to use a scope which ' cbbackupmgr ' didn't bother creating (since it wasn't going to be used). In theory this is the same behavior observed by Pierre Regazzoni i.e. no filtering is taking place. To validate that we're behaving as expected, I captured a PCAP of the HTTP traffic, in which we see the following requests: HTTP Requests 1 0.000000 ::1 ::1 HTTP/JSON 559 39800 9499 POST /api/v1/bucket/travel-sample/backup?exclude=inventory HTTP/1.1 , JavaScript Object Notation (application/json) 2 0.000942 ::1 ::1 HTTP/JSON 559 39802 9499 POST /api/v1/bucket/travel-sample/backup?exclude=inventory HTTP/1.1 , JavaScript Object Notation (application/json) 3 0.001604 ::1 ::1 HTTP/JSON 559 39804 9499 POST /api/v1/bucket/travel-sample/backup?exclude=inventory HTTP/1.1 , JavaScript Object Notation (application/json) We see three separate requests since each failed with a 500 status code (which is retried by our REST client). In each case, we can see we're correctly indicating that we're not transferring any data for the ' inventory ' scope. Removing ' tools ' and assigning to ' query '. Thanks, James

          Build couchbase-server-7.0.1-5963 contains query commit 0f7f28a with commit message:
          MB-47572 MB-47573 exclude and remap work incorrectly

          build-team Couchbase Build Team added a comment - Build couchbase-server-7.0.1-5963 contains query commit 0f7f28a with commit message: MB-47572 MB-47573 exclude and remap work incorrectly

          Build couchbase-server-7.1.0-1098 contains query commit 3dbc3bd with commit message:
          MB-47572 MB-47573 exclude and remap work incorrectly

          build-team Couchbase Build Team added a comment - Build couchbase-server-7.1.0-1098 contains query commit 3dbc3bd with commit message: MB-47572 MB-47573 exclude and remap work incorrectly

          Verified with exclude bucket.scope or exclude bucket seems to work ... Marco Greco can you also confirm that when using  --exclude-data bucket2.scope2.collection2 it should have not effect on scope2 UDFs.

          # ./cbbackupmgr restore -a /backup-1 -r my_backup -c http://localhost:8091 -u Administrator -p password --exclude-data bucket2.scope2
          Restoring backup '2021-07-28T00_25_28.520646058-07_00'
          Copied all data in 1.187s (Avg. 84.00KiB/Sec)                                                                                             0 items / 84.00KiB
          [==================================================================================================================================================] 100.00%
           
           
          | Transfer
          | --------
          | Status    | Avg Transfer Rate | Started At                        | Finished At                     | Duration |
          | Succeeded | 84.00KiB          | Wed, 28 Jul 2021 00:31:19 -0700/s | Wed, 28 Jul 2021 00:31:20 -0700 | 1.238s   |
           
           
          | Bucket
          | ------
          | Name    | Status    | Transferred | Avg Transfer Rate | Started At                      | Finished At                     | Duration |
          | default | Succeeded | 28.00KiB    | 28.00KiB/s        | Wed, 28 Jul 2021 00:31:19 -0700 | Wed, 28 Jul 2021 00:31:19 -0700 | 53ms     |
          |
          | Mutations                    | Deletions                    | Expirations                  |
          | ---------                    | ---------                    | -----------                  |
          | Received | Errored | Skipped | Received | Errored | Skipped | Received | Errored | Skipped |
          | 0        | 0       | 0       | 0        | 0       | 0       | 0        | 0       | 0       |
           
           
          | Bucket
          | ------
          | Name    | Status    | Transferred | Avg Transfer Rate | Started At                      | Finished At                     | Duration |
          | bucket1 | Succeeded | 28.00KiB    | 28.00KiB/s        | Wed, 28 Jul 2021 00:31:20 -0700 | Wed, 28 Jul 2021 00:31:20 -0700 | 51ms     |
          |
          | Mutations                    | Deletions                    | Expirations                  |
          | ---------                    | ---------                    | -----------                  |
          | Received | Errored | Skipped | Received | Errored | Skipped | Received | Errored | Skipped |
          | 0        | 0       | 0       | 0        | 0       | 0       | 0        | 0       | 0       |
           
           
          | Bucket
          | ------
          | Name    | Status    | Transferred | Avg Transfer Rate | Started At                      | Finished At                     | Duration |
          | bucket2 | Succeeded | 28.00KiB    | 28.00KiB/s        | Wed, 28 Jul 2021 00:31:20 -0700 | Wed, 28 Jul 2021 00:31:20 -0700 | 51ms     |
          |
          | Mutations                    | Deletions                    | Expirations                  |
          | ---------                    | ---------                    | -----------                  |
          | Received | Errored | Skipped | Received | Errored | Skipped | Received | Errored | Skipped |
          | 0        | 0       | 0       | 0        | 0       | 0       | 0        | 0       | 0       |
           
           
          Restore completed successfully
          [root@cluster bin]# ./cbq -u Administrator -p password
           Connected to : http://localhost:8091/. Type Ctrl-D or \QUIT to exit.
           
           
           Path to history file for the shell : /root/.cbq_history 
          cbq> select f.identity.name, f.identity.type, f.identity.`scope`, definition.`#language` from system:functions as f;
          {
              "requestID": "db4d2457-f2b1-40cd-8fa4-cde09db9c078",
              "signature": {
                  "#language": "json",
                  "name": "json",
                  "scope": "json",
                  "type": "json"
              },
              "results": [
              {
                  "#language": "inline",
                  "name": "func1",
                  "type": "global"
              },
              {
                  "#language": "inline",
                  "name": "func1",
                  "scope": "scope1",
                  "type": "scope"
              }
              ],
              "status": "success",
              "metrics": {
                  "elapsedTime": "10.888534ms",
                  "executionTime": "10.663115ms",
                  "resultCount": 2,
                  "resultSize": 202,
                  "serviceLoad": 6
              }
          } 

          pierre.regazzoni Pierre Regazzoni added a comment - Verified with exclude bucket.scope or exclude bucket seems to work ... Marco Greco  can you also confirm that when using  --exclude-data bucket2.scope2.collection2 it should have not effect on scope2 UDFs. # ./cbbackupmgr restore -a /backup- 1 -r my_backup -c http: //localhost:8091 -u Administrator -p password --exclude-data bucket2.scope2 Restoring backup '2021-07-28T00_25_28.520646058-07_00' Copied all data in 1 .187s (Avg. 84 .00KiB/Sec)                                                                                             0 items / 84 .00KiB [==================================================================================================================================================] 100.00 %     | Transfer | -------- | Status    | Avg Transfer Rate | Started At                        | Finished At                     | Duration | | Succeeded | 84 .00KiB          | Wed, 28 Jul 2021 00 : 31 : 19 - 0700 /s | Wed, 28 Jul 2021 00 : 31 : 20 - 0700 | 1 .238s   |     | Bucket | ------ | Name    | Status    | Transferred | Avg Transfer Rate | Started At                      | Finished At                     | Duration | | default | Succeeded | 28 .00KiB    | 28 .00KiB/s        | Wed, 28 Jul 2021 00 : 31 : 19 - 0700 | Wed, 28 Jul 2021 00 : 31 : 19 - 0700 | 53ms     | | | Mutations                    | Deletions                    | Expirations                  | | ---------                    | ---------                    | -----------                  | | Received | Errored | Skipped | Received | Errored | Skipped | Received | Errored | Skipped | | 0         | 0       | 0       | 0         | 0       | 0       | 0         | 0       | 0       |     | Bucket | ------ | Name    | Status    | Transferred | Avg Transfer Rate | Started At                      | Finished At                     | Duration | | bucket1 | Succeeded | 28 .00KiB    | 28 .00KiB/s        | Wed, 28 Jul 2021 00 : 31 : 20 - 0700 | Wed, 28 Jul 2021 00 : 31 : 20 - 0700 | 51ms     | | | Mutations                    | Deletions                    | Expirations                  | | ---------                    | ---------                    | -----------                  | | Received | Errored | Skipped | Received | Errored | Skipped | Received | Errored | Skipped | | 0         | 0       | 0       | 0         | 0       | 0       | 0         | 0       | 0       |     | Bucket | ------ | Name    | Status    | Transferred | Avg Transfer Rate | Started At                      | Finished At                     | Duration | | bucket2 | Succeeded | 28 .00KiB    | 28 .00KiB/s        | Wed, 28 Jul 2021 00 : 31 : 20 - 0700 | Wed, 28 Jul 2021 00 : 31 : 20 - 0700 | 51ms     | | | Mutations                    | Deletions                    | Expirations                  | | ---------                    | ---------                    | -----------                  | | Received | Errored | Skipped | Received | Errored | Skipped | Received | Errored | Skipped | | 0         | 0       | 0       | 0         | 0       | 0       | 0         | 0       | 0       |     Restore completed successfully [root @cluster bin]# ./cbq -u Administrator -p password  Connected to : http: //localhost:8091/. Type Ctrl-D or \QUIT to exit.      Path to history file for the shell : /root/.cbq_history  cbq> select f.identity.name, f.identity.type, f.identity.`scope`, definition.`#language` from system:functions as f; {     "requestID" : "db4d2457-f2b1-40cd-8fa4-cde09db9c078" ,     "signature" : {         "#language" : "json" ,         "name" : "json" ,         "scope" : "json" ,         "type" : "json"     },     "results" : [     {         "#language" : "inline" ,         "name" : "func1" ,         "type" : "global"     },     {         "#language" : "inline" ,         "name" : "func1" ,         "scope" : "scope1" ,         "type" : "scope"     }     ],     "status" : "success" ,     "metrics" : {         "elapsedTime" : "10.888534ms" ,         "executionTime" : "10.663115ms" ,         "resultCount" : 2 ,         "resultSize" : 202 ,         "serviceLoad" : 6     } }
          marco.greco Marco Greco added a comment -

          yes, excluding a collection does not affect the functions in the scope.

          marco.greco Marco Greco added a comment - yes, excluding a collection does not affect the functions in the scope.

          Verified on 7.0.1-5963

          pierre.regazzoni Pierre Regazzoni added a comment - Verified on 7.0.1-5963

          People

            pierre.regazzoni Pierre Regazzoni
            pierre.regazzoni Pierre Regazzoni
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty