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

ROX-18155: pg generic store: Upsert #6882

Merged

Conversation

janisz
Copy link
Contributor

@janisz janisz commented Jul 10, 2023

Description

The last Method migrated from to generic store. I didn't find a way to make SAC checks generic so I inject them with a function.

Checklist

  • Investigated and inspected CI test results
  • Unit test and regression tests added
  • Evaluated and added CHANGELOG entry if required
  • Determined and documented upgrade steps
  • Documented user facing changes (create PR based on openshift/openshift-docs and merge into rhacs-docs)

If any of these don't apply, please comment below.

Testing Performed

CI

@roxbot
Copy link
Contributor

roxbot commented Jul 10, 2023

Images are ready for the commit at 8f100c9.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.1.x-393-g8f100c912a.

@janisz janisz force-pushed the master-janisz/07-10-ROX-18155_pg_generic_store_Upsert branch from cf1a456 to cec2bcc Compare July 11, 2023 12:33
@janisz janisz requested a review from rhybrillou July 11, 2023 12:40
Copy link
Contributor

@rhybrillou rhybrillou left a comment

Choose a reason for hiding this comment

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

Please review the logic behind IsWriteAllowed in pkg/search/postgres/sac.go.
If the function is not needed, it could be removed.
The other changes look good. There are some possible improvement follow-ups.

if err != nil {
return false
}
return sacQuery.GetBaseQuery().GetMatchNoneQuery() != nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Write is allowed if the filter query is NOT MatchNoneQuery. I have the feeling this would return true if the sacQuery is a MatchNoneQuery. Am I mistaken here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I forgot to delete it. It's leftover from my try to make scope checker generic.


func (s *GenericStore[T, PT]) upsert(ctx context.Context, objs ...PT) error {
if s.insertInto == nil {
err := errors.New("invalid operation, missing insertInto function")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Why not making this error a file var or const ?


func (s *GenericStore[T, PT]) copyFrom(ctx context.Context, objs ...PT) error {
if s.copyFromObj == nil {
err := errors.New("invalid operation, missing copyFromObj function")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Why not making this error a file var or const ?

}

if err := s.copyFromObj(ctx, s, tx, objs...); err != nil {
if err := tx.Rollback(ctx); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could we differentiate the rollback error from the copyFromObj one ?

return err
}

conn, err := s.AcquireConn(ctx, ops.Get)
Copy link
Contributor

Choose a reason for hiding this comment

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

Although it was already so in the generated store function, I think it would make sense to use ops.Upsert here.
Can be tracked as a follow-up.

utils.Should(err)
return err
}
conn, err := s.AcquireConn(ctx, ops.Get)
Copy link
Contributor

Choose a reason for hiding this comment

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

Although it was already so in the generated store function, I think it would make sense to use ops.Upsert here.
Can be tracked as a follow-up.

return s.permissionChecker != nil
}

func (s *GenericStore[T, PT]) permissionCheckerUpsertAllows(ctx context.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: naming - how about permissionCheckerAllowsUpsert ?

pkg/search/postgres/store.go Show resolved Hide resolved
@janisz janisz requested a review from rhybrillou July 12, 2023 16:55
@janisz janisz force-pushed the master-janisz/07-10-ROX-18155_pg_generic_store_Upsert branch from f943032 to 5e857e5 Compare July 12, 2023 16:56
@janisz janisz force-pushed the master-janisz/07-10-refactor_pg_remove_blank_lines branch from 7215e6a to bc74488 Compare July 12, 2023 16:59
@janisz janisz force-pushed the master-janisz/07-10-ROX-18155_pg_generic_store_Upsert branch from 5e857e5 to f9f38c6 Compare July 12, 2023 16:59
@janisz janisz force-pushed the master-janisz/07-10-refactor_pg_remove_blank_lines branch from bc74488 to 33d8992 Compare July 13, 2023 08:40
Base automatically changed from master-janisz/07-10-refactor_pg_remove_blank_lines to master July 13, 2023 09:38
@janisz janisz force-pushed the master-janisz/07-10-ROX-18155_pg_generic_store_Upsert branch from f9f38c6 to 8f100c9 Compare July 13, 2023 10:32
@janisz janisz requested a review from a team July 13, 2023 11:35
@janisz
Copy link
Contributor Author

janisz commented Jul 13, 2023

/retest

pkg/search/postgres/store.go Show resolved Hide resolved
@janisz janisz merged commit 04ad904 into master Jul 13, 2023
67 of 68 checks passed
@janisz janisz deleted the master-janisz/07-10-ROX-18155_pg_generic_store_Upsert branch July 13, 2023 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants