You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2020/03/24 11:09:47 UTC

[GitHub] [ignite] ymolochkov opened a new pull request #7563: IGNITE-12749

ymolochkov opened a new pull request #7563: IGNITE-12749
URL: https://github.com/apache/ignite/pull/7563
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [ignite] nizhikov commented on a change in pull request #7563: IGNITE-12749 Fixed unsupported operation exception on node stop if collisionspi not null

Posted by GitBox <gi...@apache.org>.
nizhikov commented on a change in pull request #7563: IGNITE-12749 Fixed unsupported operation exception on node stop if collisionspi not null
URL: https://github.com/apache/ignite/pull/7563#discussion_r397751526
 
 

 ##########
 File path: modules/core/src/main/java/org/jsr166/ConcurrentLinkedHashMap.java
 ##########
 @@ -1536,10 +1536,49 @@ public V replacex(K key, V oldVal, V newVal) {
     }
 
     /**
-     * Removes all of the mappings from this map.
+     * Removes all of the mappings from this map. Performs global locking of the table.
      */
     @Override public void clear() {
-        throw new UnsupportedOperationException();
+
+        try {
+            lockWriteLocks();
+            replaceOldSegments();
+
+        } finally {
+            unlockWriteLocks();
+        }
+    }
+
+    /**
+     * Replaces all segments with the new ones and increments modification count for the table.
+     */
+    private void replaceOldSegments() {
+        for (int i = 0; i < segments.length; i++) {
+            segments[i] = new Segment<>(DFLT_INIT_CAP, DFLT_LOAD_FACTOR);
+        }
+
+        modCnt.increment();
+    }
+
+    /**
+     * Tries to lock all segments in order which they appear to be in an underlying array.
+     */
+    @SuppressWarnings("LockAcquiredButNotSafelyReleased")
+    private void lockWriteLocks() {
+        for (Segment<K, V> segment : segments) {
+            segment.writeLock().lock();
 
 Review comment:
   What is thread will be interrupted in the middle of this loop?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [ignite] nizhikov commented on a change in pull request #7563: IGNITE-12749 Fixed unsupported operation exception on node stop if collisionspi not null

Posted by GitBox <gi...@apache.org>.
nizhikov commented on a change in pull request #7563: IGNITE-12749 Fixed unsupported operation exception on node stop if collisionspi not null
URL: https://github.com/apache/ignite/pull/7563#discussion_r397751526
 
 

 ##########
 File path: modules/core/src/main/java/org/jsr166/ConcurrentLinkedHashMap.java
 ##########
 @@ -1536,10 +1536,49 @@ public V replacex(K key, V oldVal, V newVal) {
     }
 
     /**
-     * Removes all of the mappings from this map.
+     * Removes all of the mappings from this map. Performs global locking of the table.
      */
     @Override public void clear() {
-        throw new UnsupportedOperationException();
+
+        try {
+            lockWriteLocks();
+            replaceOldSegments();
+
+        } finally {
+            unlockWriteLocks();
+        }
+    }
+
+    /**
+     * Replaces all segments with the new ones and increments modification count for the table.
+     */
+    private void replaceOldSegments() {
+        for (int i = 0; i < segments.length; i++) {
+            segments[i] = new Segment<>(DFLT_INIT_CAP, DFLT_LOAD_FACTOR);
+        }
+
+        modCnt.increment();
+    }
+
+    /**
+     * Tries to lock all segments in order which they appear to be in an underlying array.
+     */
+    @SuppressWarnings("LockAcquiredButNotSafelyReleased")
+    private void lockWriteLocks() {
+        for (Segment<K, V> segment : segments) {
+            segment.writeLock().lock();
 
 Review comment:
   What if thread will be interrupted in the middle of this loop?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [ignite] nizhikov commented on a change in pull request #7563: IGNITE-12749 Fixed unsupported operation exception on node stop if collisionspi not null

Posted by GitBox <gi...@apache.org>.
nizhikov commented on a change in pull request #7563: IGNITE-12749 Fixed unsupported operation exception on node stop if collisionspi not null
URL: https://github.com/apache/ignite/pull/7563#discussion_r397752753
 
 

 ##########
 File path: modules/core/src/main/java/org/jsr166/ConcurrentLinkedHashMap.java
 ##########
 @@ -1536,10 +1536,49 @@ public V replacex(K key, V oldVal, V newVal) {
     }
 
     /**
-     * Removes all of the mappings from this map.
+     * Removes all of the mappings from this map. Performs global locking of the table.
      */
     @Override public void clear() {
-        throw new UnsupportedOperationException();
+
+        try {
+            lockWriteLocks();
+            replaceOldSegments();
+
+        } finally {
+            unlockWriteLocks();
 
 Review comment:
   If the exception will be thrown on lock acquire we will try to unlock locks that never acquired.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services