You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hx...@apache.org on 2019/06/07 17:40:17 UTC

[incubator-iotdb] branch feature_async_close_tsfile updated: fix bug for concurrent close and flush so that writer = null

This is an automated email from the ASF dual-hosted git repository.

hxd pushed a commit to branch feature_async_close_tsfile
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/feature_async_close_tsfile by this push:
     new 36a44f9  fix bug for concurrent close and flush so that writer = null
36a44f9 is described below

commit 36a44f9451a3c59e6ca1fa9552e7b1cc820de85d
Author: xiangdong huang <sa...@gmail.com>
AuthorDate: Sat Jun 8 01:40:01 2019 +0800

    fix bug for concurrent close and flush so that writer = null
---
 .../iotdb/db/engine/bufferwrite/BufferWriteProcessor.java      | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/iotdb/src/main/java/org/apache/iotdb/db/engine/bufferwrite/BufferWriteProcessor.java b/iotdb/src/main/java/org/apache/iotdb/db/engine/bufferwrite/BufferWriteProcessor.java
index 674810a..129f417 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/engine/bufferwrite/BufferWriteProcessor.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/engine/bufferwrite/BufferWriteProcessor.java
@@ -374,7 +374,7 @@ public class BufferWriteProcessor extends Processor {
 
   // keyword synchronized is added in this method, so that only one flush task can be submitted now.
   private Future<Boolean> flush(boolean isCloseTaskCalled) throws IOException {
-    if (isClosed) {
+    if (!isCloseTaskCalled && isClosed) {
       throw new IOException("BufferWriteProcessor closed");
     }
     // statistic information for flush
@@ -452,12 +452,12 @@ public class BufferWriteProcessor extends Processor {
   }
 
   @Override
-  public void close() throws BufferWriteProcessorException {
+  public synchronized void close() throws BufferWriteProcessorException {
     if (isClosed) {
       return;
     }
     try {
-
+      isClosed = true;
       // flush data (if there are flushing task, flush() will be blocked)
       //Future<Boolean> flush = flush();
       //and wait for finishing flush async
@@ -479,6 +479,10 @@ public class BufferWriteProcessor extends Processor {
       LOGGER.info("Bufferwrite {} Close Task: finishing the flush.", getProcessorName());
       // end file
       writer.endFile(fileSchema);
+      //FIXME suppose the flush-thread-pool is 2.
+      // then if a flush task and a close task are running in the same time
+      // and the close task is faster, then writer == null, and the flush task will throw nullpointer
+      // expcetion. Add "synchronized" keyword on both flush and close may solve the issue.
       writer = null;
       isClosed = true;
       //A BUG may appears here: workMemTable has been cleared,