Skip to content

Commit

Permalink
Remove the reset service from sandbox-classic and sandbox [DPP-804] (#…
Browse files Browse the repository at this point in the history
…12448)

* Remove the reset service from sandbox-classic and sandbox

CHANGELOG_BEGIN
Reset service has been removed from the sandbox-classic, sandbox and daml-on-sql
CHANGELOG_END

* format it
  • Loading branch information
mziolekda authored Jan 19, 2022
1 parent e40c221 commit 954bc5e
Show file tree
Hide file tree
Showing 21 changed files with 197 additions and 1,004 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,6 @@ object LedgerApiErrors extends LedgerApiErrorGroup {
override def context: Map[String, String] =
super.context ++ Map("service_name" -> _serviceName)
}

case class ServiceReset(_serviceName: String)(implicit
loggingContext: ContextualizedErrorLogger
) extends LoggingTransactionErrorImpl(
cause = s"${_serviceName} is currently being reset."
) {
override def context: Map[String, String] =
super.context ++ Map("service_name" -> _serviceName)
}
}

@Explanation("Authentication errors.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ object ClaimSet {
* | PackageService | * | isPublic |
* | PackageManagementService | * | isAdmin |
* | PartyManagementService | * | isAdmin |
* | ResetService | * | isAdmin |
* | ServerReflection | * | N/A (authentication not required) |
* | TimeService | GetTime | isPublic |
* | TimeService | SetTime | isAdmin |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,20 +524,6 @@ class ErrorFactories private (errorCodesVersionSwitcher: ErrorCodesVersionSwitch
v2 = LedgerApiErrors.ServiceNotRunning.Reject(serviceName).asGrpcError,
)

def serviceIsBeingReset(legacyStatusCode: Int)(serviceName: String)(implicit
contextualizedErrorLogger: ContextualizedErrorLogger
): StatusRuntimeException =
errorCodesVersionSwitcher.choose(
v1 = {
val statusBuilder = Status
.newBuilder()
.setCode(legacyStatusCode)
.setMessage(s"$serviceName is currently being reset.")
grpcError(statusBuilder.build())
},
v2 = LedgerApiErrors.ServiceNotRunning.ServiceReset(serviceName).asGrpcError,
)

def trackerFailure(msg: String)(implicit
contextualizedErrorLogger: ContextualizedErrorLogger
): StatusRuntimeException =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -753,34 +753,6 @@ class ErrorFactoriesSpec
}
}

"return a serviceIsBeingReset error" in {
val serviceName = "Some API Service"
val someLegacyStatusCode = Code.CANCELLED

val msg =
s"SERVICE_NOT_RUNNING(1,$truncatedCorrelationId): $serviceName is currently being reset."
assertVersionedError(_.serviceIsBeingReset(someLegacyStatusCode.value())(serviceName))(
v1_code = someLegacyStatusCode,
v1_message = s"$serviceName is currently being reset.",
v1_details = Seq.empty,
v2_code = Code.UNAVAILABLE,
v2_message = msg,
v2_details = Seq[ErrorDetails.ErrorDetail](
ErrorDetails.ErrorInfoDetail(
"SERVICE_NOT_RUNNING",
Map("category" -> "1", "definite_answer" -> "false", "service_name" -> serviceName),
),
expectedCorrelationIdRequestInfo,
ErrorDetails.RetryInfoDetail(1),
),
v2_logEntry = ExpectedLogEntry(
Level.INFO,
msg,
expectedMarkerRegex("service_name=Some API Service"),
),
)
}

