Skip to content

Commit 42d1816

Browse files
committed
Fix avro upgrader
1 parent 961032b commit 42d1816

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

storage/kafkasql/src/main/java/io/apicurio/registry/storage/impl/kafkasql/KafkaSqlAvroCanonicalizerUpgrader.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import io.apicurio.registry.types.provider.DefaultArtifactTypeUtilProviderImpl;
3232
import io.apicurio.registry.utils.impexp.ContentEntity;
3333
import jakarta.enterprise.context.ApplicationScoped;
34+
import jakarta.enterprise.context.control.ActivateRequestContext;
3435
import jakarta.inject.Inject;
3536
import org.apache.commons.codec.digest.DigestUtils;
3637
import org.slf4j.Logger;
@@ -63,6 +64,8 @@ public void upgrade(Handle dbHandle) throws Exception {
6364

6465
@Override
6566
public void upgrade(RegistryStorage registryStorage, Handle dbHandle) throws Exception {
67+
this.storage = registryStorage;
68+
6669
String sql = "SELECT c.contentId, c.content, c.canonicalHash, c.contentHash, c.artifactreferences, v.tenantId "
6770
+ "FROM versions v "
6871
+ "JOIN content c on c.contentId = v.contentId "
@@ -79,15 +82,20 @@ public void upgrade(RegistryStorage registryStorage, Handle dbHandle) throws Exc
7982
}
8083
}
8184

85+
@ActivateRequestContext
8286
protected void updateCanonicalHash(TenantContentEntity contentEntity) {
8387
try {
8488

8589
String canonicalContentHash;
90+
byte[] contentBytes = this.canonicalizeContent(contentEntity.contentEntity, ArtifactType.AVRO).bytes();
91+
92+
logger.debug("Processing content {}", contentEntity.toString());
93+
8694
if (contentEntity.contentEntity.serializedReferences != null) {
8795
byte[] referencesBytes = contentEntity.contentEntity.serializedReferences.getBytes(StandardCharsets.UTF_8);
88-
canonicalContentHash = DigestUtils.sha256Hex(concatContentAndReferences(this.canonicalizeContent(contentEntity.contentEntity, ArtifactType.AVRO).bytes(), referencesBytes));
96+
canonicalContentHash = DigestUtils.sha256Hex(concatContentAndReferences(contentBytes, referencesBytes));
8997
} else {
90-
canonicalContentHash = DigestUtils.sha256Hex(this.canonicalizeContent(contentEntity.contentEntity, contentEntity.contentEntity.artifactType).bytes());
98+
canonicalContentHash = DigestUtils.sha256Hex(contentBytes);
9199
}
92100

93101
if (canonicalContentHash.equals(contentEntity.contentEntity.canonicalHash)) {

0 commit comments

Comments
 (0)