Changing Java enums with PDX in VMware GemFire
search cancel

Changing Java enums with PDX in VMware GemFire

book

Article ID: 294044

calendar_today

Updated On:

Products

VMware Tanzu Gemfire

Issue/Introduction

Let's consider the following scenario:

The enum previously used was myEnum{A, D, C} which is then changed to myEnum{A, B, C, D}.

When doing the above described enum change, a PDX issue due to a non backward compatible change in the PDX registry arises. After changing the enum and starting to write entries with the new myEnum{A, B, C, D} the client will throw the following exception:
'ordinal cannot change while writing enum entry "D"'


We tried the following workaround:

The disk stores on the servers were removed and the data was reloaded. Data loaded correctly from the external source and initial tests shows all reads are working fine. That is until a GemFire client that was not restarted started to write data and was still using the old myEnum{A, D, C}. Then, while reading data from GemFire, the clients started throwing PDX exceptions again because the old PDX reference was not present on the servers since all PDX references were removed by removing the disk stores.

Resolution

If you would like to use enums and GemFire provided serialization and would like to change the order in which the enums are encoded, you need to perform an ETL job and update your data to be inline with the new business value(s) for the ordinal data. Enums cannot be changed programmatically by any API's so the change cannot be done while data stays in the cache. If you make changes to an enum, you will need to do an ETL job to export data, transform it, and load it back into GemFire.

An important thing is to make sure to clear the clients' PDX registry with the system property
--Dgemfire.ON_DISCONNECT_CLEAR_PDXTYPEIDS=true to avoid the clients using stale PDX data after the ETL has been done.