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 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull CopyManager / Migration stuff out of NameServer
- Loading branch information
Ed Ceaser
committed
Mar 16, 2010
1 parent
2f2efec
commit e767fc0
Showing
8 changed files
with
100 additions
and
169 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
35 changes: 35 additions & 0 deletions
35
src/main/scala/com/twitter/gizzard/nameserver/ShardMigration.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 |
---|---|---|
@@ -1,5 +1,40 @@ | ||
package com.twitter.gizzard.nameserver | ||
|
||
import shards._ | ||
|
||
|
||
object ShardMigration { | ||
def setupMigration[S <: Shard](sourceShardInfo: ShardInfo, destinationShardInfo: ShardInfo, nameServer: NameServer[S]): ShardMigration = { | ||
val lastDot = sourceShardInfo.className.lastIndexOf('.') | ||
val packageName = if (lastDot >= 0) sourceShardInfo.className.substring(0, lastDot + 1) else "" | ||
val sourceShardId = nameServer.findShard(sourceShardInfo) | ||
val destinationShardId = nameServer.createShard(destinationShardInfo) | ||
|
||
val writeOnlyShard = new ShardInfo(packageName + "WriteOnlyShard", | ||
sourceShardInfo.tablePrefix + "_migrate_write_only", "localhost", "", "", Busy.Normal, 0) | ||
val writeOnlyShardId = nameServer.createShard(writeOnlyShard) | ||
nameServer.addChildShard(writeOnlyShardId, destinationShardId, 1) | ||
|
||
val replicatingShard = new ShardInfo(packageName + "ReplicatingShard", | ||
sourceShardInfo.tablePrefix + "_migrate_replicating", "localhost", "", "", Busy.Normal, 0) | ||
val replicatingShardId = nameServer.createShard(replicatingShard) | ||
nameServer.replaceChildShard(sourceShardId, replicatingShardId) | ||
nameServer.addChildShard(replicatingShardId, sourceShardId, 1) | ||
nameServer.addChildShard(replicatingShardId, writeOnlyShardId, 1) | ||
|
||
nameServer.replaceForwarding(sourceShardId, replicatingShardId) | ||
new ShardMigration(sourceShardId, destinationShardId, replicatingShardId, writeOnlyShardId) | ||
} | ||
|
||
def finishMigration[S <: Shard](migration: ShardMigration, nameServer: NameServer[S]) { | ||
nameServer.removeChildShard(migration.writeOnlyShardId, migration.destinationShardId) | ||
nameServer.replaceChildShard(migration.replicatingShardId, migration.destinationShardId) | ||
nameServer.replaceForwarding(migration.replicatingShardId, migration.destinationShardId) | ||
nameServer.deleteShard(migration.replicatingShardId) | ||
nameServer.deleteShard(migration.writeOnlyShardId) | ||
nameServer.deleteShard(migration.sourceShardId) | ||
} | ||
} | ||
|
||
case class ShardMigration(sourceShardId: Int, destinationShardId: Int, replicatingShardId: Int, | ||
writeOnlyShardId: Int) |
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