Skip to content

Commit

Permalink
type mapper handling of is numShards pinned
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunjeet committed Jan 19, 2025
1 parent b24c27e commit 7b4d5ea
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ public HollowListTypeWriteState(HollowListSchema schema) {
}

public HollowListTypeWriteState(HollowListSchema schema, int numShards) {
super(schema, numShards);
this(schema, numShards, false);
}

public HollowListTypeWriteState(HollowListSchema schema, int numShards, boolean isNumShardsPinned) {
super(schema, numShards, isNumShardsPinned);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ public class HollowMapTypeWriteState extends HollowTypeWriteState {
public HollowMapTypeWriteState(HollowMapSchema schema) {
this(schema, -1);
}

public HollowMapTypeWriteState(HollowMapSchema schema, int numShards) {
super(schema, numShards);
super(schema, numShards, false);
}

public HollowMapTypeWriteState(HollowMapSchema schema, int numShards, boolean isNumShardsPinned) {
super(schema, numShards, isNumShardsPinned);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package com.netflix.hollow.core.write;

import static com.netflix.hollow.core.index.FieldPaths.FieldPathException.ErrorKind.NOT_BINDABLE;

import com.netflix.hollow.core.index.FieldPaths;
import com.netflix.hollow.core.memory.ByteData;
import com.netflix.hollow.core.memory.ByteDataArray;
Expand All @@ -30,8 +32,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import static com.netflix.hollow.core.index.FieldPaths.FieldPathException.ErrorKind.NOT_BINDABLE;

public class HollowSetTypeWriteState extends HollowTypeWriteState {
private static final Logger LOG = Logger.getLogger(HollowSetTypeWriteState.class.getName());

Expand All @@ -56,9 +56,13 @@ public class HollowSetTypeWriteState extends HollowTypeWriteState {
public HollowSetTypeWriteState(HollowSetSchema schema) {
this(schema, -1);
}

public HollowSetTypeWriteState(HollowSetSchema schema, int numShards) {
super(schema, numShards);
this(schema, numShards, false);
}

public HollowSetTypeWriteState(HollowSetSchema schema, int numShards, boolean isNumShardsPinned) {
super(schema, numShards, isNumShardsPinned);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ public class HollowListTypeMapper extends HollowTypeMapper {

private final HollowTypeMapper elementMapper;

public HollowListTypeMapper(HollowObjectMapper parentMapper, ParameterizedType type, String declaredName, int numShards, boolean ignoreListOrdering, Set<Type> visited) {
public HollowListTypeMapper(HollowObjectMapper parentMapper, ParameterizedType type, String declaredName, int numShards, boolean isNumShardsPinned,
boolean ignoreListOrdering, Set<Type> visited) {
this.elementMapper = parentMapper.getTypeMapper(type.getActualTypeArguments()[0], null, null, -1, visited);
String typeName = declaredName != null ? declaredName : getDefaultTypeName(type);
this.schema = new HollowListSchema(typeName, elementMapper.getTypeName());
this.ignoreListOrdering = ignoreListOrdering;

HollowListTypeWriteState existingTypeState = (HollowListTypeWriteState)parentMapper.getStateEngine().getTypeState(typeName);
this.writeState = existingTypeState != null ? existingTypeState : new HollowListTypeWriteState(schema, numShards);
this.writeState = existingTypeState != null ? existingTypeState : new HollowListTypeWriteState(schema, numShards, isNumShardsPinned);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public class HollowMapTypeMapper extends HollowTypeMapper {
private HollowTypeMapper keyMapper;
private HollowTypeMapper valueMapper;

public HollowMapTypeMapper(HollowObjectMapper parentMapper, ParameterizedType type, String declaredName, String[] hashKeyFieldPaths, int numShards, HollowWriteStateEngine stateEngine, boolean useDefaultHashKeys, Set<Type> visited) {
public HollowMapTypeMapper(HollowObjectMapper parentMapper, ParameterizedType type, String declaredName, String[] hashKeyFieldPaths,
int numShards, boolean isNumShardsPinned, HollowWriteStateEngine stateEngine, boolean useDefaultHashKeys, Set<Type> visited) {
this.keyMapper = parentMapper.getTypeMapper(type.getActualTypeArguments()[0], null, null, -1, visited);
this.valueMapper = parentMapper.getTypeMapper(type.getActualTypeArguments()[1], null, null, -1, visited);
String typeName = declaredName != null ? declaredName : getDefaultTypeName(type);
Expand All @@ -63,7 +64,7 @@ public HollowMapTypeMapper(HollowObjectMapper parentMapper, ParameterizedType ty
this.hashCodeFinder = stateEngine.getHashCodeFinder();

HollowMapTypeWriteState typeState = (HollowMapTypeWriteState) parentMapper.getStateEngine().getTypeState(typeName);
this.writeState = typeState != null ? typeState : new HollowMapTypeWriteState(schema, numShards);
this.writeState = typeState != null ? typeState : new HollowMapTypeWriteState(schema, numShards, isNumShardsPinned);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,16 @@ public void initializeTypeState(Class<?> clazz) {
}

HollowTypeMapper getTypeMapper(Type type, String declaredName, String[] hashKeyFieldPaths) {
return getTypeMapper(type, declaredName, hashKeyFieldPaths, -1, null);
return getTypeMapper(type, declaredName, hashKeyFieldPaths, -1, false, null);
}

HollowTypeMapper getTypeMapper(
Type type, String declaredName, String[] hashKeyFieldPaths, int numShards, Set<Type> visited) {
Type type, String declaredName, String[] hashKeyFieldPaths, int numShards, Set<Type> visited) { // SNAP: refactor all to below usage
return getTypeMapper(type, declaredName, hashKeyFieldPaths, numShards, false, visited);
}

HollowTypeMapper getTypeMapper(
Type type, String declaredName, String[] hashKeyFieldPaths, int numShards, boolean isNumShardsPinned, Set<Type> visited) {

// Compute the type name
String typeName = declaredName != null
Expand All @@ -173,14 +178,14 @@ HollowTypeMapper getTypeMapper(
Class<?> clazz = (Class<?>) parameterizedType.getRawType();

if (List.class.isAssignableFrom(clazz)) {
typeMapper = new HollowListTypeMapper(this, parameterizedType, typeName, numShards,
ignoreListOrdering, visited);
typeMapper = new HollowListTypeMapper(this, parameterizedType, typeName,
numShards, isNumShardsPinned, ignoreListOrdering, visited);
} else if (Set.class.isAssignableFrom(clazz)) {
typeMapper = new HollowSetTypeMapper(this, parameterizedType, typeName, hashKeyFieldPaths,
numShards, stateEngine, useDefaultHashKeys, visited);
numShards, isNumShardsPinned, stateEngine, useDefaultHashKeys, visited);
} else if (Map.class.isAssignableFrom(clazz)) {
typeMapper = new HollowMapTypeMapper(this, parameterizedType, typeName, hashKeyFieldPaths,
numShards, stateEngine, useDefaultHashKeys, visited);
numShards, isNumShardsPinned, stateEngine, useDefaultHashKeys, visited);
} else {
typeMapper = new HollowObjectTypeMapper(this, clazz, typeName, visited);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.netflix.hollow.core.write.HollowTypeWriteState;
import com.netflix.hollow.core.write.HollowWriteRecord;
import com.netflix.hollow.core.write.objectmapper.flatrecords.FlatRecordWriter;
import com.netflix.hollow.core.write.objectmapper.flatrecords.traversal.FlatRecordTraversalNode;
import com.netflix.hollow.core.write.objectmapper.flatrecords.traversal.FlatRecordTraversalObjectNode;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
Expand All @@ -36,9 +38,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.netflix.hollow.core.write.objectmapper.flatrecords.traversal.FlatRecordTraversalNode;
import com.netflix.hollow.core.write.objectmapper.flatrecords.traversal.FlatRecordTraversalObjectNode;
import sun.misc.Unsafe;

@SuppressWarnings("restriction")
Expand Down Expand Up @@ -425,7 +424,8 @@ private MappedField(Field f, Set<Type> visitedTypes) {
subTypeMapper = parentMapper.getTypeMapper(type,
typeNameAnnotation != null ? typeNameAnnotation.name() : null,
hashKeyAnnotation != null ? hashKeyAnnotation.fields() : null,
numShardsAnnotation != null ? numShardsAnnotation.numShards() : -1,
numShardsAnnotation != null ? numShardsAnnotation.numShards() : -1,
isNumShardsPinnedByAnnotation(numShardsAnnotation),
visitedTypes);

// once we've safely returned from a leaf node in recursion, we can remove this MappedField's type
Expand All @@ -435,6 +435,10 @@ private MappedField(Field f, Set<Type> visitedTypes) {
this.subTypeMapper = subTypeMapper;
}

private boolean isNumShardsPinnedByAnnotation(HollowShardLargeType numShardsAnnotation) {
return numShardsAnnotation != null && numShardsAnnotation.numShards() != -1;
}

private MappedField(MappedFieldType specialField) {
this.fieldOffset = -1;
this.type = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public class HollowSetTypeMapper extends HollowTypeMapper {

private final HollowTypeMapper elementMapper;

public HollowSetTypeMapper(HollowObjectMapper parentMapper, ParameterizedType type, String declaredName, String[] hashKeyFieldPaths, int numShards, HollowWriteStateEngine stateEngine, boolean useDefaultHashKeys, Set<Type> visited) {
public HollowSetTypeMapper(HollowObjectMapper parentMapper, ParameterizedType type, String declaredName, String[] hashKeyFieldPaths,
int numShards, boolean isNumShardsPinned, HollowWriteStateEngine stateEngine, boolean useDefaultHashKeys, Set<Type> visited) {
this.elementMapper = parentMapper.getTypeMapper(type.getActualTypeArguments()[0], null, null, -1, visited);
String typeName = declaredName != null ? declaredName : getDefaultTypeName(type);

Expand All @@ -57,7 +58,7 @@ public HollowSetTypeMapper(HollowObjectMapper parentMapper, ParameterizedType ty
this.hashCodeFinder = stateEngine.getHashCodeFinder();

HollowSetTypeWriteState existingTypeState = (HollowSetTypeWriteState) parentMapper.getStateEngine().getTypeState(typeName);
this.writeState = existingTypeState != null ? existingTypeState : new HollowSetTypeWriteState(schema, numShards);
this.writeState = existingTypeState != null ? existingTypeState : new HollowSetTypeWriteState(schema, numShards, isNumShardsPinned);
}

@Override
Expand Down

0 comments on commit 7b4d5ea

Please sign in to comment.