This repository was archived by the owner on Sep 24, 2024. It is now read-only. 
      
File tree Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -193,6 +193,29 @@ func (c *Canal) WaitDumpDone() <-chan struct{} {
193193return  c .dumpDoneCh 
194194}
195195
196+ func  (c  * Canal ) GetTableForEvent (te  * replication.TableMapEvent ) (* schema.Table , error ) {
197+ key  :=  fmt .Sprintf ("%s.%s" , te .Schema , te .Table )
198+ c .tableLock .Lock ()
199+ t , ok  :=  c .tables [key ]
200+ c .tableLock .Unlock ()
201+ 
202+ // return if we already have the table info and the columns count matches 
203+ if  ok  &&  (te  ==  nil  ||  te .ColumnCount  ==  uint64 (len (t .Columns ))) {
204+ return  t , nil 
205+ }
206+ 
207+ t , err  :=  schema .NewTable (c , string (te .Schema ), string (te .Table ))
208+ if  err  !=  nil  {
209+ return  nil , errors .Trace (err )
210+ }
211+ 
212+ c .tableLock .Lock ()
213+ c .tables [key ] =  t 
214+ c .tableLock .Unlock ()
215+ 
216+ return  t , nil 
217+ }
218+ 
196219func  (c  * Canal ) GetTable (db  string , table  string ) (* schema.Table , error ) {
197220key  :=  fmt .Sprintf ("%s.%s" , db , table )
198221c .tableLock .Lock ()
Original file line number Diff line number Diff line change @@ -79,10 +79,7 @@ func (c *Canal) handleRowsEvent(e *replication.BinlogEvent) error {
7979ev  :=  e .Event .(* replication.RowsEvent )
8080
8181// Caveat: table may be altered at runtime. 
82- schema  :=  string (ev .Table .Schema )
83- table  :=  string (ev .Table .Table )
84- 
85- t , err  :=  c .GetTable (schema , table )
82+ t , err  :=  c .GetTableForEvent (ev .Table )
8683if  err  !=  nil  {
8784return  errors .Trace (err )
8885}
                                 You can’t perform that action at this time. 
               
                  
0 commit comments