THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
ID | IEP-97 | ||||||||
Author | Anton Vinogradov | ||||||||
Sponsor | |||||||||
Created |
| ||||||||
Status |
|
...
...
It's not possible to just replace arr with valBytes because, unlike , for example, from CacheObjectImpl arr is not just a mashalled bytes, it's an object's value that is required, for example, to provide hashCode/schemaId/typeId/objectField, and we must keep it as is.
...
Code Block | ||||
---|---|---|---|---|
| ||||
public interface CacheObjectTransformerCacheObjectTransformerManager extends GridCacheSharedManager { /** * Transforms the data. * * @param original Original data. * @return Transformed data (started with {@link GridBinaryMarshaller#TRANSFORMED} when restorable) * or {@code null} when transformation is not possible/suitable. */ public @Nullable ByteBuffer transform(ByteBuffer original); /** * Restores the data. * * @param transformed Transformed data. * @return Restored data. */ public ByteBuffer restore(ByteBuffer transformed); /** * Returns {@code true} when direct byte buffers are required. * * @return Direct flag. */ public boolean direct(); } |
...
Every customer may implement this interface in a proper way if necessary and specify it in the via plugin configuration:
Code Block | ||||
---|---|---|---|---|
| ||||
IgniteConfiguration getConfiguration() { IgniteConfiguration cfg = ... cfg.setCacheObjectTransformersetPluginProviders(new XXXTransformerXXXPluginProvider()); return // Which provides some XXXCacheObjectTransformerManager() return cfg; } |
Code Block | ||||
---|---|---|---|---|
| ||||
class CompressionTransformer extends CacheObjectTransformerAdapter { protected ByteBuffer transform(ByteBuffer original) throws IgniteCheckedException { int locOverheadoverhead = 45; // OriginalTransformed length. flag int totalOverhead = CacheObjectTransformerUtils.OVERHEAD + locOverhead;+ length. int origSize = original.remaining(); int lim = origSize - totalOverheadoverhead; if (lim <= 0) throw new IgniteCheckedException(" return null; // Compression is not profitable."); ByteBuffer compressed = byteBuffer(lim);(overhead + (int)Zstd.compressBound(origSize)); compressed.position(locOverhead);put(TRANSFORMED); compressed.putInt(origSize); int size = Zstd.compress(compressed, original, 1); if (size >= lim) compressed.flip(); compressed.putInt(origSize); return null; // Compression is not profitable. compressed.rewindflip(); return compressed; } protected ByteBuffer restore(ByteBuffer transformed) { ByteBuffer restored = byteBuffer(transformed.getInt()); Zstd.decompress(restored, transformed); restored.flip(); return restored; } } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
class EncryptionTransformer extends CacheObjectTransformerAdapter { private static final int SHIFT = 42; // Secret! protected ByteBuffer transform(ByteBuffer original) throws IgniteCheckedException { ByteBuffer transformed = byteBuffer(original.remaining() + 1); // Same capacity is required. transformed.put(TRANSFORMED); while (original.hasRemaining()) transformed.put((byte)(original.get() + SHIFT)); transformed.flip(); return transformed; } protected ByteBuffer restore(ByteBuffer transformed, int length) { ByteBuffer restored = byteBuffer(transformed.remaining()); // Same size. while (transformed.hasRemaining()) restored.put((byte)(transformed.get() - SHIFT)); restored.flip(); return restored; } } |
...