This repository has been archived by the owner on May 22, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check in first pass at new NameServer API
note that tests dont pass atm
- Loading branch information
Ed Ceaser
committed
Mar 18, 2010
1 parent
e767fc0
commit cc3026e
Showing
14 changed files
with
188 additions
and
125 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
79 changes: 79 additions & 0 deletions
79
src/main/scala/com/twitter/gizzard/nameserver/CachingNameServer.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,79 @@ | ||
package com.twitter.gizzard.nameserver | ||
|
||
import java.util.TreeMap | ||
import scala.collection.mutable | ||
import shards._ | ||
|
||
|
||
class CachingNameServer(nameServer: ManagingNameServer, mappingFunction: Long => Long) | ||
extends ForwardingNameServer with ManagingNameServer { | ||
val children = List() | ||
val shardInfo = new ShardInfo("com.twitter.gizzard.nameserver.CachingNameServer", "", "") | ||
val weight = 1 // hardcode for now | ||
|
||
@volatile protected var shardInfos = mutable.Map.empty[Int, ShardInfo] | ||
@volatile private var familyTree: scala.collection.Map[Int, Seq[ChildInfo]] = null | ||
@volatile private var forwardings: scala.collection.Map[List[Int], TreeMap[Long, ShardInfo]] = null | ||
|
||
reload() | ||
|
||
def getShardInfo(id: Int) = shardInfos(id) | ||
|
||
def reload() { | ||
val newShardInfos = mutable.Map.empty[Int, ShardInfo] | ||
nameServer.listShards().foreach { shardInfo => | ||
newShardInfos += (shardInfo.shardId -> shardInfo) | ||
} | ||
|
||
val newFamilyTree = nameServer.listShardChildren() | ||
|
||
val newForwardings = new mutable.HashMap[List[Int], TreeMap[Long, ShardInfo]] | ||
nameServer.getForwardings().foreach { forwarding => | ||
val treeMap = newForwardings.getOrElseUpdate(forwarding.tableId, new TreeMap[Long, ShardInfo]) | ||
treeMap.put(forwarding.baseId, newShardInfos(forwarding.shardId)) | ||
} | ||
|
||
shardInfos = newShardInfos | ||
familyTree = newFamilyTree | ||
forwardings = newForwardings | ||
} | ||
|
||
def findCurrentForwarding(tableId: List[Int], id: Long) = { | ||
forwardings.get(tableId).flatMap { bySourceIds => | ||
val item = bySourceIds.floorEntry(mappingFunction(id)) | ||
if (item != null) { | ||
Some(item.getValue) | ||
} else { | ||
None | ||
} | ||
} getOrElse { | ||
throw new NonExistentShard | ||
} | ||
} | ||
|
||
// delegation | ||
def listShardChildren(parentId: Int) = nameServer.listShardChildren(parentId) | ||
def createShard(shardInfo: ShardInfo) = nameServer.createShard(shardInfo) | ||
def findShard(shardInfo: ShardInfo) = nameServer.findShard(shardInfo) | ||
def getShard(shardId: Int) = nameServer.getShard(shardId) | ||
def updateShard(shardInfo: ShardInfo) = nameServer.updateShard(shardInfo) | ||
def deleteShard(shardId: Int) = nameServer.deleteShard(shardId) | ||
def addChildShard(parentShardId: Int, childShardId: Int, weight: Int) = nameServer.addChildShard(parentShardId, childShardId, weight) | ||
def removeChildShard(parentShardId: Int, childShardId: Int) = nameServer.removeChildShard(parentShardId, childShardId) | ||
def replaceChildShard(oldChildShardId: Int, newChildShardId: Int) = nameServer.replaceChildShard(oldChildShardId, newChildShardId) | ||
def markShardBusy(shardId: Int, busy: Busy.Value) = nameServer.markShardBusy(shardId, busy) | ||
def setForwarding(forwarding: Forwarding) = nameServer.setForwarding(forwarding) | ||
def replaceForwarding(oldShardId: Int, newShardId: Int) = nameServer.replaceForwarding(oldShardId, newShardId) | ||
def getForwarding(tableId: List[Int], baseId: Long) = nameServer.getForwarding(tableId, baseId) | ||
def getForwardingForShard(shardId: Int) = nameServer.getForwardingForShard(shardId) | ||
def getForwardings() = nameServer.getForwardings() | ||
def shardIdsForHostname(hostname: String, className: String) = nameServer.shardIdsForHostname(hostname, className) | ||
def listShards() = nameServer.listShards() | ||
def listShardChildren() = nameServer.listShardChildren() | ||
def shardsForHostname(hostname: String, className: String) = nameServer.shardsForHostname(hostname, className) | ||
def getBusyShards() = nameServer.getBusyShards() | ||
def getParentShard(shardId: Int) = nameServer.getParentShard(shardId) | ||
def getRootShard(shardId: Int) = nameServer.getRootShard(shardId) | ||
def getChildShardsOfClass(parentShardId: Int, className: String) = nameServer.getChildShardsOfClass(parentShardId, className) | ||
def rebuildSchema() = nameServer.rebuildSchema() | ||
} |
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
12 changes: 12 additions & 0 deletions
12
src/main/scala/com/twitter/gizzard/nameserver/ForwardingNameServer.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,12 @@ | ||
package com.twitter.gizzard.nameserver | ||
|
||
import shards._ | ||
|
||
|
||
trait ForwardingNameServer { | ||
def findCurrentForwarding(tableId: List[Int], id: Long): ShardInfo | ||
def getShardInfo(shardId: Int): ShardInfo | ||
// def findShardById(shardId: Int, weight: Int): ShardInfo | ||
// def findShardById(shardId: Int): ShardInfo = findShardById(shardId, 1) | ||
} | ||
|
35 changes: 35 additions & 0 deletions
35
src/main/scala/com/twitter/gizzard/nameserver/ManagingNameServer.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,35 @@ | ||
package com.twitter.gizzard.nameserver | ||
|
||
import shards._ | ||
import scala.collection.Map | ||
|
||
|
||
trait ManagingNameServer extends Shard { | ||
def createShard(shardInfo: ShardInfo): Int | ||
def findShard(shardInfo: ShardInfo): Int | ||
def getShard(shardId: Int): ShardInfo | ||
def updateShard(shardInfo: ShardInfo) | ||
def deleteShard(shardId: Int) | ||
def addChildShard(parentShardId: Int, childShardId: Int, weight: Int) | ||
def removeChildShard(parentShardId: Int, childShardId: Int) | ||
def replaceChildShard(oldChildShardId: Int, newChildShardId: Int) | ||
def markShardBusy(shardId: Int, busy: Busy.Value) | ||
def setForwarding(forwarding: Forwarding) | ||
def replaceForwarding(oldShardId: Int, newShardId: Int) | ||
def getForwarding(tableId: List[Int], baseId: Long): ShardInfo | ||
def getForwardingForShard(shardId: Int): Forwarding | ||
def getForwardings(): List[Forwarding] | ||
def shardIdsForHostname(hostname: String, className: String): List[Int] | ||
def listShards(): Seq[ShardInfo] | ||
def listShardChildren(): Map[Int, Seq[ChildInfo]] | ||
def shardsForHostname(hostname: String, className: String): List[ShardInfo] | ||
def getBusyShards(): Seq[ShardInfo] | ||
def getParentShard(shardId: Int): ShardInfo | ||
def getRootShard(shardId: Int): ShardInfo | ||
def getChildShardsOfClass(parentShardId: Int, className: String): List[ShardInfo] | ||
def rebuildSchema() | ||
def listShardChildren(parentId: Int): Seq[ChildInfo] | ||
} | ||
|
||
// def reloadForwardings() | ||
// def reload() |
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.