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 2021/01/21 12:41:42 UTC

[GitHub] [ignite] tkalkirill opened a new pull request #8681: IGNITE-13877

tkalkirill opened a new pull request #8681:
URL: https://github.com/apache/ignite/pull/8681


   Thank you for submitting the pull request to the Apache Ignite.
   
   In order to streamline the review of the contribution 
   we ask you to ensure the following steps have been taken:
   
   ### The Contribution Checklist
   - [ ] There is a single JIRA ticket related to the pull request. 
   - [ ] The web-link to the pull request is attached to the JIRA ticket.
   - [ ] The JIRA ticket has the _Patch Available_ state.
   - [ ] The pull request body describes changes that have been made. 
   The description explains _WHAT_ and _WHY_ was made instead of _HOW_.
   - [ ] The pull request title is treated as the final commit message. 
   The following pattern must be used: `IGNITE-XXXX Change summary` where `XXXX` - number of JIRA issue.
   - [ ] A reviewer has been mentioned through the JIRA comments 
   (see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers)) 
   - [ ] The pull request has been checked by the Teamcity Bot and 
   the `green visa` attached to the JIRA ticket (see [TC.Bot: Check PR](https://mtcga.gridgain.com/prs.html))
   
   ### Notes
   - [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
   - [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
   - [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
   - [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
   
   If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.
   


----------------------------------------------------------------
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



[GitHub] [ignite] sergey-chugunov-1985 commented on a change in pull request #8681: IGNITE-13877

Posted by GitBox <gi...@apache.org>.
sergey-chugunov-1985 commented on a change in pull request #8681:
URL: https://github.com/apache/ignite/pull/8681#discussion_r568434221



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileWriteAheadLogManager.java
##########
@@ -1521,21 +1525,129 @@ private void checkOrPrepareFiles() throws StorageException {
             }
         }
 
-        File[] allFiles = walWorkDir.listFiles(WAL_SEGMENT_FILE_FILTER);
+        FileDescriptor[] walFiles = scan(walWorkDir.listFiles(WAL_SEGMENT_FILE_FILTER));
 
-        if (isArchiverEnabled() && !F.isEmpty(allFiles) && allFiles.length > dsCfg.getWalSegments()) {
-            throw new StorageException("Failed to initialize wal (work directory contains incorrect " +
-                "number of segments) [cur=" + allFiles.length + ", expected=" + dsCfg.getWalSegments() + ']');
-        }
+        if (F.isEmpty(walFiles))
+            createFile(new File(walWorkDir, fileName(0)));
 
-        // Allocate the first segment synchronously. All other segments will be allocated by archiver in background.
-        if (F.isEmpty(allFiles)) {
-            File first = new File(walWorkDir, fileName(0));
+        if (isArchiverEnabled()) {

Review comment:
       this part contains a lot of different logic: moving segments to arch dir, renaming last segment, formatting segments etc
   
   I strongly believe all these (isolated, to some extent) pieces of code should live in their own methods with descriptive names and corresponding javadocs. This should improve readability of our code greatly.




----------------------------------------------------------------
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



[GitHub] [ignite] sergey-chugunov-1985 commented on a change in pull request #8681: IGNITE-13877

Posted by GitBox <gi...@apache.org>.
sergey-chugunov-1985 commented on a change in pull request #8681:
URL: https://github.com/apache/ignite/pull/8681#discussion_r568435274



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileWriteAheadLogManager.java
##########
@@ -1521,21 +1525,129 @@ private void checkOrPrepareFiles() throws StorageException {
             }
         }
 
-        File[] allFiles = walWorkDir.listFiles(WAL_SEGMENT_FILE_FILTER);
+        FileDescriptor[] walFiles = scan(walWorkDir.listFiles(WAL_SEGMENT_FILE_FILTER));
 
-        if (isArchiverEnabled() && !F.isEmpty(allFiles) && allFiles.length > dsCfg.getWalSegments()) {
-            throw new StorageException("Failed to initialize wal (work directory contains incorrect " +
-                "number of segments) [cur=" + allFiles.length + ", expected=" + dsCfg.getWalSegments() + ']');
-        }
+        if (F.isEmpty(walFiles))
+            createFile(new File(walWorkDir, fileName(0)));
 
-        // Allocate the first segment synchronously. All other segments will be allocated by archiver in background.
-        if (F.isEmpty(allFiles)) {
-            File first = new File(walWorkDir, fileName(0));
+        if (isArchiverEnabled()) {
+            List<FileDescriptor> toMove = new ArrayList<>();
+            @Nullable FileDescriptor toRen = null;
+
+            if (!F.isEmpty(walFiles) && (walFiles.length > dsCfg.getWalSegments() || walFiles[0].idx() != 0)) {
+                toMove.addAll(F.asList(walFiles));
+
+                FileDescriptor rmv = toMove.remove(toMove.size() - 1);
+                toRen = rmv.idx() != rmv.idx() % dsCfg.getWalSegments() ? rmv : null;
+            }
+
+            toMove.addAll(F.asList(scan(walWorkDir.listFiles(WAL_SEGMENT_FILE_COMPACTED_FILTER))));
+
+            if (!toMove.isEmpty() || toRen != null) {
+                log.warning("Invalid WAL working directory contents found, for archiving to work, will need " +
+                    (toMove.isEmpty() ? "" : "move WAL segments to archive " + (toRen == null ? "" : "and ")) +
+                    (toRen == null ? "" : "rename last WAL segment") + ", this may take some time [" +
+                    (toMove.isEmpty() ? "" : "toMove=" + F.viewReadOnly(toMove, fd -> fd.file().getName())) +
+                    (toRen == null ? "" : (toMove.isEmpty() ? "" : ", ") + "toRename=[" + toRen.file().getName() +
+                        " -> " + fileName(toRen.idx() % dsCfg.getWalSegments()) + ']') + ']');
+
+                for (FileDescriptor fd : toMove) {
+                    File tmpDst = new File(walArchiveDir, fd.file().getName() + TMP_SUFFIX);
+                    File dst = new File(walArchiveDir, fd.file().getName());
+
+                    try {
+                        Files.copy(fd.file().toPath(), tmpDst.toPath());
+
+                        Files.move(tmpDst.toPath(), dst.toPath());
+
+                        Files.delete(fd.file().toPath());
+
+                        if (log.isInfoEnabled()) {

Review comment:
       I can easily imagine a situation when we have dozens or even hundreds segments to move, printing out a message for each will blow up our logs immediately.
   
   Suggest replacing with some batching.




----------------------------------------------------------------
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



[GitHub] [ignite] sergey-chugunov-1985 commented on a change in pull request #8681: IGNITE-13877

Posted by GitBox <gi...@apache.org>.
sergey-chugunov-1985 commented on a change in pull request #8681:
URL: https://github.com/apache/ignite/pull/8681#discussion_r568387101



##########
File path: modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/wal/WalArchiveConsistencyTest.java
##########
@@ -0,0 +1,295 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.persistence.wal;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.WALMode;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.junits.WithSystemProperty;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_THRESHOLD_WAL_ARCHIVE_SIZE_PERCENTAGE;
+import static org.apache.ignite.configuration.DataStorageConfiguration.DFLT_WAL_PATH;
+import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
+
+/**
+ * Class for testing cases when WAL archive configuration was changed and the node was able to start.
+ */
+@RunWith(Parameterized.class)
+@WithSystemProperty(key = IGNITE_THRESHOLD_WAL_ARCHIVE_SIZE_PERCENTAGE, value = "0.0")
+public class WalArchiveConsistencyTest extends GridCommonAbstractTest {
+    /**
+     * WAL mode.
+     */
+    @Parameterized.Parameter
+    public WALMode walMode;
+
+    /**
+     * @return Test parameters.
+     */
+    @Parameterized.Parameters(name = "walMode={0}")
+    public static Collection<Object[]> parameters() {
+        return Arrays.asList(
+            new Object[] {WALMode.LOG_ONLY},
+            new Object[] {WALMode.FSYNC}
+

Review comment:
       empty line




----------------------------------------------------------------
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



[GitHub] [ignite] sergey-chugunov-1985 commented on a change in pull request #8681: IGNITE-13877

Posted by GitBox <gi...@apache.org>.
sergey-chugunov-1985 commented on a change in pull request #8681:
URL: https://github.com/apache/ignite/pull/8681#discussion_r568387101



##########
File path: modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/wal/WalArchiveConsistencyTest.java
##########
@@ -0,0 +1,295 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.persistence.wal;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.WALMode;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.junits.WithSystemProperty;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_THRESHOLD_WAL_ARCHIVE_SIZE_PERCENTAGE;
+import static org.apache.ignite.configuration.DataStorageConfiguration.DFLT_WAL_PATH;
+import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
+
+/**
+ * Class for testing cases when WAL archive configuration was changed and the node was able to start.
+ */
+@RunWith(Parameterized.class)
+@WithSystemProperty(key = IGNITE_THRESHOLD_WAL_ARCHIVE_SIZE_PERCENTAGE, value = "0.0")
+public class WalArchiveConsistencyTest extends GridCommonAbstractTest {
+    /**
+     * WAL mode.
+     */
+    @Parameterized.Parameter
+    public WALMode walMode;
+
+    /**
+     * @return Test parameters.
+     */
+    @Parameterized.Parameters(name = "walMode={0}")
+    public static Collection<Object[]> parameters() {
+        return Arrays.asList(
+            new Object[] {WALMode.LOG_ONLY},
+            new Object[] {WALMode.FSYNC}
+

Review comment:
       empty line

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileWriteAheadLogManager.java
##########
@@ -1521,21 +1525,129 @@ private void checkOrPrepareFiles() throws StorageException {
             }
         }
 
-        File[] allFiles = walWorkDir.listFiles(WAL_SEGMENT_FILE_FILTER);
+        FileDescriptor[] walFiles = scan(walWorkDir.listFiles(WAL_SEGMENT_FILE_FILTER));
 
-        if (isArchiverEnabled() && !F.isEmpty(allFiles) && allFiles.length > dsCfg.getWalSegments()) {
-            throw new StorageException("Failed to initialize wal (work directory contains incorrect " +
-                "number of segments) [cur=" + allFiles.length + ", expected=" + dsCfg.getWalSegments() + ']');
-        }
+        if (F.isEmpty(walFiles))
+            createFile(new File(walWorkDir, fileName(0)));
 
-        // Allocate the first segment synchronously. All other segments will be allocated by archiver in background.
-        if (F.isEmpty(allFiles)) {
-            File first = new File(walWorkDir, fileName(0));
+        if (isArchiverEnabled()) {

Review comment:
       this part contains a lot of different logic: moving segments to arch dir, renaming last segment, formatting segments etc
   
   I strongly believe all these (isolated, to some extent) pieces of code should live in their own methods with descriptive names and corresponding javadocs. This should improve readability of our code greatly.

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileWriteAheadLogManager.java
##########
@@ -1521,21 +1525,129 @@ private void checkOrPrepareFiles() throws StorageException {
             }
         }
 
-        File[] allFiles = walWorkDir.listFiles(WAL_SEGMENT_FILE_FILTER);
+        FileDescriptor[] walFiles = scan(walWorkDir.listFiles(WAL_SEGMENT_FILE_FILTER));
 
-        if (isArchiverEnabled() && !F.isEmpty(allFiles) && allFiles.length > dsCfg.getWalSegments()) {
-            throw new StorageException("Failed to initialize wal (work directory contains incorrect " +
-                "number of segments) [cur=" + allFiles.length + ", expected=" + dsCfg.getWalSegments() + ']');
-        }
+        if (F.isEmpty(walFiles))
+            createFile(new File(walWorkDir, fileName(0)));
 
-        // Allocate the first segment synchronously. All other segments will be allocated by archiver in background.
-        if (F.isEmpty(allFiles)) {
-            File first = new File(walWorkDir, fileName(0));
+        if (isArchiverEnabled()) {
+            List<FileDescriptor> toMove = new ArrayList<>();
+            @Nullable FileDescriptor toRen = null;
+
+            if (!F.isEmpty(walFiles) && (walFiles.length > dsCfg.getWalSegments() || walFiles[0].idx() != 0)) {
+                toMove.addAll(F.asList(walFiles));
+
+                FileDescriptor rmv = toMove.remove(toMove.size() - 1);
+                toRen = rmv.idx() != rmv.idx() % dsCfg.getWalSegments() ? rmv : null;
+            }
+
+            toMove.addAll(F.asList(scan(walWorkDir.listFiles(WAL_SEGMENT_FILE_COMPACTED_FILTER))));
+
+            if (!toMove.isEmpty() || toRen != null) {
+                log.warning("Invalid WAL working directory contents found, for archiving to work, will need " +
+                    (toMove.isEmpty() ? "" : "move WAL segments to archive " + (toRen == null ? "" : "and ")) +
+                    (toRen == null ? "" : "rename last WAL segment") + ", this may take some time [" +
+                    (toMove.isEmpty() ? "" : "toMove=" + F.viewReadOnly(toMove, fd -> fd.file().getName())) +
+                    (toRen == null ? "" : (toMove.isEmpty() ? "" : ", ") + "toRename=[" + toRen.file().getName() +
+                        " -> " + fileName(toRen.idx() % dsCfg.getWalSegments()) + ']') + ']');
+
+                for (FileDescriptor fd : toMove) {
+                    File tmpDst = new File(walArchiveDir, fd.file().getName() + TMP_SUFFIX);
+                    File dst = new File(walArchiveDir, fd.file().getName());
+
+                    try {
+                        Files.copy(fd.file().toPath(), tmpDst.toPath());
+
+                        Files.move(tmpDst.toPath(), dst.toPath());
+
+                        Files.delete(fd.file().toPath());
+
+                        if (log.isInfoEnabled()) {

Review comment:
       I can easily imagine a situation when we have dozens or even hundreds segments to move, printing out a message for each will blow up our logs immediately.
   
   Suggest replacing with some batching.




----------------------------------------------------------------
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



[GitHub] [ignite] asfgit closed pull request #8681: IGNITE-13877

Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #8681:
URL: https://github.com/apache/ignite/pull/8681


   


----------------------------------------------------------------
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