Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,9 @@ func (s *Session) executeBatch(batch *Batch) *Iter {
return &Iter{err: ErrSessionClosed}
}

// Drop metrics from prior query executions
batch.metrics.reset()

// Prevent the execution of the batch if greater than the limit
// Currently batches have a limit of 65536 queries.
// https://datastax-oss.atlassian.net/browse/JAVA-229
Expand Down Expand Up @@ -879,6 +882,14 @@ func (qm *queryMetrics) hostMetricsLocked(host *HostInfo) *hostMetrics {
return metrics
}

// reset resets metrics, to forget about prior query executions
func (qm *queryMetrics) reset() {
qm.l.Lock()
qm.m = make(map[string]*hostMetrics)
qm.totalAttempts = 0
qm.l.Unlock()
}

// attempts returns the number of times the query was executed.
func (qm *queryMetrics) attempts() int {
qm.l.Lock()
Expand Down Expand Up @@ -1352,6 +1363,9 @@ func (q *Query) Iter() *Iter {
if isUseStatement(q.stmt) {
return &Iter{err: ErrUseStmt}
}

// Drop metrics from prior query executions
q.metrics.reset()
// if the query was specifically run on a connection then re-use that
// connection when fetching the next results
if q.conn != nil {
Expand Down