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

Ordering of patches with cycles during upload #2524

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

aditya-07
Copy link
Collaborator

IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).

Fixes #2500

Description

  1. Find subgraphs (weakly connected) of Resources with cycles in them .
  2. Pack the subgraphs in Bundles such that a single subgraph is not split between two Bundles (as it may cause server error).
  3. Order the remaining resources and add them to the Bundle (in remaining space of or new Bundles) .

Alternative(s) considered
Have you considered any alternatives? And if so, why have you chosen the approach in this PR?

Type
Choose one: Bug fix

Screenshots (if applicable)

Checklist

  • I have read and acknowledged the Code of conduct.
  • I have read the Contributing page.
  • I have signed the Google Individual CLA, or I am covered by my company's Corporate CLA.
  • I have discussed my proposed solution with code owners in the linked issue(s) and we have agreed upon the general approach.
  • I have run ./gradlew spotlessApply and ./gradlew spotlessCheck to check my code follows the style guide of this project.
  • I have run ./gradlew check and ./gradlew connectedCheck to test my changes locally.
  • I have built and run the demo app(s) to verify my change fixes the issue and/or does not break the demo app(s).

@aditya-07 aditya-07 requested review from santosh-pingle and a team as code owners April 23, 2024 06:56
@aditya-07 aditya-07 changed the title Ordering of patches with cyclic during upload Ordering of patches with cycles during upload Apr 23, 2024
@MJ1998
Copy link
Collaborator

MJ1998 commented May 1, 2024

Is this ready for review ?

@vorburger vorburger removed the request for review from a team May 16, 2024 15:05
Copy link
Collaborator

@MJ1998 MJ1998 left a comment

Choose a reason for hiding this comment

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

What if we use Strongly Connected Components (SCC) ?

  1. Identify the SCCs
  2. Consolidate all nodes in each SCC into a supernode.
  3. Then apply the same topological sorting

So for following graph:-
1 -> 2, 3
2 -> 4, 5
4 -> 1
5 -> 6
7 -> 8, 9
8 -> 7

SCC = [{1,2,4}, {7, 8}]
We can have the topological sort as - [{3}, {6}, {5}, {1, 2, 4}, {9}, {7, 8}]

Current solution is also right but the above solution has more improvements:-

  1. Time complexity is one-fourth (from first look).
  2. In current approach the weakly-connected-components will go in one bundle if there is a cycle. Whereas in the above approach only the SCC will go in one bundle -> Reduces the size of the bundle a lot.

@MJ1998
Copy link
Collaborator

MJ1998 commented May 17, 2024

data class IndividualMapping(val patchMapping: PatchMapping) : OrderedMapping

/**
* [CombinedMapping] contains weakly connected [PatchMapping]s where one or more [PatchMapping]s
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* [CombinedMapping] contains weakly connected [PatchMapping]s where one or more [PatchMapping]s
* [CombinedMapping] contains strongly connected [PatchMapping]s where one or more [PatchMapping]s

@@ -67,3 +67,20 @@ internal data class PatchMapping(
val localChanges: List<LocalChange>,
val generatedPatch: Patch,
)

/** Structure to help describe the cyclic nature of ordered [PatchMapping]. */
internal sealed interface OrderedMapping {
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think there is no order in this structure itself - so maybe patch mapping group is a better name - or something similar?

@@ -139,4 +156,138 @@ internal object PatchOrdering {
adjacencyList.keys.forEach { dfs(it) }
return stack.reversed()
}

private fun stronglyConnectedComponents(diGraph: Graph, nodesCount: Int): List<List<Node>> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

optionally - you can separate all the logic related to scc to a separate class - and try to write it as an internal api.

// reduce them to a single node
// replace the ssc nodes with super node
oldGraph.forEach {
// println(it.key)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// println(it.key)

Comment on lines +185 to +187
// Remove any cyclic dependency from connected components.
// reduce them to a single node
// replace the ssc nodes with super node
Copy link
Collaborator

Choose a reason for hiding this comment

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

reformat this please (capitalise, punctuation etc)

Copy link
Collaborator

Choose a reason for hiding this comment

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

please udpate the unit tests here

Comment on lines +35 to +38
* Since a [UrlUploadRequest] can only handle a single resource request, the
* [OrderedMapping.CombinedMapping.patchMappings] are flattened and handled as
* [OrderedMapping.IndividualMapping] mapping to generate [UrlUploadRequestMapping] for each
* [PatchMapping].
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is good. but can you also add that we could potentially make this illegal in the future and explicitly introduce configurations for referential integrity on the server side.

and maybe just add a little bit to explain that single resource requests won't be able to handle resources referencing each other if the server is strict about referential integrity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: PR under Review
Development

Successfully merging this pull request may close these issues.

Sync upload local changes reordering patch issue
3 participants