Skip to content

Commit

Permalink
fix regression
Browse files Browse the repository at this point in the history
  • Loading branch information
briangu committed Jul 13, 2012
1 parent 3247cf7 commit ad15a50
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/main/scala/io/stored/server/common/Projection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.stored.server.common

import org.json.JSONObject
import collection.immutable._
import collection.mutable.{LinkedHashMap, SynchronizedMap, SynchronizedSet}
import collection.mutable.{LinkedHashMap, SynchronizedMap, SynchronizedSet, HashMap}


class Projection(
Expand All @@ -17,7 +17,23 @@ class Projection(
def getFieldValue(key: String) = fields.get(key).get

def getNodeStores(nodeIds: Set[Int]) : Map[IndexStorage, Set[Int]] = {
nodeIds.flatMap(id => Map(nodeHostMap.get(id).get -> Set(id))).toMap
val nodeMap = new HashMap[IndexStorage, collection.mutable.HashSet[Int] with SynchronizedSet[Int]] //with SynchronizedMap[IndexStorage, HashSet[Int] with SynchronizedSet[Int]]
nodeIds.par.foreach { id =>
val node = nodeHostMap.get(id).get
if (!nodeMap.contains(node)) {
nodeMap.synchronized {
if (!nodeMap.contains(node)) {
nodeMap.put(node, new collection.mutable.HashSet[Int] with SynchronizedSet[Int])
}
}
}
nodeMap.get(node).get.add(id)
}
nodeMap.toMap

val resultMap = new HashMap[IndexStorage, Set[Int]]
nodeMap.keySet.foreach( key => resultMap.put(key, nodeMap.get(key).get.toSet))
resultMap.toMap
}

def getNodeIndexStorage(nodeId: Int) : IndexStorage = nodeHostMap.get(nodeId).get
Expand Down

0 comments on commit ad15a50

Please sign in to comment.