This repository has been archived by the owner on Sep 18, 2021. It is now read-only.
forked from nkallen/Rowz
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nick Kallen
authored and
Nick Kallen
committed
Mar 30, 2010
1 parent
44bdfb1
commit fb6af56
Showing
20 changed files
with
236 additions
and
64 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
Binary file not shown.
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,10 +1,9 @@ | ||
package com.twitter.rowz | ||
|
||
import com.twitter.gizzard.nameserver | ||
import com.twitter.querulous.evaluator.QueryEvaluator | ||
import com.twitter.gizzard.nameserver.{Forwarding, NameServer} | ||
import com.twitter.gizzard.shards.ShardException | ||
|
||
|
||
class ForwardingManager(mappingFunction: Long => Long, protected val queryEvaluator: QueryEvaluator) | ||
extends nameserver.ForwardingManager[Shard] { | ||
|
||
} | ||
class ForwardingManager(nameServer: NameServer[Shard]) extends (Long => Shard) { | ||
def apply(id: Long) = nameServer.findCurrentForwarding(0, id) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.twitter.rowz | ||
|
||
|
||
object Priority extends Enumeration { | ||
val High, Low = Value | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/scala/com/twitter/rowz/ReadWriteShardAdapter.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,14 @@ | ||
package com.twitter.rowz | ||
|
||
import com.twitter.gizzard.shards | ||
import com.twitter.gizzard.shards.ReadWriteShard | ||
import com.twitter.xrayspecs.Time | ||
|
||
|
||
class ReadWriteShardAdapter(shard: ReadWriteShard[Shard]) | ||
extends shards.ReadWriteShardAdapter(shard) with Shard { | ||
|
||
def create(info: RowInfo, at: Time) = shard.writeOperation(_.create(info, at)) | ||
def destroy(id: Long, at: Time) = shard.writeOperation(_.destroy(id, at)) | ||
def read(id: Long) = shard.readOperation(_.read(id)) | ||
} |
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,4 @@ | ||
package com.twitter.rowz | ||
|
||
|
||
case class Row(id: Long, info: RowInfo) |
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,4 @@ | ||
package com.twitter.rowz | ||
|
||
|
||
case class RowInfo(name: String, state: State.Value) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
package com.twitter.rowz | ||
|
||
import com.twitter.gizzard.shards | ||
import com.twitter.xrayspecs.Time | ||
|
||
trait Shard { | ||
|
||
|
||
trait Shard extends shards.Shard { | ||
def create(info: RowInfo, at: Time) | ||
def destroy(id: Long, at: Time) | ||
def read(id: Long): RowInfo | ||
} |
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,52 @@ | ||
package com.twitter.rowz | ||
|
||
import com.twitter.querulous.evaluator.{QueryEvaluatorFactory, QueryEvaluator} | ||
import net.lag.configgy.ConfigMap | ||
import com.twitter.gizzard.shards | ||
import com.twitter.querulous.query.SqlQueryTimeoutException | ||
import java.sql.SQLException | ||
import com.twitter.gizzard.proxy.SqlExceptionWrappingProxy | ||
|
||
|
||
class SqlShardFactory(queryEvaluatorFactory: QueryEvaluatorFactory, config: ConfigMap) | ||
extends shards.ShardFactory[Shard] { | ||
|
||
val TABLE_DDL = """ | ||
CREATE TABLE IF NOT EXISTS %s ( | ||
source_id %s NOT NULL, | ||
position BIGINT NOT NULL, | ||
updated_at INT UNSIGNED NOT NULL, | ||
destination_id %s NOT NULL, | ||
count TINYINT UNSIGNED NOT NULL, | ||
state TINYINT NOT NULL, | ||
PRIMARY KEY (source_id, state, position), | ||
UNIQUE unique_source_id_destination_id (source_id, destination_id) | ||
) TYPE=INNODB""" | ||
|
||
def instantiate(shardInfo: shards.ShardInfo, weight: Int, children: Seq[Shard]) = { | ||
val queryEvaluator = queryEvaluatorFactory(List(shardInfo.hostname), config("rowz.db.name"), config("rowz.db.username"), config("rowz.db.password")) | ||
SqlExceptionWrappingProxy[Shard](new SqlShard(queryEvaluator, shardInfo, weight, children, config)) | ||
} | ||
|
||
def materialize(shardInfo: shards.ShardInfo) = { | ||
try { | ||
val queryEvaluator = queryEvaluatorFactory( | ||
List(shardInfo.hostname), | ||
config("rowz.db.name"), | ||
config("rowz.db.username"), | ||
config("rowz.db.password")) | ||
queryEvaluatorFactory(shardInfo.hostname, null, config("rowz.db.username"), config("rowz.db.password")).execute("CREATE DATABASE IF NOT EXISTS " + config("rowz.db.name")) | ||
queryEvaluator.execute(TABLE_DDL.format(shardInfo.tablePrefix + "_rowz", shardInfo.sourceType, shardInfo.destinationType)) | ||
} catch { | ||
case e: SQLException => throw new shards.ShardException(e.toString) | ||
case e: SqlQueryTimeoutException => throw new shards.ShardTimeoutException | ||
} | ||
} | ||
} | ||
|
||
|
||
class SqlShard(private val queryEvaluator: QueryEvaluator, val shardInfo: shards.ShardInfo, | ||
val weight: Int, val children: Seq[Shard], config: ConfigMap) extends Shard { | ||
} |
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,6 @@ | ||
package com.twitter.rowz | ||
|
||
|
||
object State extends Enumeration { | ||
val Normal, Removed = Value | ||
} |
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,6 +1,9 @@ | ||
package com.twitter.rowz.jobs | ||
|
||
import com.twitter.gizzard.jobs.UnboundJob | ||
import com.twitter.xrayspecs.Time | ||
|
||
class Create { | ||
|
||
class Create(id: Long, info: RowInfo, at: Time) extends UnboundJob[ForwardingManager] { | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
package com.twitter.rowz.jobs | ||
|
||
import com.twitter.xrayspecs.Time | ||
import com.twitter.gizzard.jobs.UnboundJob | ||
|
||
|
||
class Destroy(id: Long, at: Time) extends UnboundJob[ForwardingManager] { | ||
|
||
} |
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,22 +1,27 @@ | ||
package com.twitter.rowz | ||
|
||
import net.lag.configgy.Config | ||
import com.twitter.gizzard.nameserver.NameServer | ||
import com.twitter.gizzard.scheduler.JobScheduler | ||
import com.twitter.gizzard.scheduler.PrioritizingJobScheduler | ||
import jobs.{Create, Destroy} | ||
import com.twitter.xrayspecs.Time | ||
import com.twitter.xrayspecs.TimeConversions._ | ||
import thrift.conversions.Row._ | ||
import thrift.conversions.RowInfo._ | ||
|
||
|
||
class RowzService(nameServer: NameServer[Shard], forwardingManager: ForwardingManager, scheduler: JobScheduler) { | ||
class RowzService(forwardingManager: ForwardingManager, scheduler: PrioritizingJobScheduler) extends thrift.Rowz.Iface { | ||
def create(rowInfo: RowInfo, at: Int) = { | ||
val id = makeId() | ||
scheduler(new Create(id, rowInfo.fromThrift, at)) | ||
/* val id = makeId()*/ | ||
val id = 1 | ||
scheduler(0)(new Create(id, rowInfo, Time(at.seconds))) // XXX priority const | ||
id | ||
} | ||
|
||
def delete(rowInfo: RowInfo, at: Int) { | ||
scheduler(new Delete(id, rowInfo.fromThrift, at)) | ||
def destroy(id: Long, at: Int) { | ||
scheduler(1)(new Destroy(id, Time(at.seconds))) // XXX | ||
} | ||
|
||
def get(id: Long) = { | ||
nameServer.find(id).get(id) | ||
def read(id: Long) = { | ||
forwardingManager(id).read(id).toThrift | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/scala/com/twitter/rowz/thrift/conversions/Row.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,16 @@ | ||
package com.twitter.rowz.thrift.conversions | ||
|
||
import RowInfo._ | ||
|
||
|
||
object Row { | ||
class RichShardingRow(row: rowz.Row) { | ||
def toThrift = new thrift.Row(row.id, row.info.toThrift) | ||
} | ||
implicit def shardingRowToRichShardingRow(row: rowz.Row) = new RichShardingRow(row) | ||
|
||
class RichThriftRow(row: thrift.Row) { | ||
def fromThrift = new rowz.Row(row.id, row.info.fromThrift) | ||
} | ||
implicit def thriftRowToRichThriftRow(row: thrift.Row) = new RichThriftRow(row) | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/scala/com/twitter/rowz/thrift/conversions/RowInfo.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,16 @@ | ||
package com.twitter.rowz.thrift.conversions | ||
|
||
import State._ | ||
|
||
|
||
object RowInfo { | ||
class RichShardingRowInfo(rowInfo: rowz.RowInfo) { | ||
def toThrift = new thrift.RowInfo(rowInfo.name, rowInfo.state.toThrift) | ||
} | ||
implicit def shardingRowInfoToRichShardingRowInfo(rowInfo: rowz.RowInfo) = new RichShardingRowInfo(rowInfo) | ||
|
||
class RichThriftRowInfo(rowInfo: thrift.RowInfo) { | ||
def fromThrift = new rowz.RowInfo(rowInfo.name, rowInfo.state_id.fromThrift) | ||
} | ||
implicit def thriftRowInfoToRichThriftRowInfo(rowInfo: thrift.RowInfo) = new RichThriftRowInfo(rowInfo) | ||
} |
Oops, something went wrong.