@ SneakyThrows ( ConditionalTableUpdateException . class ) private void validateConditionalUpdate ( List < TableKeyBatch . Item > items , Map < UUID , Long > bucketOffsets , String segmentName ) { val badKeyVersions = new HashMap < TableKey , Long > ( ) ; // Key = Key that failed, Value = Key's bucket offset. for ( val item : items ) { // Validate compareVersion. TableKey key = item . getKey ( ) ; Long bucketOffset = bucketOffsets . get ( item . getHash ( ) ) ; assert key . hasVersion ( ) : "validateConditionalUpdate for TableKey with no compare version" ; if ( bucketOffset == TableKey . NOT_EXISTS ) { if ( key . getVersion ( ) != TableKey . NOT_EXISTS ) { // Key does not exist, but the conditional update provided a specific version. throw new KeyNotExistsException ( segmentName , key . getKey ( ) ) ; } } else if ( bucketOffset != key . getVersion ( ) ) { // Key does exist, but has the wrong version. badKeyVersions . put ( key , bucketOffset ) ; } } if ( ! badKeyVersions . isEmpty ( ) ) { // Throw the bad key version in bulk - helps speed verification. throw new BadKeyVersionException ( segmentName , badKeyVersions ) ; } // All validations for all items passed. }
Validates a list of UpdateBatchItems against their actual Table Bucket offsets .