Skip to content

Commit

Permalink
Format all Kotlin files with ktfmt 0.46.
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjayVas committed Sep 21, 2023
1 parent 24deb7d commit 98f89e6
Show file tree
Hide file tree
Showing 92 changed files with 127 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ class BenchmarkReport private constructor(val clock: Clock = Clock.systemUTC())
buildMutualTlsChannel(apiFlags.apiTarget, clientCerts, apiFlags.apiCertHost)
.withShutdownTimeout(JavaDuration.ofSeconds(1))
}

override fun run() {
val benchmark =
Benchmark(baseFlags, createMeasurementFlags, channel, apiAuthenticationKey, clock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class CreateMeasurementFlags {
@ArgGroup(exclusive = true, multiplicity = "1", heading = "Event Measurement and params\n")
var eventMeasurementTypeParams = EventMeasurementTypeParams()
}

class PopulationMeasurementParams {
class PopulationInput {
@Option(
Expand Down Expand Up @@ -330,6 +331,7 @@ class CreateMeasurementFlags {
@ArgGroup(exclusive = false, heading = "Population Params\n")
lateinit var populationInputs: PopulationInput
private set

@ArgGroup(exclusive = false, heading = "Set Population Data Provider\n")
lateinit var populationDataProviderInput: PopulationDataProviderInput

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ class CreateMeasurement : Runnable {
}
}
}

private fun getEventDataProviderEntry(
eventDataProviderInput:
CreateMeasurementFlags.MeasurementParams.EventMeasurementParams.EventDataProviderInput,
Expand Down Expand Up @@ -931,6 +932,7 @@ private class DataProviders {
required = true,
)
private lateinit var dataProviderName: String

@Command(name = "replace-required-duchies", description = ["Replaces DataProvider's duchy list"])
fun replaceRequiredDuchyList(
@Option(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.wfanet.measurement.common.identity.DuchyInfo
/** JUnit rule that sets the global list of all valid Duchy ids to [duchyIds]. */
class DuchyIdSetter(val duchyIds: Set<String>) : TestRule {
constructor(duchyIds: Iterable<String>) : this(duchyIds.toSet())

constructor(vararg duchyIds: String) : this(duchyIds.toSet())

override fun apply(base: Statement, description: Description): Statement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private constructor(
val op: String
) {
data class Replace(val path: String, val value: Any) : JsonPatchOperation("replace")

data class Add(val path: String, val value: Any) : JsonPatchOperation("add")

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ abstract class MillBase(

private inner class CpuDurationLogger(private val getTimeMillis: () -> Long) {
private val start = getTimeMillis()

suspend fun logStageDurationMetric(
token: ComputationToken,
metricName: String,
Expand All @@ -563,11 +564,13 @@ abstract class MillBase(
logStageDurationMetric(token, metricName, time, histogram)
}
}

private fun cpuDurationLogger(): CpuDurationLogger = CpuDurationLogger(this::getCpuTimeMillis)

@OptIn(ExperimentalTime::class)
private inner class WallDurationLogger() {
private val timeMark = TimeSource.Monotonic.markNow()

suspend fun logStageDurationMetric(
token: ComputationToken,
metricName: String,
Expand All @@ -577,6 +580,7 @@ abstract class MillBase(
logStageDurationMetric(token, metricName, time, histogram)
}
}

private fun wallDurationLogger(): WallDurationLogger = WallDurationLogger()

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ class LiquidLegionsV2Mill(
directoryPath = Paths.get("any_sketch_java/src/main/java/org/wfanet/anysketch/crypto")
)
}

private val logger: Logger = Logger.getLogger(this::class.java.name)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ package org.wfanet.measurement.duchy.db.computation

/** Deals with stage specific details for MPC protocols. */
interface ComputationProtocolStageDetailsHelper<
ProtocolT, StageT, StageDetailsT, ComputationDetailsT> {
ProtocolT,
StageT,
StageDetailsT,
ComputationDetailsT
> {
/** Creates the stage specific details for a given computation stage. */
fun detailsFor(stage: StageT, computationDetails: ComputationDetailsT): StageDetailsT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ interface ProtocolStageEnumHelper<StageT> {
fun validInitialStage(stage: StageT): Boolean {
return stage in validInitialStages
}

val validTerminalStages: Set<StageT>

fun validTerminalStage(stage: StageT): Boolean = stage in validTerminalStages

val validSuccessors: Map<StageT, Set<StageT>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,7 @@ private constructor(
globalId = it.globalComputationId,
)
}
.firstOrNull()
?: return null
.firstOrNull() ?: return null

updateToken(claimed) { existing ->
claimedComputationIds.add(existing.globalComputationId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ class PostgresComputationsService(
KeyCase.REQUISITION_KEY ->
computationReader.readComputationToken(client, request.requisitionKey)
KeyCase.KEY_NOT_SET -> failGrpc(Status.INVALID_ARGUMENT) { "key not set" }
}
?: failGrpc(Status.NOT_FOUND) { "Computation not found" }
} ?: failGrpc(Status.NOT_FOUND) { "Computation not found" }

return token.toGetComputationTokenResponse()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ class ClaimWork<ProtocolT, StageT>(
unclaimedTask.computationId,
stageLongValue,
currentAttempt
)
?: throw IllegalStateException("Computation stage details is missing.")
) ?: throw IllegalStateException("Computation stage details is missing.")
// If the computation was locked, but that lock was expired we need to finish off the
// current attempt of the stage.
updateComputationStageAttempt(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ suspend fun PostgresWriter.TransactionScope.checkComputationUnmodified(
transactionContext
.executeQuery(sql)
.consume { row -> row.get<Instant>("UpdateTime") }
.firstOrNull()
?: throw ComputationNotFoundException(localId)
.firstOrNull() ?: throw ComputationNotFoundException(localId)
val updateTimeMillis = updateTime.toEpochMilli()
if (editVersion != updateTimeMillis) {
val editVersionTime = Instant.ofEpochMilli(editVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ import org.wfanet.measurement.internal.duchy.copy

/** Implementation of [ComputationsDatabaseTransactor] using GCP Spanner Database. */
class GcpSpannerComputationsDatabaseTransactor<
ProtocolT, StageT, StageDT : Message, ComputationDT : Message>(
ProtocolT,
StageT,
StageDT : Message,
ComputationDT : Message
>(
private val databaseClient: AsyncDatabaseClient,
private val computationMutations: ComputationMutations<ProtocolT, StageT, StageDT, ComputationDT>,
private val clock: Clock = Clock.systemUTC()
Expand Down Expand Up @@ -319,8 +323,7 @@ class GcpSpannerComputationsDatabaseTransactor<
val detailsBytes =
txn
.readRow("Computations", Key.of(token.localId), listOf("ComputationDetails"))
?.getBytesAsByteArray("ComputationDetails")
?: error("Computation missing $token")
?.getBytesAsByteArray("ComputationDetails") ?: error("Computation missing $token")
val details = computationMutations.parseComputationDetails(detailsBytes)
txn.buffer(
computationMutations.updateComputation(
Expand Down Expand Up @@ -399,8 +402,7 @@ class GcpSpannerComputationsDatabaseTransactor<
"RequisitionsByExternalId",
Key.of(it.key.externalRequisitionId, it.key.requisitionFingerprint.toGcloudByteArray()),
listOf("ComputationId", "RequisitionId")
)
?: error("No Computation found row for this requisition: ${it.key}")
) ?: error("No Computation found row for this requisition: ${it.key}")
txn.buffer(
computationMutations.updateRequisition(
localComputationId = row.getLong("ComputationId"),
Expand Down Expand Up @@ -645,8 +647,7 @@ class GcpSpannerComputationsDatabaseTransactor<
externalRequisitionKey.requisitionFingerprint.toGcloudByteArray()
),
listOf("ComputationId", "RequisitionId")
)
?: error("No Computation found row for this requisition: $externalRequisitionKey")
) ?: error("No Computation found row for this requisition: $externalRequisitionKey")
val localComputationId = row.getLong("ComputationId")
val requisitionId = row.getLong("RequisitionId")
require(localComputationId == token.localId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class GlobalIdsQuery<StageT>(
AND Protocol = @protocol
"""
}

override val sql: Statement =
statement(parameterizedQuery) {
bind("stages")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ class UnclaimedTasksQuery<StageT>(
LIMIT 50
"""
}

override val sql: Statement =
Statement.newBuilder(parameterizedQueryString)
.bind("current_time")
.to(timestamp)
.bind("protocol")
.to(protocol)
.build()

override fun asResult(struct: Struct): UnclaimedTaskQueryResult<StageT> =
UnclaimedTaskQueryResult(
computationId = struct.getLong("ComputationId"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ class UnfinishedAttemptQuery<StageT>(
AND EndTime IS NULL
"""
}

override val sql: Statement =
Statement.newBuilder(parameterizedQueryString).bind("local_id").to(localId).build()

override fun asResult(struct: Struct): UnfinishedAttemptQueryResult<StageT> =
UnfinishedAttemptQueryResult(
computationId = localId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ContinuationTokenReader() : SqlBasedQuery<ContinuationTokenReaderResult> {
Limit 1
"""
}

override val sql: Statement = Statement.newBuilder(parameterizedQueryString).build()

override fun asResult(struct: Struct): ContinuationTokenReaderResult =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ class AsyncComputationControlService(
val outputBlob =
token.blobsList.firstOrNull {
it.blobId == request.blobId && it.dependencyType == ComputationBlobDependency.OUTPUT
}
?: failGrpc(Status.FAILED_PRECONDITION) { "No output blob with ID ${request.blobId}" }
} ?: failGrpc(Status.FAILED_PRECONDITION) { "No output blob with ID ${request.blobId}" }
if (outputBlob.path.isNotEmpty()) {
if (outputBlob.path != request.blobPath) {
throw Status.FAILED_PRECONDITION.withDescription(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ class ComputationsService(
KeyCase.REQUISITION_KEY -> computationsDatabase.readComputationToken(request.requisitionKey)
KeyCase.KEY_NOT_SET ->
throw Status.INVALID_ARGUMENT.withDescription("key not set").asRuntimeException()
}
?: throw Status.NOT_FOUND.asRuntimeException()
} ?: throw Status.NOT_FOUND.asRuntimeException()

return computationToken.toGetComputationTokenResponse()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ private fun Expr.nonOperativeComparisonNode(operativeFields: Set<String>): Boole
val selectExpr =
listOf(callExpr.argsList[0], callExpr.argsList[1])
.singleOrNull { it.hasSelectExpr() }
?.selectExpr
?: return false
?.selectExpr ?: return false

val fieldName: String = getFieldName(selectExpr)
if (!operativeFields.contains(fieldName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class GaussianNoiser(privacyParams: DpParams, random: Random) : AbstractNoiser()

return NormalDistribution(RandomGeneratorFactory.createRandomGenerator(random), 0.0, sigma)
}

override val variance: Double
get() = distribution.numericalVariance

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ class InMemoryBackingStoreTransactionContext(
val lastEntry =
transactionReferenceLedger[reference.measurementConsumerId]
?.filter { it.referenceId == reference.referenceId }
?.maxByOrNull { it.createTime }
?: return false
?.maxByOrNull { it.createTime } ?: return false

return lastEntry.isRefund == reference.isRefund
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ private const val MAX_BATCH_INSERT = 1000
*/
class PostgresBackingStore(createConnection: () -> Connection) : PrivacyBudgetLedgerBackingStore {
private val connection = createConnection()

init {
connection.autoCommit = false
}

private var previousTransactionContext: PostgresBackingStoreTransactionContext? = null

override fun startTransaction(): PostgresBackingStoreTransactionContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.Referenc

abstract class AbstractPrivacyBudgetLedgerStoreTest {
protected abstract fun createBackingStore(): PrivacyBudgetLedgerBackingStore

protected abstract fun recreateSchema()

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ import org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.InMemory

class TestInMemoryBackingStore : InMemoryBackingStore() {
fun getDpBalancesMap() = dpBalances.toMap()

fun getAcdpBalancesMap() = acdpBalances.toMap()
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class ExchangesDeletion(
}
}
}

companion object {
private val logger: Logger = Logger.getLogger(this::class.java.name)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class PendingMeasurementsCancellation(
.counterBuilder("pending_measurements_cancellation_total")
.setDescription("Total number of pending measurements cancelled under retention policy")
.build()

fun run() {
if (timeToLive.toMillis() == 0L) {
logger.warning("Time to live cannot be 0. TTL=$timeToLive")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ object Llv2ProtocolConfig {
const val name = "llv2"
lateinit var protocolConfig: ProtocolConfig.LiquidLegionsV2
private set

lateinit var duchyProtocolConfig: DuchyProtocolConfig.LiquidLegionsV2
private set

lateinit var requiredExternalDuchyIds: Set<String>
private set

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ object RoLlv2ProtocolConfig {
const val name = "rollv2"
lateinit var protocolConfig: ProtocolConfig.LiquidLegionsV2
private set

lateinit var duchyProtocolConfig: DuchyProtocolConfig.LiquidLegionsV2
private set

lateinit var requiredExternalDuchyIds: Set<String>
private set

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,11 @@ class SpannerAccountsService(
client.singleUse(),
request.identity.issuer,
request.identity.subject
)
?: failGrpc(Status.NOT_FOUND) { "Identity not found" }
) ?: failGrpc(Status.NOT_FOUND) { "Identity not found" }

return AccountReader()
.readByInternalAccountId(client.singleUse(), identityResult.accountId)
?.account
?: failGrpc(Status.NOT_FOUND) { "Account not found" }
?.account ?: failGrpc(Status.NOT_FOUND) { "Account not found" }
}

override suspend fun generateOpenIdRequestParams(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ class SpannerApiKeysService(
val apiKey =
MeasurementConsumerApiKeyReader()
.readByAuthenticationKeyHash(txn, request.authenticationKeyHash)
?.apiKey
?: failGrpc(Status.NOT_FOUND) { "ApiKey not found for hash" }
?.apiKey ?: failGrpc(Status.NOT_FOUND) { "ApiKey not found for hash" }

return MeasurementConsumerReader()
.readByExternalMeasurementConsumerId(txn, ExternalId(apiKey.externalMeasurementConsumerId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class SpannerDataProvidersService(
}
return CreateDataProvider(request).execute(client, idGenerator)
}

override suspend fun getDataProvider(request: GetDataProviderRequest): DataProvider {
return DataProviderReader()
.readByExternalDataProviderId(client.singleUse(), ExternalId(request.externalDataProviderId))
?.dataProvider
?: failGrpc(Status.NOT_FOUND) { "DataProvider not found" }
?.dataProvider ?: failGrpc(Status.NOT_FOUND) { "DataProvider not found" }
}

override suspend fun replaceDataProviderRequiredDuchies(
Expand Down
Loading

0 comments on commit 98f89e6

Please sign in to comment.