Skip to content
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

sql/event_log: reduce tech debt, simplify and fix bugs #64894

Merged
merged 8 commits into from
May 21, 2021
7 changes: 3 additions & 4 deletions pkg/server/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,11 +823,10 @@ func (n *Node) recordJoinEvent(ctx context.Context) {
if err := n.storeCfg.DB.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
return sql.InsertEventRecord(ctx, n.sqlExec,
txn,
int32(n.Descriptor.NodeID),
int32(n.Descriptor.NodeID),
true, /* skipExternalLog - we already call log.StructuredEvent above */
int32(n.Descriptor.NodeID), /* reporting ID: the node where the event is logged */
sql.LogToSystemTable|sql.LogToDevChannelIfVerbose, /* LogEventDestination: we already call log.StructuredEvent above */
int32(n.Descriptor.NodeID), /* target ID: the node that is joining (ourselves) */
event,
false, /* onlyLog */
)
}); err != nil {
log.Warningf(ctx, "%s: unable to log event %v: %v", n, event, err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2346,10 +2346,10 @@ func (s *Server) Decommission(
ctx,
s.sqlServer.execCfg.InternalExecutor,
txn,
int32(nodeID), int32(s.NodeID()),
true, /* skipExternalLog - we already call log.StructuredEvent above */
int32(s.NodeID()), /* reporting ID: the node where the event is logged */
sql.LogToSystemTable|sql.LogToDevChannelIfVerbose, /* we already call log.StructuredEvent above */
int32(nodeID), /* target ID: the node that we wee a membership change for */
event,
false, /* onlyLog */
)
}); err != nil {
log.Ops.Errorf(ctx, "unable to record event: %+v: %+v", event, err)
Expand Down
26 changes: 16 additions & 10 deletions pkg/sql/create_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,16 +575,22 @@ func (r *createStatsResumer) Resume(ctx context.Context, execCtx interface{}) er
// CREATE STATISTICS statement.
// See: https://github.com/cockroachdb/cockroach/issues/57739
return evalCtx.ExecCfg.DB.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
return logEventInternalForSQLStatements(ctx, evalCtx.ExecCfg, txn,
descpb.IDs{details.Table.ID},
evalCtx.SessionData.User(),
evalCtx.SessionData.ApplicationName,
details.Statement,
"CREATE STATISTICS",
nil, /* no placeholders known at this point */
true, /* writeToEventLog */
&eventpb.CreateStatistics{
TableName: details.FQTableName,
return logEventInternalForSQLStatements(ctx,
evalCtx.ExecCfg, txn,
0, /* depth: use event_log=2 for vmodule filtering */
eventLogOptions{dst: LogEverywhere},
sqlEventCommonExecPayload{
user: evalCtx.SessionData.User(),
appName: evalCtx.SessionData.ApplicationName,
stmt: details.Statement,
stmtTag: "CREATE STATISTICS",
placeholders: nil, /* no placeholders known at this point */
},
eventLogEntry{
targetID: int32(details.Table.ID),
event: &eventpb.CreateStatistics{
TableName: details.FQTableName,
},
},
)
})
Expand Down
Loading