-
Notifications
You must be signed in to change notification settings - Fork 826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve field removal in CompatibleFieldSerializer #291
Comments
Can you submit the patch as a PR so it is more easily considered and merged? On Tue, Mar 10, 2015 at 3:45 PM, solf notifications@github.com wrote:
|
Not easily, no. I'm not familiar with the term & what it entails. The diff I've provided is pretty trivial (basically CompatibleFieldSerializer is changed + one field in CachedField). If this is truly a problem for some reason, I'll see if I can do PR (whatever that means). Oh, and I think I forgot to mention -- this is patch for 2.4.0 release. |
PR stands for pull request, you can read about this here: Cheers,
|
Well, I tried to create PR today, but I only have very limited GIT knowledge and trying to guess what I'm supposed to do, this is what I ended up with trying to push the branch I've created locally: Am I supposed to first create the branch using the web interface or what? |
You have to fork kryo and add your fork as remote to your git repo. This
|
Thanks for the pointers. Btw, I've added another patch (on top of the first patch) -- it is intended to throw exception on missing field definitions -- this is because of otherwise there's real risk of incorrect de-serialization: https://copy.com/hk1YcLDhxqfMaylJ On the subject of PR -- I could spent a couple more hours and hopefully figure it out... but would there be any point to it? Applying both patches linked here takes about 30 seconds (I checked :P) so I'm not sure what would I achieve by spending time on PR. |
Is there a timeline for resolving this issue of removed fields with |
Based on discussion in #286 it doesn't like the devs see at as an actual problem for some reason. If you are interested, you can try the patches I've created above and perhaps make a PR out of them -- perhaps that'll get the things moving. For myself, I've just patched the version I'm using and I don't much care about arguing with devs whether this needs to be integrated :) P.S. In case it is relevant -- I grant the rights to anyone to use the patches I've proposed above for any and all purpose with no strings attached. No any kind of warranty though. |
I tried to get around this issue by disabling references, only to be met with |
Hi, all. 'Cause I have same issue when we are using Kryo CompatibleFieldSerializer to handle the serialization between memcached data and java bean, I tried to make some patch for it. I've tried many things and it seems I've made one working code. This class is extending CompatibleFieldSerializer and overriding read(). Even thought I've fixed the bug about IndexOutOfBoundsException in CompatibleFieldSerializer#read(), I've found that mapping the value from Input to Field fails because of wrong chunk reading calculation. And DummyCachedField is the trick to cover such a failure. Simple case it was but, different from the javadoc on CompatibleFieldSerializer, this code seems to be working with Kryo.setReference(true) option. I hope this class can be helpful. public static class FieldMappingCompatibleSerializer extends CompatibleFieldSerializer {
} Kryo setting Kryo kryo = new Kryo(); Thanks. |
@diaimm Please submit it as a pull request so that we can use the usual tools to discuss it. A test case would also be great. |
OK, I will. Thanks for your response.
https://github.com/EsotericSoftware/kryo/pull/437/files Thanks. |
@diaimm I tried your FieldMappingCompatibleSerializer. I create a class with two fields x and y. They are all int array(int[]). Then, I create an instance of the class called p, set x a value and setY(p.getX()). I write p to a file by kryo. Then I removed field x and read the file by kryo , I get an Exception. Exception in thread "main" com.esotericsoftware.kryo.KryoException: Buffer underflow. |
OK, cuihz, I'll try to figure out the cause and fix it. Thanks for your report. Hi, cuih. Actually I'm a very newbie about Kryo who has met this problem and tried to solve it from just few days ago. Anyway, I've looked into the codes of Kryo, and there were some classes I really cannot sure of what they are really doing, and they are Input and Output. But in my guess, they are controlling InputStream/OutputStream to serialize/deserialize the classes(instances). This means, too awful to me, that during deserialization, if old primitive related fields are missed, there is no way to calculate the bytes. Is there anyone who can make me sure of my assumption? |
To summarize: CompatibleFieldSerializer fails to deserialize if field B is a reference to field A, and then field A is removed. The reason why: field A bytes are skipped but not interpreted because Kryo doesn't know what type the bytes represent. @diaimm's PR doesn't seem to work and he disappeared. @solf's copy.com links unfortunately no longer exist. It's too bad we didn't have time to work on this sooner, and the code wasn't submitted via Git. The approach is interesting, though a little odd and unfortunately manual. An automatic approach would be best. Since CompatibleFieldSerializer is already sacrificing size for compatibility, we could write the concrete type before every field. This allows us to deserialize a field's data even if that field is removed. We can't write the types along with the names the first time the type is encountered because we need to support polymorphism. Writing the field value types could also allow chunked encoding to be optional. When disabled, performance is obviously much better and fields can be added/removed, but classes cannot be removed. |
Not sure if this is still relevant after your commit -- the commit is big, can't say off-hand what it does -- but here's the latest version of my patch: https://yadi.sk/d/-2dGdQYF3XZwX8 It is still against kryo-2.24.0 source code: https://github.com/EsotericSoftware/kryo/archive/kryo-2.24.0.zip Can be applied by: patch -p0 < kryo.diff In addition to original fixes it also contains CompatibleFieldSerializerWithSameNameFieldSupport which has 'limited support for same-name fields (specifically only top-most in class hierarchy field is used)' I can't really speak to the quality/performance of this code, I was mostly focused on 'get it to work now so I can deploy/fix code in the prod'. |
This is an extension of #286
Please improve removed field handling in CompatibleFieldSerializer so that it is actually possible to remove fields (rather than having to keep them indefinitely for backward compatibility).
Consider the patch I've come up with: https://copy.com/akbTt9twsSr2CNqU
And second patch to force exception on missing fields (avoids risk on incorrect de-serialization; must be applied after patch above): https://copy.com/hk1YcLDhxqfMaylJ
This does two things:
If there are no actual obsolete fields in the data being de-serialized, then the performance hit is minimal.
For testing/demonstration:
The text was updated successfully, but these errors were encountered: