Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#28822] Don't advertise temporary references in the compression table #28823

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -7,12 +7,10 @@ package akka.remote.artery.compress
import java.util.function.LongFunction

import scala.annotation.tailrec

import akka.actor.ActorRef
import akka.actor.ActorSystem
import akka.actor.Address
import akka.actor.{ ActorRef, ActorSystem, Address, InternalActorRef }
import akka.event.Logging
import akka.event.LoggingAdapter
import akka.pattern.PromiseActorRef
import akka.remote.artery._
import akka.util.{ unused, OptionVal }
import org.agrona.collections.Long2ObjectHashMap
Expand Down Expand Up @@ -192,6 +190,21 @@ private[remote] final class InboundActorRefCompression(
outboundContext.sendControl(
CompressionProtocol.ActorRefCompressionAdvertisement(inboundContext.localAddress, table))
}

override protected def buildTableForAdvertisement(elements: Iterator[ActorRef]): Map[ActorRef, Int] = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, not needed for manifests

val mb = Map.newBuilder[ActorRef, Int]
var idx = 0
elements.foreach {
case ref: InternalActorRef =>
val isTemporaryRef = (ref.isLocal && ref.isInstanceOf[PromiseActorRef]) ||
(!ref.isLocal && ref.path.elements.head == "temp")
if (!isTemporaryRef) {
mb += ref -> idx
idx += 1
}
}
mb.result()
}
}

/**
Expand Down Expand Up @@ -493,15 +506,17 @@ private[remote] abstract class InboundCompression[T >: Null](
protected def advertiseCompressionTable(association: OutboundContext, table: CompressionTable[T]): Unit

private def prepareCompressionAdvertisement(nextTableVersion: Byte): CompressionTable[T] = {
// TODO optimised somewhat, check if still to heavy; could be encoded into simple array
val mappings: Map[T, Int] = {
val mb = Map.newBuilder[T, Int]
mb ++= heavyHitters.iterator.zipWithIndex
mb.result()
}
val mappings: Map[T, Int] = buildTableForAdvertisement(heavyHitters.iterator)
CompressionTable(originUid, nextTableVersion, mappings)
}

protected def buildTableForAdvertisement(elements: Iterator[T]): Map[T, Int] = {
// TODO optimised somewhat, check if still to heavy; could be encoded into simple array
val mb = Map.newBuilder[T, Int]
mb ++= elements.zipWithIndex
mb.result()
}

override def toString =
s"""${Logging.simpleName(getClass)}(countMinSketch: $cms, heavyHitters: $heavyHitters)"""

Expand Down