【发布时间】:2021-08-29 11:05:43
【问题描述】:
我在我的aerospike 恢复过程中使用了以下truncate 实现,这让我可以清楚地了解在操作期间受影响的记录数量:
def truncate(startTime: Long, durableDelete: Boolean): Iterable[Int] = {
// Setting LUT
val calendar = Calendar.getInstance()
logger.info(s"truncate(records s.t LUT <= $startTime = ${calendar.getTime}, durableDelete = $durableDelete) on ${config.toRecoverMap}")
// Define Scan and Write Policies
val writePolicy = new WritePolicy()
val scanPolicy = new ScanPolicy()
writePolicy.durableDelete = durableDelete
scanPolicy.filterExp = Exp.build(Exp.le(Exp.lastUpdate(), Exp.`val`(calendar)))
// Scan all records such as LUT <= startTime
config.toRecoverMap.flatMap { case (namespace, mapOfSetsToBins) =>
for ((set, bins) <- mapOfSetsToBins) yield {
val recordCount = new AtomicInteger(0)
client.scanAll(scanPolicy, namespace, set, new ScanCallback() {
override def scanCallback(key: Key, record: Record): Unit = {
val requiresNullify = bins.filter(record.bins.containsKey(_)).toSeq // Instead of making bulk requests which maybe not be needed and load AS
if (requiresNullify.nonEmpty) {
recordCount.incrementAndGet()
client.put(writePolicy, key, requiresNullify.map(Bin.asNull): _*)
logger.debug {
val (nullified, remains) = record.bins.asScala.partition { case (key, _) => requiresNullify.contains(key) }
s"(#$recordCount): Record $nullified bins of record with userKey: ${key.userKey}, digest: ${Buffer.bytesToHexString(key.digest)} nullified, remains: $remains"
}
}
}
})
问题是操作由于回调而花费了很多时间并且无法在production环境中受到影响,我将实现更改为以下而不是大约2小时,时间减少了到10分钟。
def truncate(startTime: Long, durableDelete: Boolean): Unit = {
// Setting LUT
val calendar = Calendar.getInstance()
logger.info(s"truncate(records s.t LUT <= $startTime = ${calendar.getTime}, durableDelete = $durableDelete) on ${config.toRecoverMap}")
// Define Write Policy
val writePolicy = new WritePolicy()
writePolicy.durableDelete = durableDelete
config.toRecoverMap.flatMap { case (namespace, mapOfSetsToBins) =>
for ((set, bins) <- mapOfSetsToBins) yield {
// Filter all elements s.t lastUpdate <= startTime on $set
writePolicy.filterExp = Exp.build(
Exp.and(
Exp.le(Exp.lastUpdate(), Exp.`val`(calendar)),
Exp.eq(Exp.setName(), Exp.`val`(set)))
)
val statement = new Statement
statement.setNamespace(namespace)
val toNullify = bins.map(Bin.asNull).map(Operation.put).toList
client.execute(writePolicy, statement, toNullify: _*).waitTillComplete(10.seconds.toMillis.toInt, 1.hour.toMillis.toInt)
}
}
}
但问题是我没有像提供给我的第一种方法那样对受影响的记录有任何可见性(查看logger.debug)
是否有解决方案如何以良好的性能运行并提供日志?
谢谢!
【问题讨论】:
标签: aerospike