Apache Ignite:如何修复使用 StreamReceiver 时的 "Unknown pair" 错误?

Apache Ignite: How do I fix the "Unknown pair" error when using a StreamReceiver?

在将 DataStreamer 与 StreamReceiver 一起使用时,如何解决以下序列化错误?我猜它在反序列化 RowStreamReceiver.

时无法找到 class

错误:SEVERE: Failure in Java callback class org.apache.ignite.IgniteException: Platform error:Apache.Ignite.Core.Binary.BinaryObjectException: Unknown pair [platformId=1, typeId=113114]

我使用的是 Apache Ignite 2.0,我正在尝试使用本测试中展示的相同类型的代码: https://github.com/apache/ignite/blob/master/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Dataload/DataStreamerTest.cs#L436

我试过将程序集添加到配置中,但这似乎没有帮助。 config.Assemblies.Add(typeof(RowStreamReceiver).Assembly.FullName);

相关代码如下:

数据流:

using (var ds = m_ignite.GetDataStreamer<string, IBinaryObject>(CacheName)) {
    ds.AllowOverwrite = true;
    ds.Receiver = new RowStreamReceiver(); // If I comment this out, the error goes away
    Parallel.ForEach(rows.Select((r, i) => new KeyValuePair<long, string>(i, r)), r => {
        var pair = BuildRow(r.Key, r.Value);
        ds.AddData(pair);
    });
}

流接收器:

[Serializable]
public class RowStreamReceiver : IStreamReceiver<string, IBinaryObject> {
    public void Receive(ICache<string, IBinaryObject> cache, ICollection<ICacheEntry<string, IBinaryObject>> entries) {
        var bin = cache.Ignite.GetBinary();
        cache.PutAll(entries.ToDictionary(x => x.Key, x => {
            var builder = bin.GetBuilder(x.Value);
            SetColumnFields(builder);
            return builder.Build();
        }));
    }

    private static void SetColumnFields(IBinaryObjectBuilder builder) {
        /* logic to set fields */
    }
}

堆栈跟踪:

