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

Flat queries #487

Merged
merged 7 commits into from
Feb 4, 2021
Merged

Flat queries #487

merged 7 commits into from
Feb 4, 2021

Conversation

dvoet
Copy link
Collaborator

@dvoet dvoet commented Nov 25, 2020

Ticket: https://broadworkbench.atlassian.net/browse/CA-315

  • There are some docs in the README, start there
  • I created a new package org/broadinstitute/dsde/workbench/sam/dataAccess and moved most of the DAOs there

PR checklist

  • I've followed the instructions if I've made any changes to the API, especially if they're breaking changes
  • I've updated the RC_XXX release ticket with any manual steps required to release this change
  • I've updated the FISMA documentation if I've made any security-related changes, including auth, encryption, or auditing

@coveralls
Copy link

coveralls commented Nov 25, 2020

Coverage Status

Coverage decreased (-0.06%) to 78.707% when pulling 0aac527 on flat_queries into 0e5f1ea on develop.

@dvoet
Copy link
Collaborator Author

dvoet commented Dec 15, 2020

jenkins retest

@dvoet
Copy link
Collaborator Author

dvoet commented Jan 13, 2021

jenkins retest

)(_ => IO(DBs.close(dbName.name)))
def resource(liquibaseConfig: LiquibaseConfig, dbName: DatabaseName): Resource[IO, DbReference] = {
for {
dbExecutionContext <- ExecutionContexts.fixedThreadPool[IO](DBs.config.getInt(s"db.${dbName.name.name}.poolMaxSize"))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

note this change moves the thread pool associated to a db connection internal to the db ref.

Comment on lines -128 to +130
private def persistResource(resourceType: ResourceType, resourceId: ResourceId, policies: Set[ValidatableAccessPolicy], authDomain: Set[WorkbenchGroupName], parentOpt: Option[FullyQualifiedResourceId], samRequestContext: SamRequestContext) =
for {
resource <- accessPolicyDAO.createResource(Resource(resourceType.name, resourceId, authDomain, parent = parentOpt), samRequestContext)
policies <- policies.toList.traverse(p => createOrUpdatePolicy(FullyQualifiedPolicyId(resource.fullyQualifiedId, p.policyName), p, samRequestContext))
} yield resource.copy(accessPolicies = policies.toSet)
private def persistResource(resourceType: ResourceType, resourceId: ResourceId, policies: Set[ValidatableAccessPolicy], authDomain: Set[WorkbenchGroupName], parentOpt: Option[FullyQualifiedResourceId], samRequestContext: SamRequestContext) = {
val accessPolicies = policies.map(constructAccessPolicy(resourceType, resourceId, _, public = false)) // can't set public at create time
accessPolicyDAO.createResource(Resource(resourceType.name, resourceId, authDomain, accessPolicies = accessPolicies, parent = parentOpt), samRequestContext)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

change to create a resource plus all policies in a single transaction


_ <- policiesToDelete.toList.parTraverse(p => accessPolicyDAO.deletePolicy(p.id, samRequestContext)).unsafeToFuture()
_ <- maybeDeleteResource(resource, samRequestContext)
_ <- accessPolicyDAO.deleteAllResourcePolicies(resource, samRequestContext).unsafeToFuture()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

delete all policies in a single transaction

val groupCount = 40
val userCount = 50
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

scaled down for the sake of elapsed time of test

policy.members.toList.parTraverse {
policy.members.toList.traverse {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

given the small database there are too many serializable failures with parTraverse so it turns out to be slower

Copy link
Contributor

@marctalbott marctalbott left a comment

Choose a reason for hiding this comment

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

Nothing blocking, mostly just questions and nits

@@ -137,7 +136,7 @@ object TestSupport extends TestSupport {

def genSamRoutesWithDefault(implicit system: ActorSystem, materializer: Materializer): SamRoutes = genSamRoutes(genSamDependencies(), UserInfo(OAuth2BearerToken(""), genWorkbenchUserId(System.currentTimeMillis()), defaultUserEmail, 3600))

lazy val dbRef = DbReference.init(config.as[LiquibaseConfig]("liquibase"), DatabaseNames.Foreground)
lazy val dbRef = DbReference.init(config.as[LiquibaseConfig]("liquibase"), DatabaseNames.Read, TestSupport.blockingEc)
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be readDbRef maybe? I'm looking at line 142 below and we're using the read pool to truncate the database. In test world, this is fine, but things might start getting confusing in the tests if we're using read and write pools willy nilly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In unit tests there really is not a difference between read and write pools. Ideally I would not even have it. But I also want to have DatabaseNames enum and DbReference.init to use it. So the situation is a little messy and I favor having more mess on the test side than the production side (i.e. I don't want to add a new database name just for tests).

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we leave a comment explaining this then? I think it is likely for someone to raise a question about this in the future.

from SAM_EFFECTIVE_RESOURCE_POLICY ep
join SAM_POLICY_ROLE pr on ep.source_policy_id = pr.resource_policy_id
join SAM_RESOURCE resource on ep.resource_id = resource.id
join sam_flattened_role flat_role on pr.resource_role_id = flat_role.base_role_id
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Out of curiosity, should sam_flattened_role be in all caps here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

doesn't matter

Copy link
Contributor

Choose a reason for hiding this comment

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

If it doesn't matter, would you mind moving it to caps for consistency?

* F | T | F | F
* F | F | T | F
* F | F | F | T
*
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to make sure I am understanding the logic behind this table, it is:
I xor not(PR or FR)

If so, that may be a useful thing to put in the comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

That may also be a simpler way to write the query? If that is the logic?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@marctalbott figured this out, if there were XOR in SQL it might be better but there isn't :(

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, the query looks good, but I was wondering about putting it above the truth table in the comment, just to make it more clear at a first glance. Although since we can't represent the sql that way, I'm okay with leaving it for now.

@dvoet
Copy link
Collaborator Author

dvoet commented Feb 3, 2021

jenkins retest - strange ivy thing on rawls

Copy link
Contributor

@s-rubenstein s-rubenstein left a comment

Choose a reason for hiding this comment

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

LGTM at this point, don't think any of my nits should hold this up.

* F | T | F | F
* F | F | T | F
* F | F | F | T
*
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, the query looks good, but I was wondering about putting it above the truth table in the comment, just to make it more clear at a first glance. Although since we can't represent the sql that way, I'm okay with leaving it for now.

from SAM_EFFECTIVE_RESOURCE_POLICY ep
join SAM_POLICY_ROLE pr on ep.source_policy_id = pr.resource_policy_id
join SAM_RESOURCE resource on ep.resource_id = resource.id
join sam_flattened_role flat_role on pr.resource_role_id = flat_role.base_role_id
Copy link
Contributor

Choose a reason for hiding this comment

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

If it doesn't matter, would you mind moving it to caps for consistency?

@zbedo
Copy link
Contributor

zbedo commented Feb 4, 2021

👍

@dvoet
Copy link
Collaborator Author

dvoet commented Feb 4, 2021

jenkins retest

@dvoet dvoet merged commit 3096814 into develop Feb 4, 2021
@dvoet dvoet deleted the flat_queries branch February 4, 2021 19:00
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

6 participants