Skip to content

Commit

Permalink
fix uncleared buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Nov 11, 2024
1 parent d043bc2 commit 6bdd9ce
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,14 @@ trait ExtraIndexerBase extends Actor with Stash with ScorexLogging {
// perform segmentation on big addresses and save their internal segment buffer
trees.values.foreach { tree =>
tree.buffer.values.foreach(seg => segments.put(seg.id, seg))
tree.buffer.clear()
tree.splitToSegments.foreach(seg => segments.put(seg.id, seg))
}

// perform segmentation on big tokens and save their internal segment buffer
tokens.values.foreach { token =>
token.buffer.values.foreach(seg => segments.put(seg.id, seg))
token.buffer.clear()
token.splitToSegments.foreach(seg => segments.put(seg.id, seg))
}

Expand Down Expand Up @@ -593,7 +595,9 @@ object ExtraIndexer {
0
}))

def getIndex(key: Array[Byte], history: ErgoHistoryReader): ByteBuffer = getIndex(key, history.historyStorage)
def getIndex(key: Array[Byte], history: ErgoHistoryReader): ByteBuffer = {
getIndex(key, history.historyStorage)
}

def apply(chainSettings: ChainSettings, cacheSettings: CacheSettings)(implicit system: ActorSystem): ActorRef = {
val props = Props.create(classOf[ExtraIndexer], cacheSettings, chainSettings.addressEncoder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ case class IndexedErgoAddress(treeHash: ModifierId,
* @return this address
*/
override private[extra] def spendBox(iEb: IndexedErgoBox, historyOpt: Option[ErgoHistoryReader] = None)(implicit ae: ErgoAddressEncoder): IndexedErgoAddress = {
if(historyOpt.isDefined)
if(historyOpt.isDefined) {
findAndModBox(iEb.globalIndex, historyOpt.get)
}
balanceInfo.foreach(_.subtract(iEb.box))
this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract class Segment[T <: Segment[_] : ClassTag](val parentId: ModifierId,
/**
* Internal segment buffer
*/
private[extra] val buffer: mutable.HashMap[ModifierId,T] = new mutable.HashMap[ModifierId,T]
private[extra] val buffer: mutable.HashMap[ModifierId, T] = new mutable.HashMap[ModifierId, T]

/**
* Number of segments in database containing box numbers
Expand Down Expand Up @@ -81,13 +81,11 @@ abstract class Segment[T <: Segment[_] : ClassTag](val parentId: ModifierId,
val mid = (low + high) >>> 1
segmentId = boxSegmentId(parentId, mid)
buffer.get(segmentId).orElse(history.typedExtraIndexById[T](idMod(segmentId))).foreach { segment =>
if(abs(segment.boxes.head) < boxNumAbs &&
abs(segment.boxes.last) < boxNumAbs)
if (abs(segment.boxes.head) < boxNumAbs && abs(segment.boxes.last) < boxNumAbs) {
low = mid + 1
else if(abs(segment.boxes.head) > boxNumAbs &&
abs(segment.boxes.last) > boxNumAbs)
} else if (abs(segment.boxes.head) > boxNumAbs && abs(segment.boxes.last) > boxNumAbs) {
high = mid - 1
else {
} else {
low = high + 1 // break
buffer.put(segmentId, segment)
}
Expand Down

0 comments on commit 6bdd9ce

Please sign in to comment.