NewRestoreRegistry creates a new registry using TiDB's session
(ctx context.Context, g glue.Glue, dom *domain.Domain)
| 211 | |
| 212 | // NewRestoreRegistry creates a new registry using TiDB's session |
| 213 | func NewRestoreRegistry(ctx context.Context, g glue.Glue, dom *domain.Domain) (*Registry, error) { |
| 214 | se, err := g.CreateSession(dom.Store()) |
| 215 | if err != nil { |
| 216 | return nil, errors.Trace(err) |
| 217 | } |
| 218 | heartbeatSession, err := g.CreateSession(dom.Store()) |
| 219 | if err != nil { |
| 220 | return nil, errors.Trace(err) |
| 221 | } |
| 222 | tableExists := true |
| 223 | _, err = dom.InfoSchema().TableByName(ctx, |
| 224 | pmodel.NewCIStr(RestoreRegistryDBName), |
| 225 | pmodel.NewCIStr(RestoreRegistryTableName), |
| 226 | ) |
| 227 | if err != nil { |
| 228 | if !infoschema.ErrTableNotExists.Equal(err) { |
| 229 | return nil, errors.Trace(err) |
| 230 | } |
| 231 | tableExists = false |
| 232 | } |
| 233 | |
| 234 | return &Registry{ |
| 235 | se: se, |
| 236 | heartbeatSession: heartbeatSession, |
| 237 | tableExists: tableExists, |
| 238 | }, nil |
| 239 | } |
| 240 | |
| 241 | func (r *Registry) Close() { |
| 242 | log.Info("closing registry") |