Skip to content

Commit

Permalink
core: remove SmallHashMap and QueryIndex (#1702)
Browse files Browse the repository at this point in the history
Phase out usage of legacy QueryIndex and SmallHashMap
implementation. Helps avoid regressions with things
picking up the old index implementation and reduce
code complexity.
  • Loading branch information
brharrington authored Oct 12, 2024
1 parent 85bb3a0 commit d14f324
Show file tree
Hide file tree
Showing 34 changed files with 84 additions and 2,452 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
package com.netflix.atlas.core.model

import java.time.Duration

import com.netflix.atlas.core.model.ConsolidationFunction.SumOrAvgCf
import com.netflix.atlas.core.util.Math
import com.netflix.atlas.core.util.SmallHashMap
import com.netflix.atlas.core.util.SortedTagMap
import com.netflix.atlas.core.util.Strings

sealed trait DataExpr extends TimeSeriesExpr with Product {
Expand Down Expand Up @@ -76,7 +75,7 @@ sealed trait DataExpr extends TimeSeriesExpr with Product {

object DataExpr {

private val unknown = SmallHashMap("name" -> "unknown")
private val unknown = SortedTagMap("name" -> "unknown")

private def defaultLabel(expr: DataExpr, ts: TimeSeries): String = {
val label = expr match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package com.netflix.atlas.core.model

import com.netflix.atlas.core.util.ArrayHelper
import com.netflix.atlas.core.util.Hash
import com.netflix.atlas.core.util.SmallHashMap
import com.netflix.atlas.core.util.SortedTagMap

import java.nio.ByteBuffer
Expand Down Expand Up @@ -61,16 +60,6 @@ class ItemIdCalculator {
tags match {
case ts: SortedTagMap =>
ts.copyToArray(pairs)
case ts: SmallHashMap[String, String] =>
var pos = 0
val iter = ts.entriesIterator
while (iter.hasNext) {
pairs(pos) = iter.key
pairs(pos + 1) = iter.value
iter.nextEntry()
pos += 2
}
ArrayHelper.sortPairs(pairs, length)
case _ =>
var pos = 0
tags.foreachEntry { (k, v) =>
Expand Down
14 changes: 4 additions & 10 deletions atlas-core/src/main/scala/com/netflix/atlas/core/model/Query.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.netflix.atlas.core.model

import com.netflix.atlas.core.stacklang.Interpreter
import com.netflix.atlas.core.util.SmallHashMap
import com.netflix.atlas.core.util.SortedTagMap
import com.netflix.spectator.impl.PatternMatcher

sealed trait Query extends Expr {
Expand Down Expand Up @@ -285,7 +285,7 @@ object Query {

def matches(tags: Map[String, String]): Boolean = {
tags match {
case ts: SmallHashMap[String, String] =>
case ts: SortedTagMap =>
val v = ts.getOrNull(k)
v != null && check(v)
case _ =>
Expand All @@ -294,18 +294,12 @@ object Query {
}

def matchesAny(tags: Map[String, List[String]]): Boolean = {
tags match {
case ts: SmallHashMap[String, ?] =>
val vs = ts.getOrNull(k).asInstanceOf[List[String]]
vs != null && vs.exists(check)
case _ =>
tags.get(k).exists(_.exists(check))
}
tags.get(k).exists(_.exists(check))
}

def couldMatch(tags: Map[String, String]): Boolean = {
tags match {
case ts: SmallHashMap[String, String] =>
case ts: SortedTagMap =>
val v = ts.getOrNull(k)
v == null || check(v)
case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package com.netflix.atlas.core.model

import com.netflix.atlas.core.util.InternMap
import com.netflix.atlas.core.util.Interner
import com.netflix.atlas.core.util.SmallHashMap
import com.netflix.atlas.core.util.SortedTagMap

/**
* Helper functions for manipulating tagged items.
Expand Down Expand Up @@ -57,7 +57,7 @@ object TaggedItem {
val iter = tags.iterator.map { t =>
strInterner.intern(t._1) -> strInterner.intern(t._2)
}
val smallMap = SmallHashMap(tags.size, iter)
val smallMap = SortedTagMap(iter)
tagsInterner.intern(smallMap)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import com.netflix.spectator.api.Utils
final case class IdMap(id: Id) extends scala.collection.immutable.Map[String, String] {

override def removed(key: String): Map[String, String] = {
SmallHashMap(this).removed(key)
SortedTagMap(this).removed(key)
}

override def updated[V1 >: String](key: String, value: V1): Map[String, V1] = {
SmallHashMap(this).updated(key, value)
SortedTagMap(this).updated(key, value)
}

override def get(key: String): Option[String] = {
Expand Down
Loading

0 comments on commit d14f324

Please sign in to comment.