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

writer: deallocate partially prepared statements on error #1592

Closed
wants to merge 1 commit into from

Conversation

algorandskiy
Copy link
Contributor

Summary

Writer does not call Close (and so that DEALLOCATE) if some of statements fail in the middle.
Although go's pg driver's Prepare is has map of prepared statements to prevent such errors (see the code excerpt below) it looks more correct to clean up in case of an error.

// Prepare creates a prepared statement with name and sql. sql can contain placeholders
// for bound parameters. These placeholders are referenced positional as $1, $2, etc.
//
// Prepare is idempotent; i.e. it is safe to call Prepare multiple times with the same
// name and sql arguments. This allows a code path to Prepare and Query/Exec without
// concern for if the statement has already been prepared.
func (c *Conn) Prepare(ctx context.Context, name, sql string) (sd *pgconn.StatementDescription, err error) {
	if name != "" {
		var ok bool
		if sd, ok = c.preparedStatements[name]; ok && sd.SQL == sql {
			return sd, nil
		}
	}
...
	sd, err = c.pgConn.Prepare(ctx, name, sql, nil)
...
	if name != "" {
		c.preparedStatements[name] = sd
	}

	return sd, nil
}

Test Plan

No test, it is hard/impossible to test b/c driver's Prepare caches statements.

Copy link

codecov bot commented Jan 12, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 4 lines in your changes missing coverage. Please review.

Project coverage is 68.43%. Comparing base (4bd144f) to head (10f7c28).
Report is 34 commits behind head on main.

Files with missing lines Patch % Lines
idb/postgres/internal/writer/writer.go 33.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1592      +/-   ##
==========================================
- Coverage   68.45%   68.43%   -0.02%     
==========================================
  Files          37       37              
  Lines        7434     7439       +5     
==========================================
+ Hits         5089     5091       +2     
- Misses       1915     1918       +3     
  Partials      430      430              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@jasonpaulos jasonpaulos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

@gmalouf
Copy link
Contributor

gmalouf commented Jan 12, 2024

@algorandskiy I suggest we ice box/close this for now - the driver for why the work was done may be resolved through configuration

@gmalouf gmalouf closed this Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants