-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
*: write binlog to unix socket. #1660
Conversation
Do we need a switch to turn on/off this feature? Not all user need it. |
"github.com/pingcap/tidb/table" | ||
"github.com/pingcap/tidb/terror" | ||
// import table implementation to init table.TableFromMeta | ||
"github.com/pingcap/tidb/perfschema" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any special reason to move the import?
@disksing @hanfei1991 PTAL |
@@ -515,7 +525,38 @@ func (t *Table) RemoveRecord(ctx context.Context, h int64, r []types.Datum) erro | |||
if err != nil { | |||
return errors.Trace(err) | |||
} | |||
|
|||
if binloginfo.Enable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here can use a function.
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package binloginfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about rename it to binlog?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the package name will conflict with tipb/go-binlog
.
For same statements, we use another sql to do some sub jobs. For example, set global variable, it will run an update statement. Do we need to avoid add an update binlog when set global variable? |
f4c066f
to
1fdbfa5
Compare
a62b19f
to
17a03f2
Compare
78c7fa8
to
6c68530
Compare
@@ -184,18 +185,29 @@ func (s *session) finishTxn(rollback bool) error { | |||
if s.txn == nil { | |||
return nil | |||
} | |||
sessVar := variable.GetSessionVars(s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sessVar
seems useless.
req := &binlog.WriteBinlogReq{ClusterID: binloginfo.ClusterID, Payload: rollbackData} | ||
resp, err := binloginfo.PumpClient.WriteBinlog(context.Background(), req) | ||
if err != nil { | ||
log.Error(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add more log information. The same as the line 431.
err = errors.New(resp.Errmsg) | ||
} | ||
} | ||
ch <- err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err -> errors.Trace(err) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest LGTM
} | ||
|
||
func (c *txnCommitter) writeCommitBinlog() { | ||
if binloginfo.PumpClient == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use shouldWriteBinlog?
} | ||
|
||
func (c *txnCommitter) rollbackBinlog() { | ||
if binloginfo.PumpClient == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldWriteBinlog?
return nil | ||
} | ||
|
||
func (c *txnCommitter) prewriteBinlog() chan error { | ||
if binloginfo.PumpClient == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldWriteBinlog?
support write binlog to a unix socket through grpc.
482b454
to
af7b814
Compare
log.Fatal(errors.ErrorStack(err1)) | ||
} | ||
binloginfo.ClusterID = id | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can line 101-112 be extract into a function?I think simpler and shorter code in the function of main is better. The same as line 122-130.
if err != nil { | ||
log.Fatal(errors.ErrorStack(err)) | ||
} | ||
if cluster := u.Query().Get("cluster"); cluster != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If cluster == ""
it has some problems?
return errors.Trace(err) | ||
} | ||
log.Warnf("txn commit succeed with error: %v, tid: %d", err, c.startTS) | ||
} | ||
c.writeCommitBinlog() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not put c.writeCommitBinlog()
and c.rollbackBinlog()
in tikvTxn.Commit()
?
def9152
to
5cd4845
Compare
PrewriteKey: c.keys[0], | ||
PrewriteValue: prewriteValue.([]byte), | ||
} | ||
prewriteData, _ := binPrewrite.Marshal() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the error. The same as line 418 and line 442
go func() { | ||
prewriteValue := c.txn.us.GetOption(kv.BinlogData) | ||
var err error | ||
if prewriteValue != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the return value of c.shouldWriteBinlog() is ture, the value of prewriteValue != nil
also is true.
} | ||
prewriteData, _ := binPrewrite.Marshal() | ||
req := &binlog.WriteBinlogReq{ClusterID: binloginfo.ClusterID, Payload: prewriteData} | ||
var resp *binlog.WriteBinlogResp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line can be removed.
LGTM |
No description provided.