This repository has been archived by the owner on May 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'multi_cluster' into copy_refactor2
Conflicts: src/main/scala/com/twitter/gizzard/thrift/ManagerService.scala
- Loading branch information
Showing
25 changed files
with
252 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/scala/com/twitter/gizzard/nameserver/NameserverState.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.twitter.gizzard.nameserver | ||
|
||
import gizzard.shards.{ShardId, ShardInfo, LinkInfo} | ||
import thrift.conversions.ShardInfo._ | ||
import thrift.conversions.LinkInfo._ | ||
import thrift.conversions.Forwarding._ | ||
import thrift.conversions.Sequences._ | ||
import scala.collection.mutable.ListBuffer | ||
|
||
class NameserverState(initialShards: List[gizzard.shards.ShardInfo], | ||
initialLinks: List[gizzard.shards.LinkInfo], | ||
initialForwardings: List[Forwarding], tableId: Int) { | ||
|
||
|
||
private val shardsById = Map(initialShards.map(s => s.id -> s): _*) | ||
|
||
private val linksByParent = initialLinks.foldLeft(Map[ShardId, List[LinkInfo]]()) { (map, link) => | ||
val key = link.upId | ||
val entry = map.get(key).map(link :: _).getOrElse(List(link)) | ||
|
||
map + (key -> entry) | ||
} | ||
|
||
val forwardings = initialForwardings.filter(_.tableId == tableId) | ||
|
||
var links = new ListBuffer[gizzard.shards.LinkInfo] | ||
var shards = new ListBuffer[gizzard.shards.ShardInfo] | ||
|
||
private def computeSubtree(id: ShardId): Unit = { | ||
shardsById.get(id).foreach { shardInfo => | ||
shards += shardInfo | ||
} | ||
linksByParent.get(id).foreach { linksOption => | ||
linksOption.foreach { link => | ||
links += link | ||
computeSubtree(link.downId) | ||
} | ||
} | ||
} | ||
|
||
forwardings.foreach { forwarding => computeSubtree(forwarding.shardId) } | ||
|
||
def toThrift = { | ||
val thriftForwardings = forwardings.map(_.toThrift).toJavaList | ||
val thriftLinks = links.map(_.toThrift).toJavaList | ||
val thriftShards = shards.map(_.toThrift).toJavaList | ||
new thrift.NameserverState(thriftShards, thriftLinks, thriftForwardings, tableId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.