英文:
How to load updated java class on a existing Ignite cluster?
问题
我有一个包含2个或更多节点(最多4个)的Ignite集群,以服务器模式运行。
假设我有一个由Java类Employee定义的Ignite缓存(假设这是版本1),并已加载和使用。如果我更新这个Employee类,添加一个新成员字段(版本2),我该如何更新已加载的类,更新缓存定义呢?Ignite如何处理先前基于Employee版本1创建的对象(缓存记录)与基于Employee版本2创建的新缓存记录?如果我有使用版本2中新定义的字段的SQL查询,是否会失败,因为基于Employee版本1的对象/缓存记录与新SQL中使用的新定义字段不兼容?
我可以从工作目录中删除数据库文件夹,重新加载新类,作为重新启动Ignite服务的一部分。但这会导致丢失所有先前的数据。
具有更新的Employee类定义的集群成员将无法加入仍加载原始Employee版本1类的其他节点。同样,我需要关闭集群中的所有成员,重新加载新的Employee版本,然后重新启动集群中的所有成员。
英文:
I have a Ignite cluster of 2 or more nodes (max of 4) in server mode.
Let's say I have an Ignite cache defined by Java class called Employee (let's say this is version 1) loaded and used. If I update this Employee class with a new member field (version 2), how would I go about updating the loaded class with the new version (ie update the cache definition)? How does Ignite handle objects (cache records) created previously based on Employee version 1 vs new cache records created with Employee version 2? If I have SQL queries using new fields as defined in version 2, is that going to fail because the Employee version 1 based objects/cache records are not compatible with new SQL using the newly defined field(s) in Employee version 2?
I can delete db folder from the working directory, reload the new class as part of restarting the Ignite service. But, I lose all previous data.
Cluster member with updated Employee class definition will not join other nodes in the cluster still loaded with original Employee version 1 class. Again, I need to shutdown all members in the cluster and reload the new Employee version and restart all members in the cluster.
答案1
得分: 1
Ignite不存储代码版本。最新部署的类正在使用。
为了保留字段,Ignite为客户类型构建二进制元数据并将其存储以进行验证。如果您要添加新字段并保留旧字段不变,Ignite将自动更新元数据,无需配置/更改。旧记录将被反序列化,并将新字段设置为null。
对于SQL,建议使用DDL来相应地调整模式:
ALTER TABLE "schema".MyTable DROP COLUMN oldColumn
ALTER TABLE "schema".MyTable ADD COLUMN newColumn VARCHAR;
您可以使用控制脚本--meta命令来检查可用的元数据(尽管不确定是否在Ignite版本中可用):
control.sh --meta list
Ignite不会自动使用peerClassLoading传播POJO更改。您应该手动更新JAR文件或依赖于某些部署SPI,如URL部署。
总的来说,您不应该每次要对POJO或SQL表进行更改时都删除db文件夹。添加新字段应该完全没问题。不要删除旧字段,最好将它们标记为弃用。
英文:
Ignite doesn't store code versions. The latest deployed class is in use.
in order to preserve the fields, Ignite builds binary meta for a customer type and stores it for validation. If you are going to add new fields and leave the old ones untouched, Ignite will update the meta automatically, nothing to configure/change. A old record will be deserialised with new fields set to null.
For SQL it's recommended to go with DDL to adjust the schema accordingly:
ALTER TABLE "schema".MyTable DROP COLUMN oldColumn
ALTER TABLE "schema".MyTable ADD COLUMN newColumn VARCHAR;
You can check available meta using control script --meta command (not sure if it's available in Ignite edition though)
control.sh --meta list
Ignite won't propagate POJO changes automatically using peerClassLoading. You should either update the JARs manually or rely on some deployment SPI, like URL deployment.
Overall, you should not remove your db folder each time you are going to make changes to your POJOs/SQL tables. Adding new fields should be totally OK. Do not remove the old fields, it's better to mark them as deprecated.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论