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

Set readonly in evolver #288

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,12 @@ lazy val `elastic-testkit` = (project in file("elastic/testkit"))
circe.generic.value,
circe.genericExtras.value,
macwire.macros,
logback.classic % Test,
logback.core % Test,
),
idePackagePrefix := Some("net.sc8s.elastic.testkit")
)
.dependsOn(`elastic-core`, `schevo-circe`.jvm)
.dependsOn(`elastic-core`, `schevo-circe`.jvm, `akka-components-testkit` % Test)

lazy val `elastic-lagom-api` =
crossProject(JSPlatform, JVMPlatform)
Expand Down
14 changes: 12 additions & 2 deletions elastic/core/src/main/scala/Evolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ object Evolver extends ClusterComponent.Singleton {
.settings(index.settings)
}

def setReadOnly(indexName: String, readOnly: Boolean) =
elasticClient.execute(updateSettings(indexName) set "index.blocks.read_only_allow_delete" -> s"$readOnly" preserveExisting true)

def default: Behaviors.Receive[Command] = Behaviors.receiveMessagePartial {
case MigrateNextIndex(pendingIndices) =>
pendingIndices.toList match {
Expand Down Expand Up @@ -224,6 +227,7 @@ object Evolver extends ClusterComponent.Singleton {
case MigrateIndex(index, oldIndexName, newIndexName, pendingIndices) =>
log.info(s"${"migratingIndex" -> "tag"} ${index.name -> "index"} from $oldIndexName to $newIndexName")
val eventualCommand = for {
_ <- setReadOnly(oldIndexName, readOnly = true)
_ <- elasticClient.execute(createIndexWithMappings(index, newIndexName)).map(_.result)
result <- elasticClient.execute(reindex(oldIndexName, newIndexName) waitForCompletion false shouldStoreResult true).map(_.result)
} yield result match {
Expand All @@ -236,7 +240,13 @@ object Evolver extends ClusterComponent.Singleton {
IndexMigrated
}

context.pipeToSelf(eventualCommand)(_.fold(e => IndexMigrationFailed(index, e), identity))
context.pipeToSelf(eventualCommand)(_.fold(e => {
setReadOnly(oldIndexName, readOnly = false).onComplete {
case Failure(exception) => log.errorT("reEnablingWriteAfterIndexMigrationFailureFailed", s"on $index due to $exception")
}

IndexMigrationFailed(index, e)
}, identity))

migratingIndex(index, oldIndexName, newIndexName, pendingIndices)

Expand Down Expand Up @@ -408,7 +418,7 @@ object Evolver extends ClusterComponent.Singleton {
}
}

private val mappingsHashField = "mappingHash"
private[elastic] val mappingsHashField = "mappingHash"

private val analysisHashField = "analysisHash"

Expand Down
Loading