Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge from twitter/storehaus #10

Merged
merged 49 commits into from
Sep 13, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
029aa0f
Merge branch 'release/0.2.0'
Mar 20, 2013
3cb6e41
Merge branch 'release/0.3.0'
Apr 23, 2013
42b1144
Merge branch 'release/0.4.0'
May 16, 2013
26e97fe
Merge branch 'release/0.4.0'
May 16, 2013
899ac6d
move to finagle-mysql 6.3.0, disable store.close in tests
rubanm May 17, 2013
5b4200c
reuse prepared statements
rubanm May 17, 2013
17eee81
beef up memcache
Jun 25, 2013
55d251b
Merge branch 'develop' into feature/better_memcached
Jun 25, 2013
08521ee
Merge branch 'develop' into feature/better_memcached
Jun 27, 2013
aa4a8db
Merge branch 'develop' into finagle_mysql_update
rubanm Jun 28, 2013
9900f36
merge with develop. remove .close from mysql tests
rubanm Jun 28, 2013
4129eb5
Bump to util 6.3.7 and finagle 6.5.1
Jul 9, 2013
f8247ce
Merge pull request #114 from rubanm/finagle_mysql_update
sritchie Jul 14, 2013
aaa665c
Merge branch 'develop' of https://github.com/twitter/storehaus into d…
Jul 15, 2013
c366da0
Merge pull request #125 from ximyu/develop
ximyu Jul 15, 2013
ec21014
upgrade algebird
Jul 18, 2013
ccb05cd
upgrade bijection
Jul 18, 2013
11992aa
fix tests
Jul 18, 2013
5baf943
fix redis props
Jul 18, 2013
a70b02c
Merge pull request #126 from twitter/feature/upgrade_alg
johnynek Jul 18, 2013
56622a2
Merge branch 'develop' into feature/better_memcached
Jul 18, 2013
e34879d
remove codec
Jul 19, 2013
cf39c83
Merge pull request #121 from twitter/feature/better_memcached
sritchie Jul 19, 2013
bd5151b
version bumps
Jul 19, 2013
d9a9179
update mima.
Jul 19, 2013
1cd9a03
Merge branch 'release/0.5.0'
Jul 19, 2013
5427c10
Merge branch 'release/0.5.0' into develop
Jul 19, 2013
fe46e9c
bump to snapshot
Jul 19, 2013
8753307
bump finagle
Jul 31, 2013
5b33cc3
bump version
Jul 31, 2013
056d7c8
added
Jul 31, 2013
242f54f
Merge branch 'master' into develop
Jul 31, 2013
c46f1f5
test and fix
Aug 9, 2013
b835bdb
Merge pull request #136 from twitter/feature/fix_mutable_cache
johnynek Aug 9, 2013
d027d2e
Added storehaus-hbase, upgraded bijection to 0.5.3
MansurAshraf Sep 8, 2013
fcdbdd8
added hbase dependencies
MansurAshraf Sep 9, 2013
c602eec
added hbase module
mav911 Sep 9, 2013
6c5d9dc
DRYed out the imp by moving common methods to HBaseStore trait
mav911 Sep 9, 2013
fee8734
changed quorum to Seq
mav911 Sep 9, 2013
55791ed
added support for HBaseMinicluster for testing
mav911 Sep 10, 2013
40a99ba
mocking hbase - second try
mav911 Sep 10, 2013
1677a9a
removed shutdown hook at it is causing zookeeper to hang
mav911 Sep 10, 2013
ecc5f3b
switched to FuturePool for blocking operations
mav911 Sep 11, 2013
2cbef56
removed unused imports
mav911 Sep 11, 2013
2101928
Merge pull request #139 from MansurAshraf/develop
sritchie Sep 11, 2013
3f64225
add changes, bump version
Sep 11, 2013
2791c98
Merge branch 'release/0.5.1' into develop
Sep 11, 2013
b77554a
Update CHANGES.md
sritchie Sep 11, 2013
a89455d
Add hbase to README
sritchie Sep 11, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
language: scala
scala:
- 2.10.0
- 2.9.2
- 2.9.3
before_script:
- mysql -u root -e "create database storehaus_test;"
- mysql -u root -e "create user 'storehaususer'@'localhost' identified by 'test1234';"
- mysql -u root -e "grant all on storehaus_test.* to 'storehaususer'@'localhost';"
services:
- redis-server
- memcache
- memcache
script: umask 0022 && sbt ++$TRAVIS_SCALA_VERSION test
17 changes: 17 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# storehaus #

