Skip to content

Commit 1cd1465

Browse files
Hash ids for modular distributed compiled mode metadata (#1203)
* Use base 32 encoding for distributed metadata id hashing * Hash ids for modular distributed metadata
1 parent 2b238ef commit 1cd1465

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/serialization/binary/DistributedBinaryGraphDeserializer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,12 @@ public RichIterable<String> getClassifierInstanceIds(String classifierId)
468468
return (classifierIndex == null) ? Lists.immutable.empty() : classifierIndex.getInstanceIds();
469469
}
470470

471+
@Override
472+
public String processId(String id)
473+
{
474+
return (this.metadataName == null) ? id : super.processId(id);
475+
}
476+
471477
@Override
472478
public String processEnumId(String enumerationName, String enumName)
473479
{

legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/serialization/binary/DistributedBinaryGraphSerializer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected DistributedBinaryGraphSerializer(PureRuntime runtime, DistributedMetad
5454
this.metadataSpecification = metadataSpecification;
5555
this.runtime = runtime;
5656
this.processorSupport = runtime.getProcessorSupport();
57-
this.idBuilder = DistributedMetadataHelper.possiblyHashIds(newIdBuilder(this.metadataSpecification, this.processorSupport));
57+
this.idBuilder = newPossiblyHashedIdBuilder(this.metadataSpecification, this.processorSupport);
5858
this.classifierCaches = new GraphSerializer.ClassifierCaches(this.processorSupport);
5959
}
6060

@@ -302,6 +302,12 @@ private static IdBuilder newIdBuilder_internal(String metadataName, ProcessorSup
302302
.build();
303303
}
304304

305+
private static IdBuilder newPossiblyHashedIdBuilder(DistributedMetadataSpecification metadataSpec, ProcessorSupport processorSupport)
306+
{
307+
IdBuilder idBuilder = newIdBuilder(metadataSpec, processorSupport);
308+
return (metadataSpec == null) ? idBuilder : DistributedMetadataHelper.possiblyHashIds(idBuilder);
309+
}
310+
305311
protected class SerializationCollector
306312
{
307313
private final MutableMap<String, MutableList<CoreInstance>> instancesForSerialization = Maps.mutable.empty();

legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/serialization/binary/DistributedMetadataHelper.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@
1818
import org.finos.legend.pure.m4.coreinstance.CoreInstance;
1919
import org.finos.legend.pure.runtime.java.compiled.generation.processors.IdBuilder;
2020

21-
import java.nio.ByteBuffer;
22-
import java.util.Base64;
2321
import java.util.Objects;
2422

2523
public class DistributedMetadataHelper
2624
{
27-
private static final boolean HASH_IDS = Boolean.parseBoolean(System.getProperty("legend.pure.runtime.java.compiled.serialization.binary.distributed.hashids", "false"));
25+
private static final boolean HASH_IDS = Boolean.parseBoolean(System.getProperty("legend.pure.runtime.java.compiled.serialization.binary.distributed.hashids", "true"));
2826

2927
private static final String META_DATA_DIRNAME = "metadata/";
3028
private static final String SPECS_DIRNAME = META_DATA_DIRNAME + "specs/";
@@ -209,10 +207,8 @@ public static String hashId(String id)
209207
hash = SpreadFunctions.longSpreadOne(hash) + (codePoint = id.codePointAt(i));
210208
}
211209

212-
// convert to base64 string
213-
byte[] bytes = new byte[8];
214-
ByteBuffer.wrap(bytes).putLong(hash);
215-
return Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);
210+
// convert to base 32 string
211+
return Long.toUnsignedString(hash, 32);
216212
}
217213

218214
public static IdBuilder hashIds(IdBuilder idBuilder)

legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/test/java/org/finos/legend/pure/runtime/java/compiled/runtime/serialization/binary/TestDistributedBinaryGraphSerialization.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void testModularSerialization() throws IOException
7878
PureRuntime runtime = buildRuntime(repo);
7979

8080
DistributedBinaryGraphSerializer.newSerializer(runtime, repo).serialize(getFileWriter());
81-
ListIterable<Obj> expectedObjs = getExpectedObjsFromRuntime(runtime, IdBuilder.builder(runtime.getProcessorSupport()).withDefaultIdPrefix(DistributedMetadataHelper.getMetadataIdPrefix(repo)).build());
81+
ListIterable<Obj> expectedObjs = getExpectedObjsFromRuntime(runtime, DistributedMetadataHelper.possiblyHashIds(IdBuilder.builder(runtime.getProcessorSupport()).withDefaultIdPrefix(DistributedMetadataHelper.getMetadataIdPrefix(repo)).build()));
8282
testSerialization(expectedObjs, Lists.immutable.with(repo), false);
8383
}
8484

0 commit comments

Comments
 (0)