Adding code to let the index importer and hdfs kv store remove their timertasks.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/2f3b9869
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/2f3b9869
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/2f3b9869

Branch: refs/heads/master
Commit: 2f3b986992aa0e3b9ff99aa9c61cade39a5a9679
Parents: a7d1639
Author: Aaron McCurry <[email protected]>
Authored: Tue Nov 11 07:51:44 2014 -0500
Committer: Aaron McCurry <[email protected]>
Committed: Tue Nov 11 07:51:44 2014 -0500

----------------------------------------------------------------------
 .../apache/blur/manager/writer/IndexImporter.java    |  2 +-
 .../apache/blur/store/hdfs_v2/HdfsKeyValueStore.java | 15 +++++++++------
 2 files changed, 10 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2f3b9869/blur-core/src/main/java/org/apache/blur/manager/writer/IndexImporter.java
----------------------------------------------------------------------
diff --git 
a/blur-core/src/main/java/org/apache/blur/manager/writer/IndexImporter.java 
b/blur-core/src/main/java/org/apache/blur/manager/writer/IndexImporter.java
index d441e53..c2a7398 100644
--- a/blur-core/src/main/java/org/apache/blur/manager/writer/IndexImporter.java
+++ b/blur-core/src/main/java/org/apache/blur/manager/writer/IndexImporter.java
@@ -90,7 +90,7 @@ public class IndexImporter extends TimerTask implements 
Closeable {
 
   @Override
   public void close() throws IOException {
-
+    cancel();
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2f3b9869/blur-store/src/main/java/org/apache/blur/store/hdfs_v2/HdfsKeyValueStore.java
----------------------------------------------------------------------
diff --git 
a/blur-store/src/main/java/org/apache/blur/store/hdfs_v2/HdfsKeyValueStore.java 
b/blur-store/src/main/java/org/apache/blur/store/hdfs_v2/HdfsKeyValueStore.java
index 1904dd3..fe917f2 100644
--- 
a/blur-store/src/main/java/org/apache/blur/store/hdfs_v2/HdfsKeyValueStore.java
+++ 
b/blur-store/src/main/java/org/apache/blur/store/hdfs_v2/HdfsKeyValueStore.java
@@ -162,6 +162,7 @@ public class HdfsKeyValueStore implements Store {
   private Path _outputPath;
   private final long _maxAmountAllowedPerFile;
   private boolean _isClosed;
+  private final TimerTask _timerTask;
 
   public HdfsKeyValueStore(Timer hdfsKeyValueTimer, Configuration 
configuration, Path path) throws IOException {
     this(hdfsKeyValueTimer, configuration, path, DEFAULT_MAX);
@@ -182,7 +183,7 @@ public class HdfsKeyValueStore implements Store {
     }
     removeAnyTruncatedFiles();
     loadIndexes();
-    addToTimer(hdfsKeyValueTimer);
+    _timerTask = addToTimer(hdfsKeyValueTimer);
     Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, HDFS_KV, SIZE, 
path.getParent().toString()), new Gauge<Long>() {
       @Override
       public Long value() {
@@ -206,7 +207,7 @@ public class HdfsKeyValueStore implements Store {
     }
   }
 
-  private void addToTimer(Timer hdfsKeyValueTimer) {
+  private TimerTask addToTimer(Timer hdfsKeyValueTimer) {
     _writeLock.lock();
     try {
       try {
@@ -217,7 +218,7 @@ public class HdfsKeyValueStore implements Store {
     } finally {
       _writeLock.unlock();
     }
-    hdfsKeyValueTimer.schedule(new TimerTask() {
+    TimerTask timerTask = new TimerTask() {
       @Override
       public void run() {
         _writeLock.lock();
@@ -242,8 +243,9 @@ public class HdfsKeyValueStore implements Store {
           _writeLock.unlock();
         }
       }
-    }, DAEMON_POLL_TIME, DAEMON_POLL_TIME);
-
+    };
+    hdfsKeyValueTimer.schedule(timerTask, DAEMON_POLL_TIME, DAEMON_POLL_TIME);
+    return timerTask;
   }
 
   @Override
@@ -446,7 +448,8 @@ public class HdfsKeyValueStore implements Store {
 
   @Override
   public void close() throws IOException {
-    if (_isClosed) {
+    if (!_isClosed) {
+      _timerTask.cancel();
       _writeLock.lock();
       try {
         syncInternal();

Reply via email to