Is it possible to wait synchronous to execute command to see the number of records affected using Java client?

Consider the following method:

 def truncate(startTimes: Seq[Long], durableDelete: Boolean): Unit = {
    logger.info(s"[AerospikeService] - truncate($startTimes) Triggered")
    for ((client, startTime) <- clients.zip(startTimes)) {
      val policy = new WritePolicy()
      policy.durableDelete = durableDelete
      val calendar = Calendar.getInstance()
      calendar.setTimeInMillis(startTime + 1262304000000L) // uses CITRUSLEAF_EPOCH  - see https://discuss.aerospike.com/t/how-to-use-view-and-calulate-last-update-time-lut-for-the-truncate-command/4330

      for ((namespace, sets) <- config.sets.groupBy(_.namespace)) {
        policy.filterExp = Exp.build(
          Exp.and(
            Exp.le(Exp.lastUpdate(), Exp.`val`(calendar)),
            if (sets.size == 1) {
              Exp.eq(Exp.setName(), Exp.`val`(sets.head.name))
            } else {
              Exp.or(sets.map(x => Exp.eq(Exp.setName(), Exp.`val`(x.name))): _*)
            }))

        val statement = new Statement
        statement.setNamespace(namespace)
        client.execute(policy, statement, Operation.delete())
      }
    }
  }

I want to find out the number of records which deleted on client.execute(policy, statement, Operation.delete()), is it possible to wait and get this information?

Are you trying to durably delete records in specific sets prior to a certain LUT? (Sorry for not being more fluent at reading such code).

If that is the purpose, the truncate command can already do that as you can specify an LUT and it will be durable if using the Enterprise Edition (without the need of keeping tombstones around).

If you are trying to do something different, is the question about getting to know the number of affected records prior to executing the command or after?

I don’t believe it is currently possible to find out the number of deleted records in the same operation.To know the number of deleted records, some possible ways include counting records that meet the filter condition prior to actual deletion (by implementing a stream udf count function or reading and counting records on client), and diff’ing the pre and post record counts.

Yes.

The problem with truncate is that it is not shipped via XDR

I want to know the number of records which were affected, but in general i used scanAll as a solution so its solved for now, thanks!

© 2021 Copyright Aerospike, Inc. | All rights reserved. Creators of the Aerospike Database.