in storehaus-core/src/main/scala/com/twitter/storehaus/ShardedStore.scala [95:115]
override def multiPut[T <: (K1, K2)](kvs: Map[T, Option[V]]): Map[T, Future[Unit]] = {
val pivoted: Map[K1, Map[K2, Option[V]]] =
kvs.groupBy { case ((k1, _), _) => k1 } // Group by the outer key:
// Keep just the inner key in each group
.mapValues { maptv => maptv.map { case ((_, k2), v) => (k2, v) } }
val shards: Map[K1, Future[Option[S]]] = routes.multiGet(pivoted.keySet)
val shardMap: Map[K1, Future[Map[K2, Future[Unit]]]] = shards.map { case (k1, fos) =>
val innerm = fos.map {
case None =>
val error = Future.exception[Unit](new MissingShardException(k1))
pivoted(k1).mapValues { _ => error }
case Some(s) => s.multiPut(pivoted(k1))
}
(k1, innerm)
}
// Do the lookup:
CollectionOps.zipWith(kvs.keySet) { t =>
shardMap(t._1).flatMap { m2 => m2(t._2) }
}
}