From d3d06c431ed7fe422d3ecae7110dd35763814b31 Mon Sep 17 00:00:00 2001 From: Ilya Smagin Date: Wed, 26 Apr 2017 15:07:48 +0300 Subject: [PATCH] T442: logging improved --- .../wavesplatform/state2/BlockchainUpdaterImpl.scala | 9 +++++++-- src/main/scala/com/wavesplatform/state2/Diff.scala | 10 +++++----- .../scala/com/wavesplatform/state2/StateWriter.scala | 2 +- .../com/wavesplatform/state2/diffs/BlockDiffer.scala | 6 +++--- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/scala/com/wavesplatform/state2/BlockchainUpdaterImpl.scala b/src/main/scala/com/wavesplatform/state2/BlockchainUpdaterImpl.scala index a5c40741a8a..fb1dcf10982 100644 --- a/src/main/scala/com/wavesplatform/state2/BlockchainUpdaterImpl.scala +++ b/src/main/scala/com/wavesplatform/state2/BlockchainUpdaterImpl.scala @@ -19,9 +19,14 @@ class BlockchainUpdaterImpl(persisted: StateWriter with StateReader, settings: F private val unsafeDifferByRange: (StateReader, (Int, Int)) => BlockDiff = { case (sr, (from, to)) => log.debug(s"Reading blocks from $from to $to") - val blocks = Range(from, to).map(bc.blockAt(_).get) + val blocks = Range(from, to).foldLeft((List.empty[Block], 0)) { case ((acc, counter), i) => + if (counter % 1000 == 0) { + log.debug(s"Read block $counter of Range($from, $to)") + } + (bc.blockAt(i).get +: acc, counter + 1) + }._1.reverse log.debug(s"Blocks read from $from to $to") - val r = BlockDiffer.unsafeDiffMany(settings, m => log.info(m))(sr, blocks) + val r = BlockDiffer.unsafeDiffMany(settings)(sr, blocks) log.debug(s"Diff for Range($from, $to) rebuilt") r } diff --git a/src/main/scala/com/wavesplatform/state2/Diff.scala b/src/main/scala/com/wavesplatform/state2/Diff.scala index 88c800ad8cf..d5f41d15dab 100644 --- a/src/main/scala/com/wavesplatform/state2/Diff.scala +++ b/src/main/scala/com/wavesplatform/state2/Diff.scala @@ -39,13 +39,13 @@ case class Diff(transactions: Map[ByteArray, (Int, Transaction, Set[Account])], leaseState: Map[ByteArray, Boolean]) { lazy val accountTransactionIds: Map[Account, List[ByteArray]] = { - val map: List[(Account, List[(Int, Long, ByteArray)])] = transactions.toList - .flatMap { case (id, (h, tx, accs)) => accs.map(acc => acc -> List((h, tx.timestamp, id))) } - val groupedByAcc = map.foldLeft(Map.empty[Account, List[(Int, Long, ByteArray)]]) { case (m, (acc, list)) => - m.combine(Map(acc -> list)) + val map: List[(Account, Set[(Int, Long, ByteArray)])] = transactions.toList + .flatMap { case (id, (h, tx, accs)) => accs.map(acc => acc -> Set((h, tx.timestamp, id))) } + val groupedByAcc = map.foldLeft(Map.empty[Account, Set[(Int, Long, ByteArray)]]) { case (m, (acc, set)) => + m.combine(Map(acc -> set)) } groupedByAcc - .mapValues(l => l.sortBy { case ((h, t, id)) => (-h, -t) }) // fresh head ([h=2, h=1, h=0]) + .mapValues(l => l.toList.sortBy { case ((h, t, id)) => (-h, -t) }) // fresh head ([h=2, h=1, h=0]) .mapValues(_.map(_._3)) } } diff --git a/src/main/scala/com/wavesplatform/state2/StateWriter.scala b/src/main/scala/com/wavesplatform/state2/StateWriter.scala index c838975212b..20806f1aa90 100644 --- a/src/main/scala/com/wavesplatform/state2/StateWriter.scala +++ b/src/main/scala/com/wavesplatform/state2/StateWriter.scala @@ -126,7 +126,7 @@ object StateWriterImpl extends ScorexLogging { (r, t1 - t0) } - def measurePersist[F[_] <: TraversableOnce[_], A](s: String)(fa: F[A])(f: F[A] => Unit): Unit = { + def measurePersist[F[_] <: TraversableOnce[_], A](s: String)(fa: => F[A])(f: F[A] => Unit): Unit = { val (_, time) = withTime(f(fa)) log.debug(s"Persisting $s(size=${fa.size}) took ${time}ms") } diff --git a/src/main/scala/com/wavesplatform/state2/diffs/BlockDiffer.scala b/src/main/scala/com/wavesplatform/state2/diffs/BlockDiffer.scala index 835c32fdba8..25446b0e19b 100644 --- a/src/main/scala/com/wavesplatform/state2/diffs/BlockDiffer.scala +++ b/src/main/scala/com/wavesplatform/state2/diffs/BlockDiffer.scala @@ -58,15 +58,15 @@ object BlockDiffer extends ScorexLogging { } - def unsafeDiffMany(settings: FunctionalitySettings, log: (String) => Unit = _ => ())(s: StateReader, blocks: Seq[Block]): BlockDiff = { + def unsafeDiffMany(settings: FunctionalitySettings)(s: StateReader, blocks: Seq[Block]): BlockDiff = { val r = blocks.foldLeft(Monoid[BlockDiff].empty) { case (diff, block) => val blockDiff = apply(settings)(new CompositeStateReader(s, diff), block).explicitGet() if (diff.heightDiff % 1000 == 0) { - log(s"Rebuilt ${diff.heightDiff} blocks out of ${blocks.size}") + log.info(s"Rebuilt ${diff.heightDiff} blocks out of ${blocks.size}") } Monoid[BlockDiff].combine(diff, blockDiff) } - log(s"Rebuild of ${blocks.size} completed") + log.info(s"Rebuild of ${blocks.size} blocks completed") r } }