Skip to content

Commit a55ca71

Browse files
committed
bugfix: History- ordinal mapper expandAndRehashTable could hash keys to wrong locations making them unsearchable
1 parent 8766413 commit a55ca71

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

hollow/src/main/java/com/netflix/hollow/tools/history/keyindex/HollowOrdinalMapper.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@
1616
*/
1717
package com.netflix.hollow.tools.history.keyindex;
1818

19+
import static com.netflix.hollow.core.HollowConstants.ORDINAL_NONE;
20+
1921
import com.netflix.hollow.core.index.key.PrimaryKey;
2022
import com.netflix.hollow.core.memory.encoding.HashCodes;
2123
import com.netflix.hollow.core.read.HollowReadFieldUtils;
2224
import com.netflix.hollow.core.read.engine.object.HollowObjectTypeReadState;
2325
import com.netflix.hollow.core.schema.HollowObjectSchema;
26+
import com.netflix.hollow.core.schema.HollowObjectSchema.FieldType;
2427
import com.netflix.hollow.core.util.IntList;
2528
import com.netflix.hollow.tools.util.ObjectInternPool;
26-
import com.netflix.hollow.core.schema.HollowObjectSchema.FieldType;
27-
28-
import static com.netflix.hollow.core.HollowConstants.ORDINAL_NONE;
29-
3029
import java.util.Arrays;
3130

3231
public class HollowOrdinalMapper {
@@ -218,14 +217,17 @@ private void expandAndRehashTable() {
218217
if(ordinalList==null || ordinalList.size()==0)
219218
continue;
220219

221-
// Recompute original hash, based on the fact that all objects in this IntList have the same hash
222-
223-
Object originalFieldObject = getFieldObject(ordinalList.get(0), fieldIdx, keyFieldTypes[fieldIdx]);
224-
225-
int originalHash = hashObject(originalFieldObject);
226-
int newIndex = indexFromHash(originalHash, newTable.length);
227-
228-
newFieldHashToOrdinal[fieldIdx][newIndex]=ordinalList;
220+
// Recompute original hash, objects in the IntList don't necessarily share the same hash (see indexFromHash)
221+
for (int i=0;i<ordinalList.size();i++) {
222+
int ordinal = ordinalList.get(i);
223+
Object originalFieldObject = getFieldObject(ordinal, fieldIdx, keyFieldTypes[fieldIdx]);
224+
int originalHash = hashObject(originalFieldObject);
225+
int newIndex = indexFromHash(originalHash, newTable.length);
226+
if (newFieldHashToOrdinal[fieldIdx][newIndex] == null) {
227+
newFieldHashToOrdinal[fieldIdx][newIndex] = new IntList();
228+
}
229+
newFieldHashToOrdinal[fieldIdx][newIndex].add(ordinal);
230+
}
229231
}
230232
}
231233

0 commit comments

Comments
 (0)