Skip to content

Commit ba749f0

Browse files
authored
CNDB-18111 fixes names in LongArray to be agnostic in 5.0 (#2512)
While `LongArray` is an utility for indexing long values, and it and its implementations are agnostic to the usage, names of methods and variables are named according to the usage, e.g., containing token and rowId. This fixes the names to be agnostic by only using Value/TargetValue and Index instead of Token and RowId.
1 parent 871afcc commit ba749f0

9 files changed

Lines changed: 36 additions & 34 deletions

File tree

src/java/org/apache/cassandra/index/sai/disk/v1/LongArray.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,22 @@ public interface LongArray extends Closeable
3939

4040

4141
/**
42-
* @param targetToken Token to look up. Must not be smaller than previous value queried
42+
* @param targetValue Value to look up. Must not be smaller than previous value queried
4343
* (the method is stateful)
44-
* @return The row ID of the first token equal to or greater than the target,
45-
* or negative value if target token is greater than all tokens
44+
* @return The index of the first value equal to or greater than the target,
45+
* or negative value if target value is greater than all values
4646
*/
47-
long ceilingRowId(long targetToken);
47+
long ceilingIndex(long targetValue);
4848

4949
/**
50-
* Using the given value returns the first index corresponding to the value.
50+
* Using the target value returns the first index corresponding to the value.
5151
*
52-
* @param value Value to lookup, and it must not be smaller than previous value
53-
* @return The index of the given value or negative value if target value is greater than all values
52+
* @param targetValue Value to lookup, and it must not be smaller than previous value
53+
* @return The index of the target value,
54+
* or negative index for a bigger value closest to the target,
55+
* or Long.MIN_VALUE if target value is greater than all values
5456
*/
55-
long indexOf(long value);
57+
long indexOf(long targetValue);
5658

5759
@Override
5860
default void close() throws IOException { }
@@ -84,17 +86,17 @@ public long length()
8486
}
8587

8688
@Override
87-
public long ceilingRowId(long targetToken)
89+
public long ceilingIndex(long targetValue)
8890
{
8991
open();
90-
return longArray.ceilingRowId(targetToken);
92+
return longArray.ceilingIndex(targetValue);
9193
}
9294

9395
@Override
94-
public long indexOf(long targetToken)
96+
public long indexOf(long targetValue)
9597
{
9698
open();
97-
return longArray.indexOf(targetToken);
99+
return longArray.indexOf(targetValue);
98100
}
99101

100102
@Override

src/java/org/apache/cassandra/index/sai/disk/v1/PartitionAwarePrimaryKeyMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public long exactRowIdOrInvertedCeiling(PrimaryKey key)
179179
@Override
180180
public long ceiling(PrimaryKey key)
181181
{
182-
return rowIdToToken.ceilingRowId(key.token().getLongValue());
182+
return rowIdToToken.ceilingIndex(key.token().getLongValue());
183183
}
184184

185185
@Override

src/java/org/apache/cassandra/index/sai/disk/v1/bitpack/AbstractBlockPackedReader.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ private LongValues getReader(int block)
7878
}
7979

8080
@Override
81-
public long ceilingRowId(long targetValue)
81+
public long ceilingIndex(long targetValue)
8282
{
8383
// already out of range
8484
if (isOutOfRangeState())
8585
return -1;
8686

87-
long rowId = findBlockRowId(targetValue);
88-
lastIndex = rowId >= 0 ? rowId : -rowId - 1;
87+
long index = findBlockIndex(targetValue);
88+
lastIndex = index >= 0 ? index : -index - 1;
8989
return isOutOfRangeState() ? -1 : lastIndex;
9090
}
9191

@@ -96,17 +96,17 @@ public long indexOf(long targetValue)
9696
if (isOutOfRangeState())
9797
return Long.MIN_VALUE;
9898

99-
long rowId = findBlockRowId(targetValue);
100-
lastIndex = rowId >= 0 ? rowId : -rowId - 1;
101-
return isOutOfRangeState() ? Long.MIN_VALUE : rowId;
99+
long index = findBlockIndex(targetValue);
100+
lastIndex = index >= 0 ? index : -index - 1;
101+
return isOutOfRangeState() ? Long.MIN_VALUE : index;
102102
}
103103

104104
private boolean isOutOfRangeState()
105105
{
106106
return lastIndex >= valueCount;
107107
}
108108

109-
private long findBlockRowId(long targetValue)
109+
private long findBlockIndex(long targetValue)
110110
{
111111
// We keep track previous returned value in lastIndex, so searching backward will not return correct result.
112112
// Also it's logically wrong to search backward during token iteration in PostingListKeyRangeIterator.
@@ -136,7 +136,7 @@ private long findBlockRowId(long targetValue)
136136
}
137137

