Skip to content

Commit

Permalink
IGNITE-15295 Correct exception for checkpoint marker reading error - F…
Browse files Browse the repository at this point in the history
…ixes apache#9325.

Signed-off-by: Sergey Chugunov <sergey.chugunov@gmail.com>
  • Loading branch information
denis-chudov authored and sergey-chugunov-1985 committed Aug 26, 2021
1 parent 3c1c92e commit d02fff5
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ private WALPointer readPointer(File cpMarkerFile, ByteBuffer buf) throws IgniteC

return new WALPointer(buf.getLong(), buf.getInt(), buf.getInt());
}
catch (IOException e) {
catch (Exception e) {
throw new IgniteCheckedException(
"Failed to read checkpoint pointer from marker file: " + cpMarkerFile.getAbsolutePath(), e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* 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.db.checkpoint;

import java.io.File;
import java.io.FileOutputStream;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.cluster.ClusterState;
import org.apache.ignite.configuration.DataRegionConfiguration;
import org.apache.ignite.configuration.DataStorageConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.junit.Test;

import static org.apache.ignite.testframework.GridTestUtils.assertThrows;

/**
* Tests that checkpoint marker reading error throws correct exception.
*/
public class CheckpointMarkerReadingErrorOnStartTest extends GridCommonAbstractTest {
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
return super.getConfiguration(igniteInstanceName)
.setDataStorageConfiguration(
new DataStorageConfiguration()
.setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true))
);
}

/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
super.beforeTest();

stopAllGrids();

cleanPersistenceDir();
}

/** {@inheritDoc} */
@Override protected void afterTest() throws Exception {
stopAllGrids();

cleanPersistenceDir();

super.afterTest();
}

/** Tests that checkpoint marker reading error throws correct exception. */
@Test
public void test() throws Exception {
IgniteEx ignite = startGrid(0);

ignite.cluster().state(ClusterState.ACTIVE);

IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(DEFAULT_CACHE_NAME);

cache.put(0, 0);

forceCheckpoint();

final PdsFolderSettings folderSettings = ignite.context().pdsFolderResolver().resolveFolders();

File storeWorkDir = new File(folderSettings.persistentStoreRootPath(), folderSettings.folderName());

File cpMarkersDir = new File(storeWorkDir, "cp");

stopGrid(0);

File[] cpMarkers = cpMarkersDir.listFiles();

assertNotNull(cpMarkers);

for (File marker : cpMarkers) {
new FileOutputStream(marker).close();
}

assertThrows(log, () -> startGrid(0), IgniteCheckedException.class,
"Failed to read checkpoint pointer from marker file");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.apache.ignite.internal.processors.cache.persistence.db.checkpoint.CheckpointFailBeforeWriteMarkTest;
import org.apache.ignite.internal.processors.cache.persistence.db.checkpoint.CheckpointFreeListTest;
import org.apache.ignite.internal.processors.cache.persistence.db.checkpoint.CheckpointListenerForRegionTest;
import org.apache.ignite.internal.processors.cache.persistence.db.checkpoint.CheckpointMarkerReadingErrorOnStartTest;
import org.apache.ignite.internal.processors.cache.persistence.db.checkpoint.CheckpointStartLoggingTest;
import org.apache.ignite.internal.processors.cache.persistence.db.checkpoint.IgniteCheckpointDirtyPagesForLowLoadTest;
import org.apache.ignite.internal.processors.cache.persistence.db.checkpoint.LightweightCheckpointTest;
Expand Down Expand Up @@ -150,6 +151,8 @@ public static List<Class<?>> suite(Collection<Class> ignoredTests) {

GridTestUtils.addTestIfNeeded(suite, WalArchiveSizeConfigurationTest.class, ignoredTests);

GridTestUtils.addTestIfNeeded(suite, CheckpointMarkerReadingErrorOnStartTest.class, ignoredTests);

return suite;
}

Expand Down

0 comments on commit d02fff5

Please sign in to comment.