tidb_check.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package service
  2. import (
  3. "regexp"
  4. "go-common/library/log"
  5. )
  6. func (ins *tidbInstance) check() (err error) {
  7. for _, db := range ins.config.Databases {
  8. for _, ctable := range db.CTables {
  9. if _, err = regexp.Compile(ctable.Name); err != nil {
  10. log.Error("regexp.Compile(%s) error(%v)", ctable.Name, err)
  11. return
  12. }
  13. }
  14. }
  15. return
  16. }
  17. func (ins *tidbInstance) getTable(dbName, table string) *Table {
  18. if ins.ignoreTables[dbName] != nil && ins.ignoreTables[dbName][table] {
  19. return nil
  20. }
  21. if ins.tables[dbName] != nil && ins.tables[dbName][table] != nil {
  22. return ins.tables[dbName][table]
  23. }
  24. var regex *regexp.Regexp
  25. for _, db := range ins.config.Databases {
  26. if db.Schema != dbName {
  27. continue
  28. }
  29. for _, ctable := range db.CTables {
  30. regex, _ = regexp.Compile(ctable.Name)
  31. if !regex.MatchString(table) {
  32. continue
  33. }
  34. if ins.tables[dbName] == nil {
  35. ins.tables[dbName] = make(map[string]*Table)
  36. }
  37. t := &Table{
  38. PrimaryKey: ctable.PrimaryKey,
  39. OmitField: make(map[string]bool),
  40. OmitAction: make(map[string]bool),
  41. name: ctable.Name,
  42. ch: make(chan *msg, 1024),
  43. }
  44. for _, action := range ctable.OmitAction {
  45. t.OmitAction[action] = true
  46. }
  47. for _, field := range ctable.OmitField {
  48. t.OmitField[field] = true
  49. }
  50. ins.waitTable.Add(1)
  51. go ins.proc(t.ch)
  52. ins.tables[dbName][table] = t
  53. return t
  54. }
  55. }
  56. if ins.ignoreTables[dbName] == nil {
  57. ins.ignoreTables[dbName] = make(map[string]bool)
  58. }
  59. ins.ignoreTables[dbName][table] = true
  60. return nil
  61. }