Skip to content

Commit

Permalink
T442: logging improved
Browse files Browse the repository at this point in the history
  • Loading branch information
ismagin committed Apr 26, 2017
1 parent dfcefdb commit d3d06c4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/com/wavesplatform/state2/Diff.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/wavesplatform/state2/StateWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit d3d06c4

Please sign in to comment.