Permalink
Browse files

root shard ids should be unique as a set

  • Loading branch information...
Josh Hull
Josh Hull committed Feb 8, 2011
1 parent 384bd3d commit ddaa5e3960dbdd36dd6376db4721b341bf198a03
Showing with 4 additions and 7 deletions.
  1. +4 −7 src/main/scala/com/twitter/gizzard/nameserver/NameServer.scala
@@ -161,17 +161,14 @@ class NameServer[S <: shards.Shard](
}
@throws(classOf[shards.ShardException])
- def getRootShardIds(id: ShardId): Seq[ShardId] = {
+ def getRootShardIds(id: ShardId): Set[ShardId] = {
val ids = nameServerShard.listUpwardLinks(id)
- (try {
- if (ids.isEmpty) List(id) else Nil
- } catch {
- case e:ShardException => Nil
- }) ++ ids.map((i) => getRootShardIds(i.upId)).flatMap((i) => i)
+ val set: Set[ShardId] = if (ids.isEmpty) Set(id) else Set() // type needed to avoid inferring to Collection[ShardId]
+ set ++ ids.flatMap((i) => getRootShardIds(i.upId).toList)
}
def getCommonShardId(ids: Seq[ShardId]) = {
- ids.map(getRootShardIds).reduceLeft((s1, s2) => s1.filter(s2.contains)).firstOption
+ ids.map(getRootShardIds).reduceLeft((s1, s2) => s1.filter(s2.contains)).toSeq.firstOption
}
@throws(classOf[shards.ShardException]) def createShard[S <: shards.Shard](shardInfo: ShardInfo, repository: ShardRepository[S]) = nameServerShard.createShard(shardInfo, repository)

0 comments on commit ddaa5e3

Please sign in to comment.