Repository: ignite
Updated Branches:
  refs/heads/ignite-5901 fa2b743b2 -> a117e0893


IGNITE-5901 - Debug


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a117e089
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a117e089
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a117e089

Branch: refs/heads/ignite-5901
Commit: a117e089372323266d8b0599b36267c5a7199f79
Parents: fa2b743
Author: Alexey Goncharuk <alexey.goncha...@gmail.com>
Authored: Thu Aug 10 20:30:37 2017 +0300
Committer: Alexey Goncharuk <alexey.goncha...@gmail.com>
Committed: Thu Aug 10 20:30:37 2017 +0300

----------------------------------------------------------------------
 .../wal/FileWriteAheadLogManager.java           | 72 +++++++++++---------
 1 file changed, 41 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a117e089/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileWriteAheadLogManager.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileWriteAheadLogManager.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileWriteAheadLogManager.java
index da295aa..ebc05a4 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileWriteAheadLogManager.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileWriteAheadLogManager.java
@@ -2028,6 +2028,9 @@ public class FileWriteAheadLogManager extends 
GridCacheSharedManagerAdapter impl
 
                 flushOrWait(ptr, stop);
 
+                if (stopped())
+                    return;
+
                 if (lastFsyncPos != written) {
                     assert lastFsyncPos < written; // Fsync position must be 
behind.
 
@@ -2069,55 +2072,62 @@ public class FileWriteAheadLogManager extends 
GridCacheSharedManagerAdapter impl
          */
         private boolean close(boolean rollOver) throws IgniteCheckedException, 
StorageException {
             if (stop.compareAndSet(false, true)) {
-                flushOrWait(null, true);
+                lock.lock();
+
+                try {
+                    flushOrWait(null, true);
 
-                WALRecord hd = head.get();
+                    WALRecord hd = head.get();
 
-                assert stopped() : "Segment is not closed after close flush: " 
+ hd;
+                    assert stopped() : "Segment is not closed after close 
flush: " + hd;
 
-                try {
-                    int switchSegmentRecSize = 
RecordV1Serializer.REC_TYPE_SIZE + RecordV1Serializer.FILE_WAL_POINTER_SIZE;
+                    try {
+                        int switchSegmentRecSize = 
RecordV1Serializer.REC_TYPE_SIZE + RecordV1Serializer.FILE_WAL_POINTER_SIZE;
 
-                    if (rollOver && written < (maxSegmentSize - 
switchSegmentRecSize)) {
-                        //it is expected there is sufficient space for this 
record because rollover should run early
-                        final ByteBuffer buf = 
ByteBuffer.allocate(switchSegmentRecSize);
-                        
buf.put((byte)(WALRecord.RecordType.SWITCH_SEGMENT_RECORD.ordinal() + 1));
+                        if (rollOver && written < (maxSegmentSize - 
switchSegmentRecSize)) {
+                            //it is expected there is sufficient space for 
this record because rollover should run early
+                            final ByteBuffer buf = 
ByteBuffer.allocate(switchSegmentRecSize);
+                            
buf.put((byte)(WALRecord.RecordType.SWITCH_SEGMENT_RECORD.ordinal() + 1));
 
-                        final FileWALPointer pointer = new FileWALPointer(idx, 
(int)fileIO.position(), -1);
-                        RecordV1Serializer.putPosition(buf, pointer);
+                            final FileWALPointer pointer = new 
FileWALPointer(idx, (int)fileIO.position(), -1);
+                            RecordV1Serializer.putPosition(buf, pointer);
 
-                        buf.rewind();
+                            buf.rewind();
 
-                        int rem = buf.remaining();
+                            int rem = buf.remaining();
 
-                        while (rem > 0) {
-                            int written0 = fileIO.write(buf, written);
+                            while (rem > 0) {
+                                int written0 = fileIO.write(buf, written);
 
-                            written += written0;
+                                written += written0;
 
-                            rem -= written0;
+                                rem -= written0;
+                            }
                         }
-                    }
 
-                    // Do the final fsync.
-                    if (mode == WALMode.DEFAULT) {
-                        fileIO.force();
+                        // Do the final fsync.
+                        if (mode == WALMode.DEFAULT) {
+                            fileIO.force();
+
+                            lastFsyncPos = written;
+                        }
+
+                        closeStack = new Exception("written=" + written + ", 
head=" + hd);
 
-                        lastFsyncPos = written;
+                        fileIO.close();
+                    }
+                    catch (IOException e) {
+                        throw new IgniteCheckedException(e);
                     }
 
-                    closeStack = new Exception("written=" + written + ", 
head=" + hd);
+                    if (log.isDebugEnabled())
+                        log.debug("Closed WAL write handle [idx=" + idx + "]");
 
-                    fileIO.close();
+                    return true;
                 }
-                catch (IOException e) {
-                    throw new IgniteCheckedException(e);
+                finally {
+                    lock.unlock();
                 }
-
-                if (log.isDebugEnabled())
-                    log.debug("Closed WAL write handle [idx=" + idx + "]");
-
-                return true;
             }
             else
                 return false;

Reply via email to