You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

lockkey.go 2.2 kB

the ability to automatically run unit tests after creating a pull request. (#764) * feat: add unit test workflow * feat:the ability to automatically run unit tests after creating a pull request. * feat:the ability to automatically run unit tests after creating a pull request. * feat:the ability to automatically run unit tests after creating a pull request. * feat:the ability to automatically run unit tests after creating a pull request. * feat:the ability to automatically run unit tests after creating a pull request. * feat:the ability to automatically run unit tests after creating a pull request. * Optimize/at build lock key performance (#837) * Refer to buildlockkey2 optimization #829 * Time complexity O(NM)-> O(NK) about buildlockkey and buildlockkey2 Increased readability #829 * update import sort #829 * update Encapsulation into util packages #829 * Support Update join (#761) * duplicate image row for update join * update join condition placeholder param error * update join bugfix * Open test annotations * recover update executor * recover update test * recover update test * modified version param --------- Co-authored-by: JayLiu <38887641+luky116@users.noreply.github.com> Co-authored-by: FengZhang <zfcode@qq.com> --------- Co-authored-by: jimin <slievrly@163.com> Co-authored-by: JayLiu <38887641+luky116@users.noreply.github.com> Co-authored-by: FengZhang <zfcode@qq.com> Co-authored-by: Wiggins <125641755+MinatoWu@users.noreply.github.com> Co-authored-by: lxfeng1997 <33981743+lxfeng1997@users.noreply.github.com>
3 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. // Copyright 2016 The Go Authors. All rights reserved.
  18. // Use of this source code is governed by a BSD-style
  19. // license that can be found in the LICENSE file.
  20. package util
  21. import (
  22. "fmt"
  23. "seata.apache.org/seata-go/pkg/datasource/sql/types"
  24. "strings"
  25. )
  26. func BuildLockKey(records *types.RecordImage, meta types.TableMeta) string {
  27. var lockKeys strings.Builder
  28. type ColMapItem struct {
  29. pkIndex int
  30. colIndex int
  31. }
  32. lockKeys.WriteString(meta.TableName)
  33. lockKeys.WriteString(":")
  34. keys := meta.GetPrimaryKeyOnlyName()
  35. keyIndexMap := make(map[string]int, len(keys))
  36. for idx, columnName := range keys {
  37. keyIndexMap[columnName] = idx
  38. }
  39. columns := make([]ColMapItem, 0, len(keys))
  40. if len(records.Rows) > 0 {
  41. for colIdx, column := range records.Rows[0].Columns {
  42. if pkIdx, ok := keyIndexMap[column.ColumnName]; ok {
  43. columns = append(columns, ColMapItem{pkIndex: pkIdx, colIndex: colIdx})
  44. }
  45. }
  46. for i, row := range records.Rows {
  47. if i > 0 {
  48. lockKeys.WriteString(",")
  49. }
  50. primaryKeyValues := make([]interface{}, len(keys))
  51. for _, mp := range columns {
  52. if mp.colIndex < len(row.Columns) {
  53. primaryKeyValues[mp.pkIndex] = row.Columns[mp.colIndex].Value
  54. }
  55. }
  56. for j, pkVal := range primaryKeyValues {
  57. if j > 0 {
  58. lockKeys.WriteString("_")
  59. }
  60. if pkVal == nil {
  61. continue
  62. }
  63. lockKeys.WriteString(fmt.Sprintf("%v", pkVal))
  64. }
  65. }
  66. }
  67. return lockKeys.String()
  68. }