138138
// Find the global (not block-specific) index of the target token, which is equivalent to its row ID:
139-
return findBlockRowID(targetValue, blockIndex, exactMatch);
139+
return findBlockIndex(targetValue, blockIndex, exactMatch);
140140
}
141141

142142
/**
@@ -206,7 +206,7 @@ else if (midVal > targetValue)
206206
return -low; // no exact match found
207207
}
208208

209-
private long findBlockRowID(long targetValue, long blockIdx, boolean exactMatch)
209+
private long findBlockIndex(long targetValue, long blockIdx, boolean exactMatch)
210210
{
211211
// Calculate the global offset for the selected block:
212212
long offset = blockIdx << blockShift;

src/java/org/apache/cassandra/index/sai/disk/v1/bitpack/MonotonicBlockPackedReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ protected long blockOffsetAt(int block)
106106
}
107107

108108
@Override
109-
public long ceilingRowId(long targetValue)
109+
public long ceilingIndex(long targetValue)
110110
{
111111
throw new UnsupportedOperationException();
112112
}
113113

114114
@Override
115-
public long indexOf(long targetToken)
115+
public long indexOf(long targetValue)
116116
{
117117
throw new UnsupportedOperationException();
118118
}

src/java/org/apache/cassandra/index/sai/disk/v1/postings/PostingsReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ private LongArrayReader(RandomAccessInput input, LongValues reader, int length)
203203
}
204204

205205
@Override
206-
public long ceilingRowId(long value)
206+
public long ceilingIndex(long targetValue)
207207
{
208208
throw new UnsupportedOperationException();
209209
}
210210

211211
@Override
212-
public long indexOf(long targetToken)
212+
public long indexOf(long targetValue)
213213
{
214214
throw new UnsupportedOperationException();
215215
}

test/microbench/org/apache/cassandra/test/microbench/index/sai/v1/BlockPackedReaderBench.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void findTokenRowID(Blackhole bh)
107107
{
108108
for (int i = 0; i < tokenValues.length;)
109109
{
110-
bh.consume(rowIdToToken.ceilingRowId(tokenValues[i]));
110+
bh.consume(rowIdToToken.ceilingIndex(tokenValues[i]));
111111
i++;
112112
}
113113
}

test/microbench/org/apache/cassandra/test/microbench/index/sai/v1/PostingsReaderBench.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void skipAndRequestNext(Blackhole bh) throws Throwable
9797
{
9898
long token = tokenValues[i];
9999
if (rowId < 0)
100-
rowId = (int) rowIdToToken.ceilingRowId(token);
100+
rowId = (int) rowIdToToken.ceilingIndex(token);
101101
bh.consume(reader.advance(rowId));
102102
rowId = -1;
103103

test/microbench/org/apache/cassandra/test/microbench/index/sai/v2/sortedbytes/SortedTermsBench.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public void longArrayFindTokenRowID(Blackhole bh)
281281
{
282282
for (int i = 0; i < NUM_INVOCATIONS; i++)
283283
{
284-
bh.consume(rowIdToToken.ceilingRowId(tokenValues[i * skippingDistance]));
284+
bh.consume(rowIdToToken.ceilingIndex(tokenValues[i * skippingDistance]));
285285
}
286286
}
287287
}

test/unit/org/apache/cassandra/index/sai/disk/v1/bitpack/NumericValuesTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ public void testTokenFind() throws Exception
107107

108108
for (int x = 0; x < array.length; x++)
109109
{
110-
long rowId = reader.ceilingRowId(array[x]);
110+
long rowId = reader.ceilingIndex(array[x]);
111111
assertEquals("rowID=" + x + " token=" + array[x], x, rowId);
112-
assertEquals(rowId, reader.ceilingRowId(array[x]));
112+
assertEquals(rowId, reader.ceilingIndex(array[x]));
113113
}
114114
}
115115

@@ -121,9 +121,9 @@ public void testTokenFind() throws Exception
121121

122122
for (int x = 0; x < array.length; x++)
123123
{
124-
long rowId = reader.ceilingRowId(array[x] - 1);
124+
long rowId = reader.ceilingIndex(array[x] - 1);
125125
assertEquals("rowID=" + x + " matched token=" + array[x] + " target token="+(array[x] - 1), x, rowId);
126-
assertEquals(rowId, reader.ceilingRowId(array[x] - 1));
126+
assertEquals(rowId, reader.ceilingIndex(array[x] - 1));
127127
}
128128
}
129129
}
@@ -143,7 +143,7 @@ private void testRepeatedNumericValuesFindTokenRowID() throws Exception
143143
{
144144
for (int x = 0; x < length; x++)
145145
{
146-
long rowID = reader.ceilingRowId(1000L);
146+
long rowID = reader.ceilingIndex(1000L);
147147

148148
assertEquals(0, rowID);
149149
}

0 commit comments

Comments
 (0)