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

update netaddr #50

Merged
merged 14 commits into from
Feb 28, 2021
Merged

update netaddr #50

merged 14 commits into from
Feb 28, 2021

Conversation

majst01
Copy link
Contributor

@majst01 majst01 commented Feb 27, 2021

  • new version of netaddr split IPSet into a unmutable IPSet and a mutable IPSetBuilder
  • replace github.com/pkg/errors with fmt.Errorf
  • wrap all errors
  • simplify OptimisticLockException handling and detection
  • replace panic() with require in tests
  • enforce golangci-lint run -p bug to pass

@codecov-io
Copy link

codecov-io commented Feb 27, 2021

Codecov Report

Merging #50 (ebf4ec6) into master (0958608) will decrease coverage by 0.46%.
The diff coverage is 43.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #50      +/-   ##
==========================================
- Coverage   76.73%   76.27%   -0.47%     
==========================================
  Files           7        6       -1     
  Lines         546      548       +2     
==========================================
- Hits          419      418       -1     
  Misses         68       68              
- Partials       59       62       +3     
Impacted Files Coverage Δ
postgres.go 70.00% <0.00%> (ø)
sql.go 66.30% <28.00%> (-3.02%) ⬇️
prefix.go 78.01% <64.70%> (ø)
memory.go 94.28% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0958608...ebf4ec6. Read the comment docs.

@majst01 majst01 requested a review from droid42 February 27, 2021 13:36
@majst01 majst01 marked this pull request as ready for review February 27, 2021 13:36
Copy link
Collaborator

@droid42 droid42 left a comment

Choose a reason for hiding this comment

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

Good improvement to error handling 👍
Added some comments.

sql.go Outdated
@@ -133,9 +133,9 @@ func (s *sql) UpdatePrefix(prefix Prefix) (Prefix, error) {
if rows == 0 {
err := tx.Rollback()
if err != nil {
return Prefix{}, newOptimisticLockError("select for update did not effect any row, but rollback did not work:" + err.Error())
return Prefix{}, fmt.Errorf("select for update did not effect any row, but rollback did not work:%w", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This changes the contract, because now the error is no longer the OptimisticLockError but the Error seen at Rollback. The client should really see the OptimisticLockError in my opinion.
We could even remove the rollback since if zero rows had been are affected this makes no sense to rollback "no changes".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes thats right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

still do the rollback, but error handling is removed.

sql.go Outdated
@@ -145,17 +145,17 @@ func (s *sql) UpdatePrefix(prefix Prefix) (Prefix, error) {
if rows == 0 {
err := tx.Rollback()
if err != nil {
return Prefix{}, newOptimisticLockError("updatePrefix did not effect any row, but rollback did not work:" + err.Error())
return Prefix{}, fmt.Errorf("updatePrefix did not effect any row, but rollback did not work:%w", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This changes the contract, because now the error is no longer the OptimisticLockError but the Error seen at Rollback. The client should really see the OptimisticLockError in my opinion.
Could even remove the rollback, see above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same

sql.go Outdated
}
return prefix, tx.Commit()
}

func (s *sql) DeletePrefix(prefix Prefix) (Prefix, error) {
tx, err := s.db.Beginx()
if err != nil {
return Prefix{}, fmt.Errorf("unable to start transaction:%v", err)
return Prefix{}, fmt.Errorf("unable to start transaction:%w", err)
}
tx.MustExec("DELETE from prefixes WHERE cidr=$1", prefix.Cidr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Whoa, we should really replace this tx.MustExec and do proper error handling here, since MustExec panics if it fails!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoa good catch, we have mustExec everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All MustExec are remove now, this was a big mistake in the past.

memory.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@droid42 droid42 left a comment

Choose a reason for hiding this comment

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

LGTM

@majst01 majst01 merged commit 12a934f into master Feb 28, 2021
@majst01 majst01 deleted the update-netaddr branch February 28, 2021 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants