This is an automated email from the ASF dual-hosted git repository.
zstan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 3a6371390d1 IGNITE-21900 Remove meta command need to remove marshaller
data (#11295)
3a6371390d1 is described below
commit 3a6371390d1175346a5f7891be71238f1c5defdf
Author: Evgeniy Stanilovskiy <[email protected]>
AuthorDate: Wed Apr 3 16:02:50 2024 +0300
IGNITE-21900 Remove meta command need to remove marshaller data (#11295)
---
.../util/GridCommandHandlerIndexingTest.java | 34 ++++++++++++++++++++++
.../ignite/internal/MarshallerContextImpl.java | 18 ++++++++++++
.../internal/MarshallerMappingFileStore.java | 24 +++++++++++++++
.../cache/binary/BinaryMetadataFileStore.java | 2 ++
4 files changed, 78 insertions(+)
diff --git
a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingTest.java
b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingTest.java
index 46535d73e8b..23640957d91 100644
---
a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingTest.java
+++
b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerIndexingTest.java
@@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.cluster.ClusterState;
import org.apache.ignite.internal.IgniteEx;
@@ -100,6 +101,39 @@ public class GridCommandHandlerIndexingTest extends
GridCommandHandlerClusterPer
assertContains(log, out, GRID_NOT_IDLE_MSG + "[\"" + GROUP_NAME +
"\"]");
}
+ /** Check that metadata remove command also removes class mapping. */
+ @Test
+ public void testRemoveMetadataAndRecreateWithDifferentCase() throws
Exception {
+ IgniteEx ig = startGrids(2);
+
+ ig.cluster().active(true);
+
+ IgniteCache<?, ?> cache = grid(0).getOrCreateCache(CACHE_NAME);
+
+ cache.query(new SqlFieldsQuery("CREATE TABLE t1(id INT PRIMARY KEY,
str VARCHAR) " +
+ "WITH \"cache_name=" + DEFAULT_CACHE_NAME + ",
key_type=CUSTOM_SQL_KEY_TYPE, value_type=CUSTOM_SQL_VALUE_TYPE\"")
+ .setSchema("PUBLIC")).getAll();
+
+ cache.query(new SqlFieldsQuery("INSERT INTO PUBLIC.t1 VALUES(1,
'1')")).getAll();
+
+ cache.query(new SqlFieldsQuery("DROP TABLE PUBLIC.t1")).getAll();
+
+ assertEquals(EXIT_CODE_OK, execute("--meta", "remove", "--typeName",
"CUSTOM_SQL_KEY_TYPE"));
+ assertEquals(EXIT_CODE_OK, execute("--meta", "remove", "--typeName",
"CUSTOM_SQL_VALUE_TYPE"));
+
+ cache.query(new SqlFieldsQuery("CREATE TABLE t1(id INT PRIMARY KEY,
str VARCHAR) " +
+ "WITH \"cache_name=" + DEFAULT_CACHE_NAME + ",
key_type=CUSTOM_SQL_KEY_TYPE, value_type=CUSTOM_SQL_VALUE_type\"")
+ .setSchema("PUBLIC")).getAll();
+
+ for (int i = 0; i < 10; ++i) {
+ cache.query(new SqlFieldsQuery("INSERT INTO PUBLIC.t1 VALUES(" + i
+ ", '1')")).getAll();
+ }
+
+ List<List<?>> res = cache.query(new SqlFieldsQuery("SELECT * FROM
PUBLIC.t1")).getAll();
+
+ assertEquals(10, res.size());
+ }
+
/** Run index validation check on busy cluster. */
@Test
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
index 327e40d307a..2cf1146e3be 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
@@ -329,6 +329,19 @@ public class MarshallerContextImpl implements
MarshallerContext {
return true;
}
+ /** Remove mapping for appropriate type locally. */
+ public void unregisterClassNameLocally(int typeId) {
+ byte[] allPlatforms = otherPlatforms((byte)-1);
+
+ for (byte platformId : allPlatforms) {
+ ConcurrentMap<Integer, MappedName> cache = getCacheFor(platformId);
+
+ cache.remove(typeId);
+ }
+
+ fileStore.deleteMapping(typeId);
+ }
+
/**
* @param res result of exchange.
*/
@@ -700,6 +713,11 @@ public class MarshallerContextImpl implements
MarshallerContext {
return false;
}
+ /** {@inheritDoc} */
+ @Override public MappedName remove(@NotNull Object key) {
+ return userMap.remove(key);
+ }
+
/** {@inheritDoc} */
@Override public boolean replace(@NotNull Integer key, @NotNull
MappedName oldVal, @NotNull MappedName newVal) {
return false;
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerMappingFileStore.java
b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerMappingFileStore.java
index c719710bde9..26bab219fb1 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerMappingFileStore.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerMappingFileStore.java
@@ -36,6 +36,7 @@ import org.apache.ignite.marshaller.MarshallerContext;
import static java.nio.file.StandardCopyOption.ATOMIC_MOVE;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
+import static org.apache.ignite.internal.MarshallerPlatformIds.otherPlatforms;
import static
org.apache.ignite.internal.binary.BinaryUtils.MAPPING_FILE_EXTENSION;
import static
org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.TMP_SUFFIX;
@@ -76,6 +77,29 @@ final class MarshallerMappingFileStore {
fixLegacyFolder();
}
+ /** Drop appropriate mapping file. */
+ void deleteMapping(int typeId) {
+ byte[] allPlatforms = otherPlatforms((byte)-1);
+
+ for (byte platformId : allPlatforms) {
+ String fileName = BinaryUtils.mappingFileName(platformId, typeId);
+
+ File file = new File(mappingDir, fileName);
+
+ if (file.exists()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Try to remove: " + file.getAbsolutePath());
+ }
+
+ if (!file.delete()) {
+ final String msg = "Failed to remove mapping for typeId: "
+ typeId;
+
+ U.error(log, msg);
+ }
+ }
+ }
+ }
+
/**
* @param platformId Platform id.
* @param typeId Type id.
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/BinaryMetadataFileStore.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/BinaryMetadataFileStore.java
index 408e6f1ffc8..0ffafc4b432 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/BinaryMetadataFileStore.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/BinaryMetadataFileStore.java
@@ -193,6 +193,8 @@ class BinaryMetadataFileStore {
if (!enabled)
return;
+ ctx.marshallerContext().unregisterClassNameLocally(typeId);
+
File file = new File(metadataDir,
BinaryUtils.binaryMetaFileName(typeId));
if (!file.delete()) {