anton-vinogradov opened a new pull request, #13422:
URL: https://github.com/apache/ignite/pull/13422

   [IGNITE-27606](https://issues.apache.org/jira/browse/IGNITE-27606)
   
   `PartitionUpdateCountersMessage` keeps its counters in one `byte[]`, packed 
by hand as 20-byte items (partition, initial counter, updates count). The 
packing used `GridUnsafe`. This replaces it with byte-array `VarHandle` views.
   
   ### The wire form does not change
   
   The bytes stay the same on every little-endian machine, which is every 
platform Ignite runs on today. The new test `testWireLayoutIsLittleEndian` 
asserts the layout byte by byte, and it passes against the code before this 
change as well.
   
   ### Two problems fixed along the way
   
   **A write past the end of the array.** `ensureSpace` grew the array by a 
factor of 1.33, and that can be less than what was asked for: 1.33 of a 
one-item array is 26 bytes, while two items need 40. `GridUnsafe` does not 
check bounds, so `add` then wrote outside the array and the value was silently 
lost. The new test `testAddPastInitialSize` fails against the old code with 
`expected:<100> but was:<0>`. It never fires in production because both callers 
size the message exactly (`IgniteTxHandler`, `IgniteTxLocalAdapter`), so the 
growth path is never taken. `ensureSpace` now takes `Math.max` of the request 
and the growth.
   
   **The byte order followed the host.** `GridUnsafe.getInt`/`getLong` over a 
`byte[]` use the native order, so a node wrote the counters in its own order 
and the receiver read them in its own. In a cluster with mixed endianness this 
corrupts the counters. The `VarHandle` views pin little-endian, so the wire 
form no longer depends on the architecture.
   
   `VarHandle` also brings bounds checking, which is what turns the first 
problem from a silent bad value into an exception.
   
   ### Checks
   
   * new `PartitionUpdateCountersMessageTest`, 5 cases - green; against the 
code before this change 1 fails (the bug above) and 4 pass (the wire form is 
unchanged);
   * `IgniteCoreMessagesSerializationTest` - green;
   * `GridCachePartitionsUpdateCountersAndSizeTest` - green, 4 of 4;
   * checkstyle with `-Pcheckstyle` - no violations.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to