Skip to content

Commit

Permalink
br: fix br debug encode panic (#40880) (#40891)
Browse files Browse the repository at this point in the history
close #40878
  • Loading branch information
ti-chi-bot authored Jan 31, 2023
1 parent a046a2d commit ac6560f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions br/pkg/utils/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ func makeJSONSchema(schema *backuppb.Schema) (*jsonSchema, error) {

func fromJSONSchema(jSchema *jsonSchema) (*backuppb.Schema, error) {
schema := jSchema.Schema
if schema == nil {
schema = &backuppb.Schema{}
}

var err error
schema.Db, err = json.Marshal(jSchema.DB)
if err != nil {
Expand Down
38 changes: 38 additions & 0 deletions br/pkg/utils/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,44 @@ var testMetaJSONs = [][]byte{
"is_raw_kv": true,
"br_version": "BR\nRelease Version: v5.0.0-master\nGit Commit Hash: c0d60dae4998cf9ac40f02e5444731c15f0b2522\nGit Branch: HEAD\nGo Version: go1.13.4\nUTC Build Time: 2021-03-25 08:10:08\nRace Enabled: false"
}`),
[]byte(`{
"files": [
{
"sha256": "3ae857ef9b379d498ae913434f1d47c3e90a55f3a4cd9074950bfbd163d5e5fc",
"start_key": "7480000000000000115f720000000000000000",
"end_key": "7480000000000000115f72ffffffffffffffff00",
"name": "1_20_9_36adb8cedcd7af34708edff520499e712e2cfdcb202f5707dc9305a031d55a98_1675066275424_write.sst",
"end_version": 439108573623222300,
"crc64xor": 16261462091570213000,
"total_kvs": 15,
"total_bytes": 1679,
"cf": "write",
"size": 2514,
"cipher_iv": "56MTbxA4CaNILpirKnBxUw=="
}
],
"schemas": [
{
"db": {
"charset": "utf8mb4",
"collate": "utf8mb4_bin",
"db_name": {
"L": "test",
"O": "test"
},
"id": 1,
"policy_ref_info": null,
"state": 5
}
}
],
"ddls": [],
"cluster_id": 7194351714070942000,
"cluster_version": "\"6.1.0\"\n",
"br_version": "BR\nRelease Version: v6.1.0\nGit Commit Hash: 1a89decdb192cbdce6a7b0020d71128bc964d30f\nGit Branch: heads/refs/tags/v6.1.0\nGo Version: go1.18.2\nUTC Build Time: 2022-06-05 05:09:12\nRace Enabled: false",
"end_version": 439108573623222300,
"new_collations_enabled": "True"
}`),
}

func TestEncodeAndDecode(t *testing.T) {
Expand Down

0 comments on commit ac6560f

Please sign in to comment.