### Version.0.5.1 ###

* Add storehaus-hbase and upgrade to bijection 0.5.3: https://github.com/twitter/storehaus/pull/139
* Fix mutable TTL cache bug: https://github.com/twitter/storehaus/pull/136

### Version.0.5.0 ###

* Reuse prepared statements in mysql: https://github.com/twitter/storehaus/issues/93
* storehaus-testing module: https://github.com/twitter/storehaus/pull/115
* cache ttl is now a duration, vs a time: https://github.com/twitter/storehaus/pull/100
* improve performance of CollectionOps: https://github.com/twitter/storehaus/pull/117
* Augment memcachestore with common functions: https://github.com/twitter/storehaus/pull/121
* bump twitter-util and finagle versions: https://github.com/twitter/storehaus/pull/125
* Upgrade to scala 2.9.3, algebird 0.2.0 and Bijection 0.5.2: https://github.com/twitter/storehaus/pull/126

Thanks to Doug Tangren, Ruban Monu, Ximing Yu, Ryan LeCompte, Sam Ritchie and Oscar Boykin for contributions!

### Version.0.4.0 ###

* Storehaus-Mysql support for numeric types
Expand Down
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Storehaus provides a number of modules wrapping existing key-value stores. Enric
* [Storehaus-memcache](http://twitter.github.com/storehaus/#com.twitter.storehaus.memcache.MemcacheStore) (wraps Twitter's [finagle-memcached](https://github.com/twitter/finagle/tree/master/finagle-memcached) library)
* [Storehaus-mysql](http://twitter.github.com/storehaus/#com.twitter.storehaus.mysql.MySQLStore) (wraps Twitter's [finagle-mysql](https://github.com/twitter/finagle/tree/master/finagle-mysql) library)
* [Storehaus-redis](http://twitter.github.com/storehaus/#com.twitter.storehaus.redis.RedisStore) (wraps Twitter's [finagle-redis](https://github.com/twitter/finagle/tree/master/finagle-redis) library)
* [Storehaus-hbase](http://twitter.github.com/storehaus/#com.twitter.storehaus.hbase.HBaseStore)

#### Planned Modules

Expand All @@ -94,22 +95,26 @@ See the [current API documentation](http://twitter.github.com/storehaus) for mor

## Maven

Storehaus modules are available on maven central. The current groupid and version for all modules is, respectively, `"com.twitter"` and `0.4.0`.
Storehaus modules are available on maven central. The current groupid and version for all modules is, respectively, `"com.twitter"` and `0.5.1`.

Current published artifacts are

* `storehaus-core_2.9.2`
* `storehaus-core_2.9.3`
* `storehaus-core_2.10`
* `storehaus-algebra_2.9.2`
* `storehaus-algebra_2.9.3`
* `storehaus-algebra_2.10`
* `storehaus-memcache_2.9.2`
* `storehaus-memcache_2.9.3`
* `storehaus-memcache_2.10`
* `storehaus-mysql_2.9.2`
* `storehaus-mysql_2.9.3`
* `storehaus-mysql_2.10`
* `storehaus-redis_2.9.2`
* `storehaus-hbase_2.9.3`
* `storehaus-hbase_2.10`
* `storehaus-redis_2.9.3`
* `storehaus-redis_2.10`
* `storehaus-cache_2.9.2`
* `storehaus-cache_2.9.3`
* `storehaus-cache_2.10`
* `storehaus-testing_2.9.3`
* `storehaus-testing_2.10`

The suffix denotes the scala version.

Expand Down
89 changes: 60 additions & 29 deletions project/Build.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2013 Twitter inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package storehaus

import sbt._
Expand All @@ -8,6 +24,13 @@ import com.typesafe.tools.mima.plugin.MimaPlugin.mimaDefaultSettings
import com.typesafe.tools.mima.plugin.MimaKeys.previousArtifact

object StorehausBuild extends Build {
def withCross(dep: ModuleID) =
dep cross CrossVersion.binaryMapped {
case "2.9.3" => "2.9.2" // TODO: hack because twitter hasn't built things against 2.9.3
case version if version startsWith "2.10" => "2.10" // TODO: hack because sbt is broken
case x => x
}

val extraSettings =
Project.defaultSettings ++ releaseSettings ++ Boilerplate.settings ++ mimaDefaultSettings

Expand All @@ -19,7 +42,7 @@ object StorehausBuild extends Build {
logLevel in Test := Level.Info
) else Seq.empty[Project.Setting[_]]

val testCleanup = extraSettings ++ Seq(
val testCleanup = Seq(
testOptions in Test += Tests.Cleanup { loader =>
val c = loader.loadClass("com.twitter.storehaus.testing.Cleanup$")
c.getMethod("cleanup").invoke(c.getField("MODULE$").get(c))
Expand All @@ -28,38 +51,27 @@ object StorehausBuild extends Build {

val sharedSettings = extraSettings ++ ciSettings ++ Seq(
organization := "com.twitter",
crossScalaVersions := Seq("2.9.2", "2.10.0"),

scalaVersion := "2.9.3",
crossScalaVersions := Seq("2.9.3", "2.10.0"),
javacOptions ++= Seq("-source", "1.6", "-target", "1.6"),

javacOptions in doc := Seq("-source", "1.6"),

libraryDependencies ++= Seq(
"org.scala-tools.testing" %% "specs" % "1.6.9" % "test" withSources()
),

libraryDependencies += "org.scala-tools.testing" %% "specs" % "1.6.9" % "test" withSources(),
resolvers ++= Seq(
Opts.resolver.sonatypeSnapshots,
Opts.resolver.sonatypeReleases,
"Twitter Maven" at "http://maven.twttr.com"
),

parallelExecution in Test := true,

scalacOptions ++= Seq(Opts.compile.unchecked, Opts.compile.deprecation),

// Publishing options:
publishMavenStyle := true,

publishArtifact in Test := false,

pomIncludeRepository := { x => false },

publishTo <<= version { v =>
Some(if (v.trim.toUpperCase.endsWith("SNAPSHOT")) Opts.resolver.sonatypeSnapshots
else Opts.resolver.sonatypeStaging)
},

pomExtra := (
<url>https://github.com/twitter/storehaus</url>
<licenses>
Expand Down Expand Up @@ -97,10 +109,10 @@ object StorehausBuild extends Build {
def youngestForwardCompatible(subProj: String) =
Some(subProj)
.filterNot(unreleasedModules.contains(_))
.map { s => "com.twitter" % ("storehaus-" + s + "_2.9.2") % "0.3.0" }
.map { s => "com.twitter" % ("storehaus-" + s + "_2.9.3") % "0.5.0" }

val algebirdVersion = "0.1.13"
val bijectionVersion = "0.4.0"
val algebirdVersion = "0.2.0"
val bijectionVersion = "0.5.3"

lazy val storehaus = Project(
id = "storehaus",
Expand All @@ -117,42 +129,63 @@ object StorehausBuild extends Build {
storehausMemcache,
storehausMySQL,
storehausRedis,
storehausHBase,
storehausTesting
)

def module(name: String) = {
val id = "storehaus-%s".format(name)
Project(id = id, base = file(id), settings = sharedSettings ++ Seq(
Project(id = id, base = file(id), settings = sharedSettings ++ testCleanup ++ Seq(
Keys.name := id,
previousArtifact := youngestForwardCompatible(name)) ++ testCleanup
previousArtifact := youngestForwardCompatible(name))
).dependsOn(storehausTesting % "test->test")
}

lazy val storehausCache = module("cache")

lazy val storehausCore = module("core").settings(
libraryDependencies += "com.twitter" %% "util-core" % "6.3.0",
libraryDependencies += "com.twitter" %% "bijection-core" % bijectionVersion
libraryDependencies ++= Seq(
withCross("com.twitter" %% "util-core" % "6.3.7"),
"com.twitter" %% "bijection-core" % bijectionVersion,
"com.twitter" %% "bijection-util" % bijectionVersion
)
).dependsOn(storehausCache % "test->test;compile->compile")

lazy val storehausAlgebra = module("algebra").settings(
libraryDependencies += "com.twitter" %% "algebird-core" % algebirdVersion,
libraryDependencies += "com.twitter" %% "algebird-util" % algebirdVersion,
libraryDependencies += "com.twitter" %% "bijection-algebird" % bijectionVersion
libraryDependencies += "com.twitter" %% "algebird-bijection" % algebirdVersion
).dependsOn(storehausCore % "test->test;compile->compile")

lazy val storehausMemcache = module("memcache").settings(
libraryDependencies += Finagle.module("memcached")
libraryDependencies ++= Seq(
"com.twitter" %% "algebird-core" % algebirdVersion,
"com.twitter" %% "bijection-core" % bijectionVersion,
"com.twitter" %% "bijection-netty" % bijectionVersion,
Finagle.module("memcached")
)
).dependsOn(storehausAlgebra % "test->test;compile->compile")

lazy val storehausMySQL = module("mysql").settings(
libraryDependencies += Finagle.module("mysql", "6.2.1") // tests fail with the latest
libraryDependencies += Finagle.module("mysql")
).dependsOn(storehausCore % "test->test;compile->compile")

lazy val storehausRedis = module("redis").settings(
libraryDependencies += Finagle.module("redis"),
// we don't want various tests clobbering each others keys
parallelExecution in Test := false
parallelExecution in Test := false
).dependsOn(storehausAlgebra % "test->test;compile->compile")

lazy val storehausHBase= module("hbase").settings(
libraryDependencies ++= Seq(
"com.twitter" %% "algebird-core" % algebirdVersion,
"com.twitter" %% "bijection-core" % bijectionVersion,
"com.twitter" %% "bijection-hbase" % bijectionVersion ,
"org.apache.hbase" % "hbase" % "0.94.6" % "provided->default" classifier "tests" classifier "",
"org.apache.hadoop" % "hadoop-core" % "1.2.0" % "provided->default",
"org.apache.hadoop" % "hadoop-test" % "1.2.0" % "test"
),
parallelExecution in Test := false
).dependsOn(storehausAlgebra % "test->test;compile->compile")

val storehausTesting = Project(
Expand All @@ -161,9 +194,7 @@ object StorehausBuild extends Build {
settings = sharedSettings ++ Seq(
name := "storehaus-testing",
previousArtifact := youngestForwardCompatible("testing"),
libraryDependencies ++= Seq(
"org.scalacheck" %% "scalacheck" % "1.10.0" withSources()
)
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.10.0" withSources()
)
)
}
4 changes: 2 additions & 2 deletions project/Finagle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package storehaus
* dependency */
object Finagle {
import sbt._
val LatestVersion = "6.3.0"
val LatestVersion = "6.5.1"
def module(name: String, version: String = LatestVersion) =
"com.twitter" %% "finagle-%s".format(name) % version
StorehausBuild.withCross("com.twitter" %% "finagle-%s".format(name) % version)
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.12.0
sbt.version=0.12.0
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ConvertedMergeableStore[K1, -K2, V1, V2](store: MergeableStore[K1, V1])(kf
(implicit bij: ImplicitBijection[V2, V1])
extends com.twitter.storehaus.ConvertedStore[K1, K2, V1, V2](store)(kfn)(Injection.fromBijection(bij.bijection))
with MergeableStore[K2, V2] {
import com.twitter.bijection.algebird.AlgebirdBijections._
import com.twitter.algebird.bijection.AlgebirdBijections._

override def monoid: Monoid[V2] = store.monoid.as[Monoid[V2]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,24 @@ class AlgebraicMutableCache[K, V](cache: MutableCache[K, V]) {
new MutableCache[K, U] {
override def get(k: K) = for {
v <- cache.get(k)
(_, u) <- injection.invert(k, v)
(_, u) <- injection.invert(k, v).toOption
} yield u

override def +=(ku: (K, U)) = { cache += injection(ku); this }

override def hit(k: K) = cache.hit(k).flatMap { injection.invert(k, _) }.map { _._2 }
override def hit(k: K) =
cache.hit(k)
.flatMap(injection.invert(k, _).toOption).map(_._2)

override def evict(k: K) = for {
evictedV <- cache.evict(k)
(_, evictedU) <- injection.invert(k, evictedV)
(_, evictedU) <- injection.invert(k, evictedV).toOption
} yield evictedU

override def empty = new AlgebraicMutableCache(cache.empty).inject(injection)

override def clear = { cache.clear; this }
override def iterator = cache.iterator.flatMap(injection.invert(_))
override def iterator =
cache.iterator.flatMap(injection.invert(_).toOption)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.twitter.storehaus.algebra

import com.twitter.algebird.Semigroup
import com.twitter.bijection.Injection
import scala.util.{ Success, Failure }

/**
* Injection that maps values paired with stale values of T => None
Expand All @@ -27,17 +28,19 @@ import com.twitter.bijection.Injection
* @author Sam Ritchie
*/

case class ExpiredException[K, V](pair: (K, V)) extends RuntimeException(pair.toString)

class TTLInjection[K, T: Ordering: Semigroup, V](delta: T)(clock: () => T) extends Injection[(K, V), (K, (T, V))] {
def apply(pair: (K, V)): (K, (T, V)) = {
val (k, v) = pair
(k, (Semigroup.plus(clock(), delta), v))
}

override def invert(pair: (K, (T, V))): Option[(K, V)] = {
override def invert(pair: (K, (T, V))) = {
val (k, (expiration, v)) = pair
if (Ordering[T].gteq(expiration, clock()))
Some((k, v))
Success(k -> v)
else
None
Failure(ExpiredException(k -> v))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.twitter.storehaus.algebra

import com.twitter.algebird.{ MapAlgebra, Monoid, SummingQueue }
import com.twitter.bijection.algebird.AlgebirdBijections._
import com.twitter.algebird.bijection.AlgebirdBijections._
import com.twitter.bijection.Injection
import com.twitter.storehaus._
import com.twitter.util.Await
Expand Down Expand Up @@ -93,7 +93,7 @@ object MergeableStoreProperties extends Properties("MergeableStore") {

property("Converted MergeableStore obeys the mergeable store laws") = {
// We are using a weird monoid on Int here:
import com.twitter.bijection.algebird.AlgebirdBijections._
import com.twitter.algebird.bijection.AlgebirdBijections._
import com.twitter.bijection.Conversion.asMethod
implicit val monoid : Monoid[Int] = implicitly[Monoid[(Short,Short)]].as[Monoid[Int]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object MutableLRUCache {
}

class MutableLRUCache[K, V](capacity: Int) extends JMapCache[K, V](() =>
new JLinkedHashMap[K, V](capacity + 1, 0.75f) {
new JLinkedHashMap[K, V](capacity + 1, 0.75f, true) {
override protected def removeEldestEntry(eldest: JMap.Entry[K, V]) =
super.size > capacity
}) {
Expand Down
Loading