"return a missingField error" in {
val fieldName = "my field"

Expand Down
1 change: 0 additions & 1 deletion ledger/participant-integration-api/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ da_scala_test_suite(
srcs = glob(
["src/test/suite/**/*.scala"],
exclude = [
"src/test/suite/**/ResetService*IT.scala",
"**/*Oracle*",
],
),
Expand Down
34 changes: 6 additions & 28 deletions ledger/sandbox-classic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ da_scala_library(
scala_deps = [
"@maven//:com_typesafe_akka_akka_actor",
"@maven//:com_typesafe_akka_akka_stream",
"@maven//:org_playframework_anorm_anorm",
"@maven//:org_playframework_anorm_anorm_tokenizer",
"@maven//:org_scalactic_scalactic",
"@maven//:org_scalatest_scalatest_core",
"@maven//:org_scalatest_scalatest_flatspec",
Expand Down Expand Up @@ -162,7 +160,6 @@ da_scala_library(
"//ledger/ledger-api-health",
"//ledger/ledger-configuration",
"//ledger/ledger-resources",
"//ledger/ledger-resources:ledger-resources-test-lib",
"//ledger/metrics",
"//ledger/participant-integration-api",
"//ledger/participant-integration-api:participant-integration-api-tests-lib",
Expand Down Expand Up @@ -264,43 +261,24 @@ scala_test_deps = [
"@maven//:org_scalaz_scalaz_core",
]

# The reset service is cursed so we mark all tests involving it as flaky.
reset_service_pattern = "src/test/suite/**/*ResetService*.scala"

[
da_scala_test_suite(
name = "sandbox-classic-tests{}".format(suffix),
size = size,
name = "sandbox-classic-tests",
size = "medium",
srcs = glob(
[pattern],
exclude = exclusions,
["src/test/suite/**/*.scala"],
exclude = [],
),
data = [
"//daml-lf/encoder:testing-dars",
"//ledger/test-common:model-tests-default.dar",
"//ledger/test-common/test-certificates",
],
flaky = flaky,
flaky = False,
resources = glob(["src/test/resources/**/*"]) + ["//ledger/sandbox-common:src/main/resources/logback.xml"],
scala_deps = scala_test_deps,
deps = test_deps,
)
for (suffix, pattern, exclusions, flaky, size) in [
(
"",
"src/test/suite/**/*.scala",
[reset_service_pattern],
False,
"medium", # Default timeout of 5min
),
(
"-resetservice",
reset_service_pattern,
[],
True,
"large", # Reset service tests have a large variance in their run time, use a timeout of 15min
),
]
),
]

SERVERS = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@ import com.daml.platform.sandbox.SandboxServer._
import com.daml.platform.sandbox.banner.Banner
import com.daml.platform.sandbox.config.SandboxConfig.EngineMode
import com.daml.platform.sandbox.config.{LedgerName, SandboxConfig}
import com.daml.platform.sandbox.services.SandboxResetService
import com.daml.platform.sandbox.stores.ledger.ScenarioLoader.LedgerEntryOrBump
import com.daml.platform.sandbox.stores.ledger._
import com.daml.platform.sandbox.stores.ledger.sql.SqlStartMode
import com.daml.platform.sandbox.stores.{InMemoryActiveLedgerState, SandboxIndexAndWriteService}
import com.daml.platform.server.api.validation.ErrorFactories
import com.daml.platform.services.time.TimeProviderType
import com.daml.platform.store.{DbSupport, DbType, FlywayMigrations, LfValueTranslationCache}
import com.daml.platform.usermanagement.PersistentUserManagementStore
Expand Down Expand Up @@ -122,33 +120,15 @@ object SandboxServer {
}

final class SandboxState(
materializer: Materializer,
metrics: Metrics,
packageStore: InMemoryPackageStore,
// nested resource so we can release it independently when restarting
apiServerResource: Resource[ApiServer],
apiServerResource: Resource[ApiServer]
) {
def port(implicit executionContext: ExecutionContext): Future[Port] =
apiServer.map(_.port)

private[SandboxServer] def apiServer: Future[ApiServer] =
apiServerResource.asFuture

private[SandboxServer] def reset(
newApiServer: (
Materializer,
Metrics,
InMemoryPackageStore,
Port,
) => Resource[ApiServer]
)(implicit executionContext: ExecutionContext): Future[SandboxState] =
for {
currentPort <- port
_ <- release()
replacementApiServer = newApiServer(materializer, metrics, packageStore, currentPort)
_ <- replacementApiServer.asFuture
} yield new SandboxState(materializer, metrics, packageStore, replacementApiServer)

def release(): Future[Unit] =
apiServerResource.release()
}
Expand Down Expand Up @@ -211,30 +191,6 @@ final class SandboxServer(
def portF(implicit executionContext: ExecutionContext): Future[Port] =
apiServer.map(_.port)

def resetAndRestartServer()(implicit
executionContext: ExecutionContext,
loggingContext: LoggingContext,
): Future[Unit] = {
val apiServicesClosed = apiServer.flatMap(_.servicesClosed())

// TODO: eliminate the state mutation somehow
sandboxState = sandboxState.flatMap(
_.reset((materializer, metrics, packageStore, port) =>
buildAndStartApiServer(
materializer = materializer,
metrics = metrics,
packageStore = packageStore,
startMode = SqlStartMode.ResetAndStart,
currentPort = Some(port),
)
)
)

// Wait for the services to be closed, so we can guarantee that future API calls after finishing
// the reset will never be handled by the old one.
apiServicesClosed
}

// if requested, initialize the ledger state with the given scenario
private def createInitialState(
config: SandboxConfig,
Expand Down Expand Up @@ -403,15 +359,6 @@ final class SandboxServer(
"index" -> indexAndWriteService.indexService,
"write" -> indexAndWriteService.writeService,
)
// the reset service is special, since it triggers a server shutdown
resetService = new SandboxResetService(
ledgerId,
() => resetAndRestartServer(),
authorizer,
errorFactories = ErrorFactories(
new ErrorCodesVersionSwitcher(config.enableSelfServiceErrorCodes)
),
)
executionSequencerFactory <- new ExecutionSequencerFactoryOwner().acquire()
apiServicesOwner = new ApiServices.Owner(
participantId = config.participantId,
Expand Down Expand Up @@ -449,7 +396,6 @@ final class SandboxServer(
maxDeduplicationDurationEnforced = false,
),
)(materializer, executionSequencerFactory, loggingContext)
.map(_.withServices(List(resetService)))
apiServer <- new LedgerApiServer(
apiServicesOwner,
// NOTE: Re-use the same port after reset.
Expand All @@ -463,8 +409,7 @@ final class SandboxServer(
userManagementStore,
servicesExecutionContext,
errorCodesVersionSwitcher,
),
resetService,
)
),
servicesExecutionContext,
metrics,
Expand Down Expand Up @@ -524,7 +469,7 @@ final class SandboxServer(
.getOrElse(SqlStartMode.MigrateAndStart),
currentPort = None,
)
Future.successful(new SandboxState(materializer, metrics, packageStore, apiServerResource))
Future.successful(new SandboxState(apiServerResource))
}
}

Expand Down
Loading

0 comments on commit 954bc5e

Please sign in to comment.