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

Add partial reindexing to composite views #4151

Merged
merged 7 commits into from
Aug 17, 2023

Conversation

imsdu
Copy link
Contributor

@imsdu imsdu commented Aug 9, 2023

Related to #3948

This first part prepares the model for partial reindexing when updating a composite view:

  • The indexingRev represents the last revision where a change impacted the indexing
  • Whenever a source is updated, the indexingRev is updated for both sources and projections and it will trigger a full reindexing
  • If a projection is updated, only this projection will be restarted

The changes in the indexing process will come in a second PR

@@ -55,8 +57,8 @@ import scala.concurrent.duration.FiniteDuration
final case class CompositeView(
id: Iri,
project: ProjectRef,
sources: NonEmptySet[CompositeViewSource],
projections: NonEmptySet[CompositeViewProjection],
sources: NonEmptyMap[Iri, CompositeViewSource],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NonEmptySet were kind of a pain here and as we mostly want to access sources and projections individually, a NonEmptyMap makes more sense

@@ -28,8 +27,8 @@ import scala.concurrent.duration.FiniteDuration
final case class CompositeViewFields(
name: Option[String],
description: Option[String],
sources: NonEmptySet[CompositeViewSourceFields],
projections: NonEmptySet[CompositeViewProjectionFields],
sources: NonEmptyList[CompositeViewSourceFields],
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, here, we check for duplication before creating the composite view anyway

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this an advantage? Set is telling us that ordering doesn't matter and the duplicates don't have an effect, which seems good?

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 because NonEmptyList is a lot easier to use.
NonEmptySet is based on a sorted set, requires an order and did not bring value here
as there is also a check for duplicates on the id of sources/projections when evaluating as sources and projections must all have different ids.

@imsdu imsdu marked this pull request as ready for review August 11, 2023 07:44
@@ -35,6 +35,8 @@ import scala.annotation.nowarn
* the collection of tags
* @param rev
* the current revision of the view
* @param indexingRev
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no indexingRev in this class

Copy link
Contributor

Choose a reason for hiding this comment

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

ℹ️ This is still there

*/
def sparqlProjections: Set[SparqlProjection] = projectionsOf[SparqlProjection]

private def projectionsOf[X: ClassTag] =
Copy link
Contributor

Choose a reason for hiding this comment

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

It won't looks super nice but it is possible to avoid reflection for sparqlProjections and elasticSearchProjections. Probably doesn't really matter though

@@ -37,6 +35,8 @@ sealed trait CompositeViewProjection extends Product with Serializable {
*/
def uuid: UUID

def indexingRev: Int
Copy link
Contributor

Choose a reason for hiding this comment

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

Utility of the docstring might be questionable but it is missing

@@ -534,14 +533,9 @@ object CompositeViews {
case Some(s) if s.deprecated =>
IO.raiseError(ViewIsDeprecated(c.id))
case Some(s) =>
val newRev = s.rev + 1
Copy link
Contributor

Choose a reason for hiding this comment

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

When newRev is used here or in further methods I have to say I keep losing track of what kind of revision we are dealing with

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I try to address that

Comment on lines 98 to 101
projections.foldLeft(Set.empty[X]) {
case (acc, projection: X) => acc + projection
case (acc, _) => acc
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You could just use .collect 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.

projections is a Map, not a set

includeMetadata
)

test("Create the matching source from the project source field with a defined id") {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is a matching source?

Copy link
Contributor

Choose a reason for hiding this comment

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

More broadly I don't really understand what these tests are actually asserting. What is the API doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That the fields are correctly transformed into a value

Comment on lines 49 to 70
test("Insert states and events and run migration") {
for {
_ <- xas.initPartitions(proj)
// Events to migrate
_ <- loadEvent("migration/event-created.json")
_ <- loadEvent("migration/event-updated.json")
// Events already migrated
_ <- loadEvent("composite-views/database/named-view-created.json")
_ <- loadEvent("composite-views/database/named-view-updated.json")
// States to migrate
_ <- loadState(Tag.latest, "migration/state.json")
_ <- loadState(UserTag.unsafe("v1.0"), "migration/state.json")
_ <- loadState(Tag.latest, "composite-views/database/view-state.json")
_ <- loadState(UserTag.unsafe("v1.0"), "composite-views/database/view-state.json")
_ <- eventsToMigrate(xas).map(_.assertSize(2))
_ <- statesToMigrate(xas).map(_.assertSize(2))
_ <- new MigrateCompositeViews(xas).run.assert((2, 2))
// Making sure all has been updated
_ <- eventsToMigrate(xas).map(_.assertSize(0))
_ <- statesToMigrate(xas).map(_.assertSize(0))
} yield ()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be a test, it's just setup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not only setup, it also run the migration.

Copy link
Contributor

Choose a reason for hiding this comment

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

The fact that it's unclear isn't a good sign. If this test runs a migration, and the other tests are checking that the migration ran correctly, then I would say that either this test is actually setup, or there should only be one test

@@ -35,6 +35,8 @@ import scala.annotation.nowarn
* the collection of tags
* @param rev
* the current revision of the view
* @param indexingRev
Copy link
Contributor

Choose a reason for hiding this comment

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

ℹ️ This is still there

@imsdu imsdu merged commit 4f85763 into BlueBrain:master Aug 17, 2023
4 of 5 checks passed
@imsdu imsdu deleted the 3948-composite-views-partial-reindexing branch August 17, 2023 13:49
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.

3 participants