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

clean up htable after finishing get and put operations. #207

Merged
merged 3 commits into from
Jan 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013 Twitter inc.
* Copyright 2014 Twitter inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -67,29 +67,32 @@ trait HBaseStore {
require(isNotEmpty(column), "column is required")
}

def getValue[K, V](key: K)(implicit keyInj: Injection[K, Array[Byte]], valueInj: Injection[V, Array[Byte]]): Future[Option[V]] = futurePool {
def getValue[K, V](key: K)(implicit keyInj: Injection[K, Array[Byte]], valueInj: Injection[V, Array[Byte]]): Future[Option[V]] = {
val tbl = pool.getTable(table)
val g = new Get(keyInj(key))
g.addColumn(columnFamily.as[StringBytes], column.as[StringBytes])
futurePool {
val g = new Get(keyInj(key))
g.addColumn(columnFamily.as[StringBytes], column.as[StringBytes])

val result = tbl.get(g)
val value = result.getValue(columnFamily.as[StringBytes], column.as[StringBytes])
Option(value).map(v => valueInj.invert(v).get)
val result = tbl.get(g)
val value = result.getValue(columnFamily.as[StringBytes], column.as[StringBytes])

Option(value).map(v => valueInj.invert(v).get)
} ensure tbl.close
}

def putValue[K, V](kv: (K, Option[V]))(implicit keyInj: Injection[K, Array[Byte]], valueInj: Injection[V, Array[Byte]]): Future[Unit] = {
val tbl = pool.getTable(table)
kv match {
case (k, Some(v)) => futurePool {
val p = new Put(keyInj(k))
p.add(columnFamily.as[StringBytes], column.as[StringBytes], valueInj(v))
val tbl = pool.getTable(table)
tbl.put(p)
}
} ensure tbl.close

case (k, None) => futurePool {
val delete = new Delete(keyInj(k))
val tbl = pool.getTable(table)
tbl.delete(delete)
}
} ensure tbl.close
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013 Twitter inc.
* Copyright 2014 Twitter inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,7 @@ import org.scalacheck.Prop._
import com.twitter.util.Await

/**
* @author MansurAshraf
* @author Mansur Ashraf
* @since 9/8/13
*/
object HBaseStringStoreProperties extends Properties("HBaseStore")
Expand Down