【发布时间】:2020-07-05 17:26:10
【问题描述】:
大家好,我遇到了问题,我在 .NET 核心中使用一组 Apache Ignite (2.8.1) 服务器节点来创建数据网格并通过 Apache ignite java 客户端对网格运行查询。我完全没有问题以二进制模式将数据写入网格并通过提供的思考层询问查询。我使用 DBeaver 运行查询,一切正常。当我尝试从抱怨缓存冲突“:缓存 MY_CAHE 的配置合并期间的冲突”的 Java 客户端查询数据时,问题出现了。找到下面的错误信息:
Caused by: class org.apache.ignite.spi.IgniteSpiException: Conflicts during configuration merge for cache 'DOTNET_BINARY_CACHE' :
TRADE conflict:
keyType is different: local=Apache.Ignite.Core.Cache.Affinity.AffinityKey, received=org.apache.ignite.cache.affinity.AffinityKey
valType is different: local=Servicing.Agent4.Service.Implementation.Misc.Ignite.Trade, received=Servicing.Agent4.Core.Java.Models.Trade
在下面找到我在 .NET 和 Java 中的实现:
public static class IgniteUtils
{
const string CACHE_NAME = "DOTNET_BINARY_CACHE";
public static IgniteConfiguration DefaultIgniteConfig()
{
return new IgniteConfiguration
{
BinaryConfiguration = new BinaryConfiguration
{
NameMapper = new BinaryBasicNameMapper { IsSimpleName = true },
CompactFooter = true,
TypeConfigurations = new[] {
new BinaryTypeConfiguration(typeof(Trade)) {
Serializer = new IgniteTradeSerializer()
}
}
},
// omit jvm and network options
IncludedEventTypes = EventType.All,
Logger = new IgniteNLogLogger(),
CacheConfiguration = new[]{
new CacheConfiguration{
Name = CACHE_NAME,
CacheMode = CacheMode.Partitioned,
Backups = 0,
QueryEntities = new[] { new QueryEntity(typeof(AffinityKey), typeof(Trade))}
}
}
};
}
}
Apache Ignite 的设置发生在课堂上:
public class IgniteService
{
public void Start()
{
IIgnite _ignite = Ignition.Start(IgniteUtils.DefaultIgniteConfig());
// Create new cache and configure queries for Trade binary types.
// Note that there are no such classes defined.
var cache0 = _ignite.GetOrCreateCache<AffinityKey, Trade>("DOTNET_BINARY_CACHE");
// Switch to binary mode to work with data in serialized form.
var cache = cache0.WithKeepBinary<AffinityKey, IBinaryObject>();
// Clean up caches on all nodes before run.
cache.Clear();
// Populate cache with sample data entries.
IBinary binary = cache.Ignite.GetBinary();
cache[new AffinityKey(1, 1)] = binary.GetBuilder("TRADE")
.SetField("Symbol", "James Wilson")
.SetField("Id", 1)
.SetField("Login", 123)
.SetField("SourceId", 1)
.Build();
}
域类如下:
public class Trade
{
[QuerySqlField(IsIndexed = true)]
public int Id { set; get; }
[QueryTextField]
public string Symbol { set; get; }
[QuerySqlField]
public int Login { set; get; }
[QuerySqlField(IsIndexed = true)]
public int SourceId { get; set; }
//omit constructor
}
Java 客户端代码
public class IgniteScheduler {
final String CACHE_NAME = "DOTNET_BINARY_CACHE";
@PostConstruct
public void start() {
IgniteConfiguration cfg = new IgniteConfiguration();
// Enable client mode.
cfg.setClientMode(true);
CacheConfiguration<AffinityKey<Integer>, Trade> cacheCfg = new CacheConfiguration<>();
cacheCfg.setName(CACHE_NAME);
cacheCfg.setCacheMode(CacheMode.PARTITIONED);
cacheCfg.setBackups(0);
cacheCfg.setQueryEntities(Arrays.asList(new QueryEntity(AffinityKey.class, Trade.class)));
// Setting up an IP Finder to ensure the client can locate the servers.
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
ipFinder.setAddresses(Collections.singletonList("127.0.0.1:47500..47509"));
cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder));
cfg.setCacheConfiguration(cacheCfg);
// Configure Ignite to connect with .NET nodes
cfg.setBinaryConfiguration(new BinaryConfiguration()
.setNameMapper(new BinaryBasicNameMapper(true))
.setCompactFooter(true)
BinaryTypeConfiguration(Trade.class.getSimpleName())))
);
// Start Ignite in client mode.
Ignite ignite = Ignition.start(cfg);
// omit functional code
}
域类如下:
@Data
public class Trade implements Serializable {
@QuerySqlField(index = true)
public int Id;
@QueryTextField
public String Symbol;
@QuerySqlField
public int Login;
//@AffinityKeyMapped does not work as well
@QuerySqlField(index = true)
public int SourceId;
// omit constructor
}
调试信息
- 操作系统:Windows 10 10.0 amd64
- VM 信息:Java(TM) SE Runtime Environment 11.0.5+10-LTS Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 11.0.5+10-LTS
- Apache Ignite 2.8.1 版本
【问题讨论】:
-
我可以看到 .NET 类 Trade 有两个不同的包:local=Servicing.Agent4.Service.Implementation.Misc.Ignite.Trade received=Servicing.Agent4.Core.Java.Models。贸易 这两者有什么区别?
-
一个用于Java,另一个用于.NET,它是数据库的域。