From 169a4aaa32c149c8112eb61857fad864b99b13d9 Mon Sep 17 00:00:00 2001 From: MansurAshraf Date: Sun, 12 Jan 2014 19:33:07 -0600 Subject: [PATCH 1/3] clean up htable after finishing get and put. Fixes #206 --- .../main/scala/com/twitter/storehaus/hbase/HBaseStore.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/storehaus-hbase/src/main/scala/com/twitter/storehaus/hbase/HBaseStore.scala b/storehaus-hbase/src/main/scala/com/twitter/storehaus/hbase/HBaseStore.scala index b583c755..8b43336d 100644 --- a/storehaus-hbase/src/main/scala/com/twitter/storehaus/hbase/HBaseStore.scala +++ b/storehaus-hbase/src/main/scala/com/twitter/storehaus/hbase/HBaseStore.scala @@ -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. @@ -74,6 +74,7 @@ trait HBaseStore { val result = tbl.get(g) val value = result.getValue(columnFamily.as[StringBytes], column.as[StringBytes]) + tbl.close() Option(value).map(v => valueInj.invert(v).get) } @@ -84,11 +85,13 @@ trait HBaseStore { p.add(columnFamily.as[StringBytes], column.as[StringBytes], valueInj(v)) val tbl = pool.getTable(table) tbl.put(p) + tbl.close() } case (k, None) => futurePool { val delete = new Delete(keyInj(k)) val tbl = pool.getTable(table) tbl.delete(delete) + tbl.close() } } } From 444a3c314d749cfbfdfb4f64ae3ccd26cf3a5978 Mon Sep 17 00:00:00 2001 From: MansurAshraf Date: Mon, 13 Jan 2014 09:15:03 -0600 Subject: [PATCH 2/3] wrapped table close in ensure block --- .../twitter/storehaus/hbase/HBaseStore.scala | 25 ++++++++++--------- .../hbase/HBaseStringStoreProperties.scala | 4 +-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/storehaus-hbase/src/main/scala/com/twitter/storehaus/hbase/HBaseStore.scala b/storehaus-hbase/src/main/scala/com/twitter/storehaus/hbase/HBaseStore.scala index 8b43336d..7a60ebb9 100644 --- a/storehaus-hbase/src/main/scala/com/twitter/storehaus/hbase/HBaseStore.scala +++ b/storehaus-hbase/src/main/scala/com/twitter/storehaus/hbase/HBaseStore.scala @@ -67,32 +67,33 @@ 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]) - tbl.close() - 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) - tbl.close() - } + } ensure tbl.close + case (k, None) => futurePool { val delete = new Delete(keyInj(k)) - val tbl = pool.getTable(table) tbl.delete(delete) tbl.close() - } + } ensure tbl.close } } } diff --git a/storehaus-hbase/src/test/scala/com/twitter/storehaus/hbase/HBaseStringStoreProperties.scala b/storehaus-hbase/src/test/scala/com/twitter/storehaus/hbase/HBaseStringStoreProperties.scala index 6506bd95..aa0a7ad9 100644 --- a/storehaus-hbase/src/test/scala/com/twitter/storehaus/hbase/HBaseStringStoreProperties.scala +++ b/storehaus-hbase/src/test/scala/com/twitter/storehaus/hbase/HBaseStringStoreProperties.scala @@ -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. @@ -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") From 9440eecb3963e053aecdb7963f22e4fb3047fe61 Mon Sep 17 00:00:00 2001 From: MansurAshraf Date: Mon, 13 Jan 2014 09:17:26 -0600 Subject: [PATCH 3/3] wrapped table close in ensure block --- .../src/main/scala/com/twitter/storehaus/hbase/HBaseStore.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/storehaus-hbase/src/main/scala/com/twitter/storehaus/hbase/HBaseStore.scala b/storehaus-hbase/src/main/scala/com/twitter/storehaus/hbase/HBaseStore.scala index 7a60ebb9..55060fd2 100644 --- a/storehaus-hbase/src/main/scala/com/twitter/storehaus/hbase/HBaseStore.scala +++ b/storehaus-hbase/src/main/scala/com/twitter/storehaus/hbase/HBaseStore.scala @@ -92,7 +92,6 @@ trait HBaseStore { case (k, None) => futurePool { val delete = new Delete(keyInj(k)) tbl.delete(delete) - tbl.close() } ensure tbl.close } }