Jul 07, 2017 11:25:22 AM java.util.logging.LogManager$RootLogger log
SEVERE: Failure in Java callback class org.apache.ignite.IgniteException: Platform error:Apache.Ignite.Core.Binary.BinaryObjectException: Unknown pair [platformId=1, typeId=113114] ---> Apache.Ignite.Core.Common.JavaException: class org.apache.ignite.binary.BinaryObjectException: Unknown pair [platformId=1, typeId=113114]
        at org.apache.ignite.internal.processors.platform.binary.PlatformBinaryProcessor.processInStreamOutStream(PlatformBinaryProcessor.java:119)
        at org.apache.ignite.internal.processors.platform.PlatformTargetProxyImpl.inStreamOutStream(PlatformTargetProxyImpl.java:155)
        at org.apache.ignite.internal.processors.platform.callback.PlatformCallbackUtils.inLongLongLongObjectOutLong(Native Method)
        at org.apache.ignite.internal.processors.platform.callback.PlatformCallbackGateway.dataStreamerStreamReceiverInvoke(PlatformCallbackGateway.java:464)
        at org.apache.ignite.internal.processors.platform.datastreamer.PlatformStreamReceiverImpl.receive(PlatformStreamReceiverImpl.java:100)
        at org.apache.ignite.internal.processors.datastreamer.DataStreamerUpdateJob.call(DataStreamerUpdateJob.java:137)
        at org.apache.ignite.internal.processors.datastreamer.DataStreamProcessor.localUpdate(DataStreamProcessor.java:382)
        at org.apache.ignite.internal.processors.datastreamer.DataStreamProcessor.processRequest(DataStreamProcessor.java:301)
        at org.apache.ignite.internal.processors.datastreamer.DataStreamProcessor.access[=13=]0(DataStreamProcessor.java:58)
        at org.apache.ignite.internal.processors.datastreamer.DataStreamProcessor.onMessage(DataStreamProcessor.java:88)
        at org.apache.ignite.internal.managers.communication.GridIoManager.invokeListener(GridIoManager.java:1257)
        at org.apache.ignite.internal.managers.communication.GridIoManager.processRegularMessage0(GridIoManager.java:885)
        at org.apache.ignite.internal.managers.communication.GridIoManager.access00(GridIoManager.java:114)
        at org.apache.ignite.internal.managers.communication.GridIoManager.run(GridIoManager.java:802)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.ClassNotFoundException: Unknown pair [platformId=1, typeId=113114]
        at org.apache.ignite.internal.MarshallerContextImpl.getClassName(MarshallerContextImpl.java:385)
        at org.apache.ignite.internal.processors.platform.binary.PlatformBinaryProcessor.processInStreamOutStream(PlatformBinaryProcessor.java:113)
        ... 16 more

   --- End of inner exception stack trace ---    at Apache.Ignite.Core.Impl.Unmanaged.UnmanagedCallbacks.Error(Void* target, Int32 errType, SByte* errClsChars, Int32 errClsCharsLen, SByte* errMsgChars, Int32 errMsgCharsLen, SByte* stackTraceChars, Int32 stackTraceCharsLen, Void* errData, Int32 errDataLen)    at Apache.Ignite.Core.Impl.Unmanaged.IgniteJniNativeMethods.TargetInStreamOutStream(Void* ctx, Void* target, Int32 opType, Int64 inMemPtr, Int64 outMemPtr)    at Apache.Ignite.Core.Impl.PlatformTarget.DoOutInOp[TR](Int32 type, Action`1 outAction, Func`2 inAction)    at Apache.Ignite.Core.Impl.Binary.BinaryProcessor.GetType(Int32 id)    at Apache.Ignite.Core.Impl.Binary.Marshaller.GetDescriptor(Boolean userType, Int32 typeId, Boolean requiresType)    at Apache.Ignite.Core.Impl.Binary.BinaryReader.ReadFullObject[T](Int32 pos)    at Apache.Ignite.Core.Impl.Binary.BinaryReader.TryDeserialize[T](T& res)  at Apache.Ignite.Core.Impl.Binary.BinaryReader.Deserialize[T]()    at Apache.Ignite.Core.Impl.Binary.BinaryReader.ReadBinaryObject[T](Boolean do Detach)    at Apache.Ignite.Core.Impl.Binary.BinaryReader.TryDeserialize[T](T& res)  at Apache.Ignite.Core.Impl.Binary.BinaryReader.Deserialize[T]()    at Apache.Ignite.Core.Impl.Datastream.StreamReceiverHolder.InvokeReceiver[TK, TV](IStreamReceiver`2 receiver, Ignite grid, IUnmanagedTarget cache, IBinaryStream stream, Boolean keepBinary)    at Apache.Ignite.Core.Impl.Datastream.StreamReceiverHolder.Receive(Ignite grid, IUnmanagedTarget cache, IBinaryStream stream, Boolean keepBinary)    at Apache.Ignite.Core.Impl.Unmanaged.UnmanagedCallbacks.DataStreamerStreamReceiverInvoke(Int64 memPtr, Int64 unused, Int64 unused1, Void* cache)    at Apache.Ignite.Core.Impl.Unmanaged.UnmanagedCallbacks.InLongLongLongObjectOutLong(Void* target, Int32 type, Int64 val1, Int64 val2, Int64 val3, Void* arg)
        at org.apache.ignite.internal.processors.platform.PlatformProcessorImpl.loggerLog(PlatformProcessorImpl.java:497)
        at org.apache.ignite.internal.processors.platform.callback.PlatformCallbackUtils.inLongLongLongObjectOutLong(Native Method)
        at org.apache.ignite.internal.processors.platform.callback.PlatformCallbackGateway.dataStreamerStreamReceiverInvoke(PlatformCallbackGateway.java:464)
        at org.apache.ignite.internal.processors.platform.datastreamer.PlatformStreamReceiverImpl.receive(PlatformStreamReceiverImpl.java:100)
        at org.apache.ignite.internal.processors.datastreamer.DataStreamerUpdateJob.call(DataStreamerUpdateJob.java:137)
        at org.apache.ignite.internal.processors.datastreamer.DataStreamProcessor.localUpdate(DataStreamProcessor.java:382)
        at org.apache.ignite.internal.processors.datastreamer.DataStreamProcessor.processRequest(DataStreamProcessor.java:301)
        at org.apache.ignite.internal.processors.datastreamer.DataStreamProcessor.access[=13=]0(DataStreamProcessor.java:58)
        at org.apache.ignite.internal.processors.datastreamer.DataStreamProcessor.onMessage(DataStreamProcessor.java:88)
        at org.apache.ignite.internal.managers.communication.GridIoManager.invokeListener(GridIoManager.java:1257)
        at org.apache.ignite.internal.managers.communication.GridIoManager.processRegularMessage0(GridIoManager.java:885)
        at org.apache.ignite.internal.managers.communication.GridIoManager.access00(GridIoManager.java:114)
        at org.apache.ignite.internal.managers.communication.GridIoManager.run(GridIoManager.java:802)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:748)

typeId=113114 用于 Row class 名称。看起来你在 RowStreamReceiver 的某个地方尝试反序列化这样一个对象,但是找不到 class。

能否将调试器附加到服务器节点并查看抛出异常的位置?

"Unknown pair"问题是由于未正确使用GetDataStreamer引起的。我的缓存最初是这样创建的:

ignite.GetOrCreateCache<string, object>(cacheConfig)

所以在获取 DataStreamer 时,我需要使用相同的类型,然后使用 KeepWithBinary

var ds = m_ignite.GetDataStreamer<string, object>(CacheName).KeepWithBinary<string, IBinaryObject>()