尝试使用以下命令在现有 Cloud SQL 实例上添加高可用性时:
gcloud sql instances patch $INSTANCE --project $PROJECT --availability-type regional
进程失败并显示此消息
The following message will be used for the patch API method.
{"project": "$PROJECT", "name": "$INSTANCE", "settings": {"availabilityType": "REGIONAL", "databaseFlags": [{"name": "sql_mode", "value": "TRADITIONAL"}, {"name": "default_time_zone", "value": "+01:00"}]}}
ERROR: (gcloud.sql.instances.patch) HTTPError 400: The incoming request contained invalid data.
使用 Web 界面也会失败。 云版Google Cloud SDK [280.0.0]
这是日志的输出(我看不到太多帮助(:
2020-02-14 11:01:34,476 DEBUG root Loaded Command Group: [u'gcloud', u'sql', u'instances']
2020-02-14 11:01:34,510 DEBUG root Loaded Command Group: [u'gcloud', u'sql', u'instances', u'patch']
2020-02-14 11:01:34,517 DEBUG root Running [gcloud.sql.instances.patch] with arguments: [--availability-type: "regional", --project: "$PROJECT", INSTANCE: "$INSTANCE"]
2020-02-14 11:01:35,388 INFO ___FILE_ONLY___ The following message will be used for the patch API method.
2020-02-14 11:01:35,398 INFO ___FILE_ONLY___ {"project": "$PROJECT", "name": "$INSTANCE", "settings": {"availabilityType": "REGIONAL", "databaseFlags": [{"name": "sql_mode", "value": "TRADITIONAL"}, {"name": "default_time_zone", "value": "+01:00"}]}}
2020-02-14 11:01:35,865 DEBUG root (gcloud.sql.instances.patch) HTTPError 400: The incoming request contained invalid data.
Traceback (most recent call last):
File "C:UsersudALAppDataLocalGoogleCloud SDKgoogle-cloud-sdklibgooglecloudsdkcalliopecli.py", line 981, in Execute
resources = calliope_command.Run(cli=self, args=args)
File "C:UsersudALAppDataLocalGoogleCloud SDKgoogle-cloud-sdklibgooglecloudsdkcalliopebackend.py", line 807, in Run
resources = command_instance.Run(args)
File "C:UsersudALAppDataLocalGoogleCloud SDKgoogle-cloud-sdklibsurfacesqlinstancespatch.py", line 306, in Run
return RunBasePatchCommand(args, self.ReleaseTrack())
File "C:UsersudALAppDataLocalGoogleCloud SDKgoogle-cloud-sdklibsurfacesqlinstancespatch.py", line 278, in RunBasePatchCommand
instance=instance_ref.instance))
File "C:UsersudALAppDataLocalGoogleCloud SDKgoogle-cloud-sdklibgooglecloudsdkthird_partyapissqlv1beta4sql_v1beta4_client.py", line 697, in Patch
config, request, global_params=global_params)
File "C:UsersudALAppDataLocalGoogleCloud SDKgoogle-cloud-sdkbin..libthird_partyapitoolsbasepybase_api.py", line 731, in _RunMethod
return self.ProcessHttpResponse(method_config, http_response, request)
File "C:UsersudALAppDataLocalGoogleCloud SDKgoogle-cloud-sdkbin..libthird_partyapitoolsbasepybase_api.py", line 737, in ProcessHttpResponse
self.__ProcessHttpResponse(method_config, http_response, request))
File "C:UsersudALAppDataLocalGoogleCloud SDKgoogle-cloud-sdkbin..libthird_partyapitoolsbasepybase_api.py", line 604, in __ProcessHttpResponse
http_response, method_config=method_config, request=request)
HttpBadRequestError: HttpError accessing <https://sqladmin.googleapis.com/sql/v1beta4/projects/$PROJECT/instances/$INSTANCE?alt=json>: response: <{'status': '400', 'content-length': '269', 'x-xss-protection': '0', 'x-content-type-options': 'nosniff', 'transfer-encoding': 'chunked', 'vary': 'Origin, X-Origin, Referer', 'server': 'ESF', '-content-encoding': 'gzip', 'cache-control': 'private', 'date': 'Fri, 14 Feb 2020 10:01:35 GMT', 'x-frame-options': 'SAMEORIGIN', 'alt-svc': 'quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000', 'content-type': 'application/json; charset=UTF-8'}>, content <{
"error": {
"code": 400,
"message": "The incoming request contained invalid data.",
"errors": [
{
"message": "The incoming request contained invalid data.",
"domain": "global",
"reason": "invalidRequest"
}
]
}
}
>
2020-02-14 11:01:35,868 ERROR root (gcloud.sql.instances.patch) HTTPError 400: The incoming request contained invalid data.
2020-02-14 11:01:35,898 DEBUG root Metrics reporting process started...
编辑:
使用 gcloud cli 命令时:
具有 3 个输入参数的 GCLOUD 补丁
- $PROJECT和$INSTANCE都存在,因为我可以
gcloud sql databases list --instance $INSTANCE --project $PROJECT
并且工作正常。 - 可用性类型=区域 它有记录,所以应该工作
我没有手动构建请求,我使用的是 gcloud CLI
使用 console.cloud.google.com Web 界面时:
主菜单 -> SQL ->选择实例->启用高可用性。 这是一个按钮,没有我自己添加的参数。
两者都返回相同的错误"传入请求包含无效数据"。 看不出我怎么可能做错了。
请检查传入请求中的数据。
我使用了方法:实例.patch,它为我按预期工作。
project
instance-name
request body
:
"settings": {
"availabilityType": "REGIONAL",
"databaseFlags": [
{
"name": "sql_mode",
"value": "TRADITIONAL"
},
{
"name": "default_time_zone",
"value": "+01:00"
}
]
}
}
卷曲命令:
'https://sqladmin.googleapis.com/sql/v1beta4/projects/your-project/instances/your_instancet?key=[YOUR_API_KEY]'
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]'
--header 'Accept: application/json'
--header 'Content-Type: application/json'
--data '{"settings":{"availabilityType":"REGIONAL","databaseFlags":[{"name":"sql_mode","value":"TRADITIONAL"},{"name":"default_time_zone","value":"+01:00"}]}}'
--compressed```
响应 200:
{
"kind": "sql#operation",
"targetLink": "https://content-sqladmin.googleapis.com/sql/v1beta4/projects/your-project/instances/your-instance",
"status": "PENDING",
"user": "@cloud.com",
"insertTime": "2020-02-14T12:35:37.615Z",
"operationType": "UPDATE",
"name": "3f55c1be-97b5-4d37-8d1f-15cb61b4c6cc",
"targetId": "your-instance",
"selfLink": "https://content-sqladmin.googleapis.com/sql/v1beta4/projects/wave25-vladoi/operations/3f55c1be-97b5-4d37-8d1f-15cb61b4c6cc",
"targetProject": "your-project"
}