in app/services/LegacyProxiesScanner.scala [58:121]
def updateProvisionedWriteCapacity(boostTo: Int, tgt:ScanTarget, completionPromise:Option[Promise[Boolean]]):Either[LPSError, Boolean] = {
val rq = DescribeTableRequest.builder().tableName(config.get[String]("proxies.tableName")).build()
val result = ddbClient.describeTable(rq)
if(result.table().tableStatusAsString()!="ACTIVE"){
logger.warn(s"Can't update table status while it is in ${result.table().tableStatusAsString()} state.")
Left(WrongTableState)
} else {
val tableThroughput = result.table().provisionedThroughput()
if(tableThroughput.readCapacityUnits()==0){ //we are not in provisioned mode
return Right(true)
}
val indexName = result.table().globalSecondaryIndexes().get(0).indexName()
val indexThroughput = result.table().globalSecondaryIndexes().get(0).provisionedThroughput()
logger.info(s"index name is $indexName, throughput is $indexThroughput")
if (tableThroughput.writeCapacityUnits() == boostTo && indexThroughput.writeCapacityUnits()==boostTo) {
Right(true)
} else {
val msgToSend = completionPromise match {
case Some(promise) => CheckTableReadyPrms(promise)
case None => CheckTableReady(ScanBucket(tgt))
}
try {
val newTableThroughput = ProvisionedThroughput.builder()
.writeCapacityUnits(boostTo.toLong)
.readCapacityUnits(tableThroughput.readCapacityUnits())
.build()
val newIndexThroughput = ProvisionedThroughput.builder()
.writeCapacityUnits(boostTo.toLong)
.readCapacityUnits(10L)
.build()
val initialRq = UpdateTableRequest.builder()
.tableName(tableName)
val tableRq = if(tableThroughput.writeCapacityUnits() == boostTo){
initialRq
} else {
initialRq.provisionedThroughput(newTableThroughput)
}
val indexRq = if(indexThroughput.writeCapacityUnits()==boostTo){
tableRq
} else {
tableRq.globalSecondaryIndexUpdates(GlobalSecondaryIndexUpdate.builder()
.update(UpdateGlobalSecondaryIndexAction.builder()
.indexName(indexName)
.provisionedThroughput(newIndexThroughput)
.build()
).build()
)
}
ddbClient.updateTable(indexRq.build()) //this raises if it fails, caught just below.
tableReadyTimer = Some(system.scheduler.scheduleAtFixedRate(10 seconds, 1 second, self, msgToSend))
Right(false)
} catch {
case ex:Throwable=>Left(ProviderError(ex))
}
}
}
}