ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ag...@apache.org
Subject ignite git commit: IGNITE-6722 Writing to disk metadate in registerLocally methods was added
Date Tue, 07 Nov 2017 12:10:52 GMT
Repository: ignite
Updated Branches:
  refs/heads/master cc6975dab -> 3132a18a9


IGNITE-6722 Writing to disk metadate in registerLocally methods was added

Signed-off-by: Andrey Gura <agura@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/3132a18a
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/3132a18a
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/3132a18a

Branch: refs/heads/master
Commit: 3132a18a93d3e30e49f6ee3765dd176e79a4cd4a
Parents: cc6975d
Author: Sergey Chugunov <sergey.chugunov@gmail.com>
Authored: Tue Nov 7 15:10:18 2017 +0300
Committer: Andrey Gura <agura@apache.org>
Committed: Tue Nov 7 15:10:18 2017 +0300

----------------------------------------------------------------------
 .../ignite/internal/MarshallerContextImpl.java  |  2 +
 .../internal/MarshallerMappingFileStore.java    | 23 +++++++++++
 .../cache/binary/BinaryMetadataFileStore.java   | 43 +++++++++++++++++++-
 .../cache/binary/BinaryMetadataTransport.java   |  4 +-
 .../binary/CacheObjectBinaryProcessorImpl.java  | 15 +++++--
 5 files changed, 81 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/3132a18a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
----------------------------------------------------------------------
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 1e5c370..08661a3 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
@@ -277,6 +277,8 @@ public class MarshallerContextImpl implements MarshallerContext {
     {
         ConcurrentMap<Integer, MappedName> cache = getCacheFor(platformId);
 
+        fileStore.mergeAndWriteMapping(platformId, typeId, clsName);
+
         cache.put(typeId, new MappedName(clsName, true));
 
         return true;

http://git-wip-us.apache.org/repos/asf/ignite/blob/3132a18a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerMappingFileStore.java
----------------------------------------------------------------------
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 59a99b8..6fb1371 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
@@ -185,6 +185,29 @@ final class MarshallerMappingFileStore {
     }
 
     /**
+     * Checks if marshaller mapping for given [platformId, typeId] pair is already presented
on disk.
+     * If so verifies that it is the same (if no {@link IgniteCheckedException} is thrown).
+     * If there is not such mapping writes it.
+     *
+     * @param platformId Platform id.
+     * @param typeId Type id.
+     * @param typeName Type name.
+     */
+    void mergeAndWriteMapping(byte platformId, int typeId, String typeName) throws IgniteCheckedException
{
+        String existingTypeName = readMapping(platformId, typeId);
+
+        if (existingTypeName != null) {
+            if (!existingTypeName.equals(typeName))
+                throw new IgniteCheckedException("Failed to merge new and existing marshaller
mappings." +
+                    " For [platformId=" + platformId + ", typeId=" + typeId + "]" +
+                    " new typeName=" + typeName + ", existing typeName=" + existingTypeName
+ "." +
+                    " Consider cleaning up persisted mappings from <workDir>/marshaller
directory.");
+        }
+        else
+            writeMapping(platformId, typeId, typeName);
+    }
+
+    /**
      * @param fileName Name of file with marshaller mapping information.
      * @throws IgniteCheckedException If file name format is broken.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/3132a18a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/BinaryMetadataFileStore.java
----------------------------------------------------------------------
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 19514c0..a58918b 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
@@ -24,6 +24,7 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.binary.BinaryMetadata;
+import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.util.typedef.internal.CU;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.jetbrains.annotations.Nullable;
@@ -85,7 +86,7 @@ class BinaryMetadataFileStore {
     /**
      * @param binMeta Binary metadata to be written to disk.
      */
-    void saveMetadata(BinaryMetadata binMeta) {
+    void writeMetadata(BinaryMetadata binMeta) {
         if (!CU.isPersistenceEnabled(ctx.config()))
             return;
 
@@ -123,4 +124,44 @@ class BinaryMetadataFileStore {
             }
         }
     }
+
+    /**
+     * Checks if binary metadata for the same typeId is already presented on disk.
+     * If so merges it with new metadata and stores the result.
+     * Otherwise just writes new metadata.
+     *
+     * @param binMeta new binary metadata to write to disk.
+     */
+    void mergeAndWriteMetadata(BinaryMetadata binMeta) {
+        BinaryMetadata existingMeta = readMetadata(binMeta.typeId());
+
+        if (existingMeta != null) {
+            BinaryMetadata mergedMeta = BinaryUtils.mergeMetadata(existingMeta, binMeta);
+
+            writeMetadata(mergedMeta);
+        } else
+            writeMetadata(binMeta);
+    }
+
+    /**
+     * Reads binary metadata for given typeId.
+     *
+     * @param typeId typeId of BinaryMetadata to be read.
+     */
+    private BinaryMetadata readMetadata(int typeId) {
+        File file = new File(workDir, Integer.toString(typeId) + ".bin");
+
+        if (!file.exists())
+            return null;
+
+        try (FileInputStream in = new FileInputStream(file)) {
+            return U.unmarshal(ctx.config().getMarshaller(), in, U.resolveClassLoader(ctx.config()));
+        }
+        catch (Exception e) {
+            U.warn(log, "Failed to restore metadata from file: " + file.getName() +
+                "; exception was thrown: " + e.getMessage());
+        }
+
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/3132a18a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/BinaryMetadataTransport.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/BinaryMetadataTransport.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/BinaryMetadataTransport.java
index 010ab0f..3a77190 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/BinaryMetadataTransport.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/BinaryMetadataTransport.java
@@ -462,9 +462,9 @@ final class BinaryMetadataTransport {
                     return;
                 }
 
-                metaLocCache.put(typeId, new BinaryMetadataHolder(holder.metadata(), holder.pendingVersion(),
newAcceptedVer));
+                metadataFileStore.writeMetadata(holder.metadata());
 
-                metadataFileStore.saveMetadata(holder.metadata());
+                metaLocCache.put(typeId, new BinaryMetadataHolder(holder.metadata(), holder.pendingVersion(),
newAcceptedVer));
             }
 
             for (BinaryMetadataUpdatedListener lsnr : binaryUpdatedLsnrs)

http://git-wip-us.apache.org/repos/asf/ignite/blob/3132a18a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
index 6a70936..ed4c520 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
@@ -463,9 +463,18 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
 
         BinaryMetadata oldMeta = metaHolder != null ? metaHolder.metadata() : null;
 
-        BinaryMetadata mergedMeta = BinaryUtils.mergeMetadata(oldMeta, newMeta0);
+        try {
+            BinaryMetadata mergedMeta = BinaryUtils.mergeMetadata(oldMeta, newMeta0);
+
+            metadataFileStore.mergeAndWriteMetadata(mergedMeta);
 
-        metadataLocCache.put(typeId, new BinaryMetadataHolder(mergedMeta, 0, 0));
+            metadataLocCache.put(typeId, new BinaryMetadataHolder(mergedMeta, 0, 0));
+        }
+        catch (BinaryObjectException e) {
+            throw new BinaryObjectException("New binary metadata is incompatible with binary
metadata" +
+                " persisted locally." +
+                " Consider cleaning up persisted metadata from <workDir>/binary_meta
directory.", e);
+        }
     }
 
     /** {@inheritDoc} */
@@ -918,7 +927,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
                 metadataLocCache.put(e.getKey(), localHolder);
 
                 if (!ctx.clientNode())
-                    metadataFileStore.saveMetadata(holder.metadata());
+                    metadataFileStore.writeMetadata(holder.metadata());
             }
         }
     }


Mime
View raw message