Skip to content

Commit

Permalink
Fallback to ArrayUtil.oversize if we overflow targets
Browse files Browse the repository at this point in the history
  • Loading branch information
vnickolov committed May 28, 2024
1 parent 5f2dddd commit a9cc6ac
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.Arrays;
import java.util.Locale;
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -190,4 +192,21 @@ void oversizeAlignsToPointerSize() {
// 42 + (42/8) == 47, which gets aligned to 48
assertEquals(48, actual);
}

@ParameterizedTest(name = "{1}")
@MethodSource("bytesPerElement")
void oversizeThrowsOnIntegerMaxValue(int bytesPerElement, String label) {
assertThatIllegalArgumentException().isThrownBy(
() -> ArrayUtil.oversize(Integer.MAX_VALUE, bytesPerElement)
)
.withMessageContaining("requested array size")
.withMessageContaining("exceeds maximum array in java ");
}

private static Stream<Arguments> bytesPerElement() {
return Stream.of(
Arguments.of(Byte.BYTES, "Byte.BYTES"),
Arguments.of(Integer.BYTES, "Integer.BYTES")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ private byte[] ensureCompressedTargetsCapacity(long index, int pos, int required
)
);
} else if (compressedTargets.length <= targetLength) {
int newLength = BitUtil.nextHighestPowerOfTwo(targetLength);
// int newLength = ArrayUtil.oversize(pos + required, Byte.BYTES);
int newLength = getNewLength(targetLength);
compressedTargets = Arrays.copyOf(compressedTargets, newLength);
this.targetLists.set(index, compressedTargets);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
package org.neo4j.gds.core.loading;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.neo4j.gds.core.compression.common.AdjacencyCompression;
import org.neo4j.gds.core.compression.common.ZigZagLongDecoding;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.assertj.core.api.Assertions.fail;
import static org.neo4j.gds.core.compression.common.ZigZagLongDecoding.Identity.INSTANCE;
import static org.neo4j.gds.core.loading.AdjacencyPreAggregation.IGNORE_VALUE;
Expand Down Expand Up @@ -232,4 +235,19 @@ void addWithPreAggregatedWeights() {
assertThat(actualProperties[0]).containsSequence(3L, 3L, 4L);
});
}

@ParameterizedTest
@ValueSource(ints = {
110_000_000_0,
210_000_000_9,
214_000_000_5
})
void shouldComputeNewLength(int minLength) {
assertThatNoException().isThrownBy(
() ->
assertThat(ChunkedAdjacencyLists.getNewLength(minLength))
.isPositive()
.isLessThan(Integer.MAX_VALUE)
);
}
}

0 comments on commit a9cc6ac

Please sign in to comment.