-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add partial reindexing to composite views #4151
Conversation
@@ -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], |
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
...s/search/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/search/SearchViewFactory.scala
Show resolved
Hide resolved
delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/circe/package.scala
Outdated
Show resolved
Hide resolved
delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/circe/Decoders.scala
Outdated
Show resolved
Hide resolved
delta/sourcing-psql/src/main/scala/ch/epfl/bluebrain/nexus/delta/sourcing/Transactors.scala
Outdated
Show resolved
Hide resolved
...s/search/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/search/SearchViewFactory.scala
Show resolved
Hide resolved
@@ -35,6 +35,8 @@ import scala.annotation.nowarn | |||
* the collection of tags | |||
* @param rev | |||
* the current revision of the view | |||
* @param indexingRev |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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] = |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
projections.foldLeft(Set.empty[X]) { | ||
case (acc, projection: X) => acc + projection | ||
case (acc, _) => acc | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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 () | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
...c/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/compositeviews/CompositeViewFactory.scala
Show resolved
Hide resolved
@@ -35,6 +35,8 @@ import scala.annotation.nowarn | |||
* the collection of tags | |||
* @param rev | |||
* the current revision of the view | |||
* @param indexingRev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ This is still there
Related to #3948
This first part prepares the model for partial reindexing when updating a composite view:
The changes in the indexing process will come in a second PR