tkalkirill commented on code in PR #2594:
URL: https://github.com/apache/ignite-3/pull/2594#discussion_r1328287005
##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/checkpoint/CheckpointWorkflow.java:
##########
@@ -343,14 +365,35 @@ private DataRegionsDirtyPages beginCheckpoint(
Collection<? extends DataRegion<PersistentPageMemory>> dataRegions,
CompletableFuture<?> allowToReplace
) {
+ Map<DataRegion<?>, Set<FullPageId>> dirtyPartitionsMap =
this.dirtyPartitionsMap;
+
+ this.dirtyPartitionsMap = new ConcurrentHashMap<>();
Review Comment:
Why is `dirtyPartitionsMap` not volatile?
If this is a fine case, mention the reason in the javaDoc for the field.
##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/PersistentPageMemory.java:
##########
@@ -1230,6 +1230,7 @@ private void setDirty(FullPageId pageId, long absPtr,
boolean dirty, boolean for
if (dirty) {
assert checkpointTimeoutLock.checkpointLockIsHeldByThread();
+ assert pageIndex(pageId.pageId()) != 0;
Review Comment:
Optional: maybe add text, what's wrong here?
##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/engine/AbstractStorageEngineTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.storage.engine;
+
+import static
org.apache.ignite.internal.catalog.commands.CatalogUtils.DEFAULT_DATA_REGION;
+import static
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
+import static org.mockito.Mockito.mock;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.storage.AbstractMvTableStorageTest;
+import org.apache.ignite.internal.storage.BaseMvStoragesTest;
+import org.apache.ignite.internal.storage.MvPartitionStorage;
+import org.apache.ignite.internal.storage.index.StorageIndexDescriptorSupplier;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests basic functionality of storage engines. Allows for more complex
scenarios than {@link AbstractMvTableStorageTest}, because it
+ * doesn't limit the usage of the engine with a single table.
+ */
+public abstract class AbstractStorageEngineTest extends BaseMvStoragesTest {
+ /** Engine instance. */
+ private StorageEngine storageEngine;
+
+ @BeforeEach
+ void createEngineBeforeTest() {
+ storageEngine = createEngine();
+
+ storageEngine.start();
+ }
+
+ @AfterEach
+ void stopEngineAfterTest() {
+ if (storageEngine != null) {
+ storageEngine.stop();
+ }
+ }
+
+ /**
+ * Creates a new storage engine instance. For persistent engines, the
instances within a single test method should point to the same
+ * directory.
+ */
+ protected abstract StorageEngine createEngine();
+
+ /**
+ * Tests that explicitly flushed data remains persistent on the device,
when the engine is restarted.
+ */
+ @Test
+ void testRestartAfterFlush() throws Exception {
+ assumeFalse(storageEngine.isVolatile());
+
+ StorageTableDescriptor tableDescriptor = new StorageTableDescriptor(1,
1, DEFAULT_DATA_REGION);
+ StorageIndexDescriptorSupplier indexSupplier =
mock(StorageIndexDescriptorSupplier.class);
+
+ MvTableStorage mvTableStorage =
storageEngine.createMvTable(tableDescriptor, indexSupplier);
+
+ mvTableStorage.start();
+ try (AutoCloseable ignored0 = mvTableStorage::stop) {
+ CompletableFuture<MvPartitionStorage> mvPartitionStorageFuture =
mvTableStorage.createMvPartition(0);
+
+ assertThat(mvPartitionStorageFuture, willCompleteSuccessfully());
+ MvPartitionStorage mvPartitionStorage =
mvPartitionStorageFuture.join();
+
+ try (AutoCloseable ignored1 = mvTableStorage::stop) {
+ // Flush. Persist the table itself, not the update.
+ CompletableFuture<Void> flushFuture =
mvPartitionStorage.flush();
+ assertThat(flushFuture, willCompleteSuccessfully());
+
+ mvPartitionStorage.runConsistently(locker -> {
+ // Update of basic storage data.
+ mvPartitionStorage.lastApplied(10, 20);
+
+ return null;
+ });
+
+ // Flush.
+ flushFuture = mvPartitionStorage.flush();
+ assertThat(flushFuture, willCompleteSuccessfully());
Review Comment:
```suggestion
assertThat(mvPartitionStorage.flush(),
willCompleteSuccessfully());
```
##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/checkpoint/CheckpointWorkflow.java:
##########
@@ -343,14 +365,35 @@ private DataRegionsDirtyPages beginCheckpoint(
Collection<? extends DataRegion<PersistentPageMemory>> dataRegions,
CompletableFuture<?> allowToReplace
) {
+ Map<DataRegion<?>, Set<FullPageId>> dirtyPartitionsMap =
this.dirtyPartitionsMap;
+
+ this.dirtyPartitionsMap = new ConcurrentHashMap<>();
+
Collection<DataRegionDirtyPages<Collection<FullPageId>>>
dataRegionsDirtyPages = new ArrayList<>(dataRegions.size());
+ // First, we iterate all regions that have dirty pages.
for (DataRegion<PersistentPageMemory> dataRegion : dataRegions) {
Collection<FullPageId> dirtyPages =
dataRegion.pageMemory().beginCheckpoint(allowToReplace);
+ Set<FullPageId> dirtyMetaPageIds =
dirtyPartitionsMap.remove(dataRegion);
+
+ if (dirtyMetaPageIds != null) {
+ // Merge these two collections. There should be no
intersections.
+ dirtyPages = CollectionUtils.concat(dirtyMetaPageIds,
dirtyPages);
Review Comment:
I remember that you didn’t like `CollectionUtils#concat`, I see that you
used it)
##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/engine/AbstractStorageEngineTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.storage.engine;
+
+import static
org.apache.ignite.internal.catalog.commands.CatalogUtils.DEFAULT_DATA_REGION;
+import static
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
+import static org.mockito.Mockito.mock;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.storage.AbstractMvTableStorageTest;
+import org.apache.ignite.internal.storage.BaseMvStoragesTest;
+import org.apache.ignite.internal.storage.MvPartitionStorage;
+import org.apache.ignite.internal.storage.index.StorageIndexDescriptorSupplier;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests basic functionality of storage engines. Allows for more complex
scenarios than {@link AbstractMvTableStorageTest}, because it
+ * doesn't limit the usage of the engine with a single table.
+ */
+public abstract class AbstractStorageEngineTest extends BaseMvStoragesTest {
+ /** Engine instance. */
+ private StorageEngine storageEngine;
+
+ @BeforeEach
+ void createEngineBeforeTest() {
+ storageEngine = createEngine();
+
+ storageEngine.start();
+ }
+
+ @AfterEach
+ void stopEngineAfterTest() {
+ if (storageEngine != null) {
+ storageEngine.stop();
+ }
+ }
+
+ /**
+ * Creates a new storage engine instance. For persistent engines, the
instances within a single test method should point to the same
+ * directory.
+ */
+ protected abstract StorageEngine createEngine();
+
+ /**
+ * Tests that explicitly flushed data remains persistent on the device,
when the engine is restarted.
+ */
+ @Test
+ void testRestartAfterFlush() throws Exception {
+ assumeFalse(storageEngine.isVolatile());
+
+ StorageTableDescriptor tableDescriptor = new StorageTableDescriptor(1,
1, DEFAULT_DATA_REGION);
+ StorageIndexDescriptorSupplier indexSupplier =
mock(StorageIndexDescriptorSupplier.class);
+
+ MvTableStorage mvTableStorage =
storageEngine.createMvTable(tableDescriptor, indexSupplier);
+
+ mvTableStorage.start();
+ try (AutoCloseable ignored0 = mvTableStorage::stop) {
+ CompletableFuture<MvPartitionStorage> mvPartitionStorageFuture =
mvTableStorage.createMvPartition(0);
+
+ assertThat(mvPartitionStorageFuture, willCompleteSuccessfully());
+ MvPartitionStorage mvPartitionStorage =
mvPartitionStorageFuture.join();
+
+ try (AutoCloseable ignored1 = mvTableStorage::stop) {
+ // Flush. Persist the table itself, not the update.
+ CompletableFuture<Void> flushFuture =
mvPartitionStorage.flush();
+ assertThat(flushFuture, willCompleteSuccessfully());
Review Comment:
```suggestion
assertThat(mvPartitionStorage.flush(),
willCompleteSuccessfully());
```
##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/mv/PersistentPageMemoryMvPartitionStorage.java:
##########
@@ -212,13 +212,30 @@ public void lastApplied(long lastAppliedIndex, long
lastAppliedTerm) throws Stor
}
private void lastAppliedBusy(long lastAppliedIndex, long lastAppliedTerm)
throws StorageException {
+ updateMeta((lastCheckpointId, meta) ->
meta.lastApplied(lastCheckpointId, lastAppliedIndex, lastAppliedTerm));
+ }
+
+ /**
+ * Closure interface for {@link #update(UUID, PartitionMeta)}.
+ */
+ @FunctionalInterface
+ private interface MetaUpdateClosure {
+ void update(UUID lastCheckpointId, PartitionMeta meta);
+ }
+
+ /**
+ * Updates partition meta. Hides all the necessary boilderplate in a
single place.
+ */
Review Comment:
```suggestion
/** Updates partition meta. Hides all the necessary boilderplate in a
single place. */
```
##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/checkpoint/CheckpointWorkflow.java:
##########
@@ -161,6 +174,15 @@ public void stop() {
}
}
+ /**
+ * Marks partition as dirty, forcing partition's meta-page to be written
on disk during next checkpoint.
+ */
+ public void markPartitionAsDirty(DataRegion<?> dataRegion, int groupId,
int partitionId) {
+ Set<FullPageId> dirtyMetaPageIds =
dirtyPartitionsMap.computeIfAbsent(dataRegion, unused -> newKeySet());
Review Comment:
Optional: It is not necessary to use a local variable.
##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/checkpoint/CheckpointWorkflow.java:
##########
@@ -343,14 +365,35 @@ private DataRegionsDirtyPages beginCheckpoint(
Collection<? extends DataRegion<PersistentPageMemory>> dataRegions,
CompletableFuture<?> allowToReplace
) {
+ Map<DataRegion<?>, Set<FullPageId>> dirtyPartitionsMap =
this.dirtyPartitionsMap;
+
+ this.dirtyPartitionsMap = new ConcurrentHashMap<>();
+
Collection<DataRegionDirtyPages<Collection<FullPageId>>>
dataRegionsDirtyPages = new ArrayList<>(dataRegions.size());
+ // First, we iterate all regions that have dirty pages.
for (DataRegion<PersistentPageMemory> dataRegion : dataRegions) {
Collection<FullPageId> dirtyPages =
dataRegion.pageMemory().beginCheckpoint(allowToReplace);
+ Set<FullPageId> dirtyMetaPageIds =
dirtyPartitionsMap.remove(dataRegion);
+
+ if (dirtyMetaPageIds != null) {
+ // Merge these two collections. There should be no
intersections.
+ dirtyPages = CollectionUtils.concat(dirtyMetaPageIds,
dirtyPages);
Review Comment:
I remember that you didn’t like `CollectionUtils#concat`, I see that you
used it)
##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/mv/PersistentPageMemoryMvPartitionStorage.java:
##########
@@ -212,13 +212,30 @@ public void lastApplied(long lastAppliedIndex, long
lastAppliedTerm) throws Stor
}
private void lastAppliedBusy(long lastAppliedIndex, long lastAppliedTerm)
throws StorageException {
+ updateMeta((lastCheckpointId, meta) ->
meta.lastApplied(lastCheckpointId, lastAppliedIndex, lastAppliedTerm));
+ }
+
+ /**
+ * Closure interface for {@link #update(UUID, PartitionMeta)}.
+ */
Review Comment:
```suggestion
/** Closure interface for {@link #update(UUID, PartitionMeta)}. */
```
##########
modules/storage-api/src/main/java/org/apache/ignite/internal/storage/engine/StorageEngine.java:
##########
@@ -43,6 +43,11 @@ public interface StorageEngine {
*/
void stop() throws StorageException;
+ /**
+ * Whether the data is lost upon engine restart or not.
+ */
Review Comment:
```suggestion
/** Whether the data is lost upon engine restart or not. */
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]