Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slow domain object ingestion #2006

Merged
merged 35 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5ecd9fd
Use UpsertPgCopy logc to speed up performance
Nana-EC May 20, 2021
b640ac4
upsert pgopy tokens and schedules
Nana-EC May 22, 2021
0c73d89
Fix tests
Nana-EC May 24, 2021
99a813b
Fixed up more tests with schedule upsert support
Nana-EC May 25, 2021
fcc5faf
Break up upsert into insert and update
Nana-EC May 25, 2021
4ec33be
Fix all but 1 tests to verify insert and update flow
Nana-EC May 26, 2021
d771e50
Fix some code smells
Nana-EC May 26, 2021
e3ebd8e
Fix up multiEntityUpdate test and removed upsert sql
Nana-EC May 26, 2021
211a0f6
Added basic performance test class
Nana-EC May 26, 2021
09706de
Fix nullable string fields issue
Nana-EC May 27, 2021
bb6ec3f
Fixed some code smells
Nana-EC May 27, 2021
664ae77
Auto generate upsert sql and add custom repositories for updatebale d…
Nana-EC Jun 5, 2021
f777fe2
Implemented separate insert and update for upsert
Nana-EC Jun 7, 2021
4617879
Fixed build issue and removed upsert
Nana-EC Jun 7, 2021
da02f34
Cleaned up a bit more
Nana-EC Jun 7, 2021
67191f2
Addressing initial comments
Nana-EC Jun 10, 2021
aaeddf7
Removed OnEntityId usage
Nana-EC Jun 10, 2021
b339caf
Removed EntityId classes and updated hex key byte array logic
Nana-EC Jun 10, 2021
4382a70
Moved UpdatableDomainRepositoryCustom to UpsertQueryGenerator packages
Nana-EC Jun 10, 2021
d8b49bd
Add migration to v2
Nana-EC Jun 10, 2021
b359efc
Fixed some code smells
Nana-EC Jun 10, 2021
3e6d8f1
Updated NullableStringSerializer check
Nana-EC Jun 10, 2021
7de10c3
Added UpsertPgCopyTest
Nana-EC Jun 11, 2021
b98107a
Adopt sets in UpsertQueryGenerators
Nana-EC Jun 11, 2021
4530084
Add test to ensure all schema fields are captured
Nana-EC Jun 11, 2021
f7bc5dc
Addressed feedback on tablename method
Nana-EC Jun 12, 2021
14ece16
Remove usage of getNewAccountFreezeStatus and getNewAccountKycStatus
Nana-EC Jun 14, 2021
ad70a47
Updated update column selection logic
Nana-EC Jun 14, 2021
db3912a
Simplified interface and abstract class layouts
Nana-EC Jun 14, 2021
d984499
Added freeze and kyc status tests
Nana-EC Jun 15, 2021
7b830f4
Fixed v2 schema tests
Nana-EC Jun 15, 2021
5763a62
Split out v1 and v2 tests
Nana-EC Jun 15, 2021
c69e533
Add env flag for v1 run
Nana-EC Jun 15, 2021
d7bab05
Used spring values to inject flyway props
Nana-EC Jun 15, 2021
e63613b
Address 2 code smells after rebasing
Nana-EC Jun 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/importer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ jobs:
path: ~/.m2
restore-keys: ${{ runner.os }}-m2

- name: Set environment
- name: Set v1 environment
if: matrix.schema == 'v1'
run: echo 'groups=!v2' >> $GITHUB_ENV

- name: Set v2 environment
if: matrix.schema == 'v2'
run: echo 'groups=!v1' >> $GITHUB_ENV

Expand Down
4 changes: 4 additions & 0 deletions hedera-mirror-importer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class CacheConfiguration {

public static final String EXPIRE_AFTER_5M = "cacheManagerExpireAfter5m";
public static final String EXPIRE_AFTER_30M = "cacheManagerExpireAfter30m";
public static final String NEVER_EXPIRE_LARGE = "cacheManagerNeverExpireLarge";

@Bean(EXPIRE_AFTER_5M)
@Primary
Expand All @@ -54,11 +53,4 @@ CacheManager cacheManager30m() {
caffeineCacheManager.setCacheSpecification("maximumSize=10000,expireAfterWrite=30m");
return new TransactionAwareCacheManagerProxy(caffeineCacheManager);
}

@Bean(NEVER_EXPIRE_LARGE)
CacheManager cacheManagerNeverExpireLarge() {
CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager();
caffeineCacheManager.setCacheSpecification("maximumSize=2000000"); // 2 million 120MB
return new TransactionAwareCacheManagerProxy(caffeineCacheManager);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

@Named
public class ByteArrayToHexSerializer extends JsonSerializer<byte[]> {
public static final ByteArrayToHexSerializer INSTANCE = new ByteArrayToHexSerializer();

@Override
public void serialize(byte[] value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
if (value != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

@Named
public class EntityIdSerializer extends JsonSerializer<EntityId> {
public static final EntityIdSerializer INSTANCE = new EntityIdSerializer();

@Override
public void serialize(EntityId value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
if (!EntityId.isEmpty(value)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.hedera.mirror.importer.converter;

/*-
* ‌
* Hedera Mirror Node
* ​
* Copyright (C) 2019 - 2021 Hedera Hashgraph, LLC
* ​
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ‍
*/

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.util.UUID;
import javax.inject.Named;
import org.apache.commons.lang3.StringUtils;

@Named
public class NullableStringSerializer extends JsonSerializer<String> {
public static final String NULLABLE_STRING_REPLACEMENT = UUID.randomUUID().toString();

@Override
public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
// empty strings are serialized as null, set to reserved space character and rely on db update sql to parse
gen.writeString(StringUtils.EMPTY.equals(value) ? NULLABLE_STRING_REPLACEMENT : value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -43,7 +42,6 @@
import org.springframework.data.domain.Persistable;

import com.hedera.mirror.importer.converter.AccountIdConverter;
import com.hedera.mirror.importer.converter.EntityIdSerializer;
import com.hedera.mirror.importer.parser.domain.StreamItem;

@Data
Expand Down Expand Up @@ -85,7 +83,6 @@ public static class Id implements Serializable {
private long consensusTimestamp;

@Convert(converter = AccountIdConverter.class)
@JsonSerialize(using = EntityIdSerializer.class)
private EntityId accountId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Convert;
Expand All @@ -35,7 +34,6 @@
import org.springframework.data.domain.Persistable;

import com.hedera.mirror.importer.converter.AccountIdConverter;
import com.hedera.mirror.importer.converter.EntityIdSerializer;

@Data
@Entity
Expand Down Expand Up @@ -74,7 +72,6 @@ public static class Id implements Serializable {
private String ipAddressV4;

@Convert(converter = AccountIdConverter.class)
@JsonSerialize(using = EntityIdSerializer.class)
private EntityId nodeId;

private int port;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.io.Serializable;
import javax.persistence.Convert;
import javax.persistence.Embeddable;
Expand All @@ -34,15 +33,14 @@
import org.springframework.data.domain.Persistable;

import com.hedera.mirror.importer.converter.AccountIdConverter;
import com.hedera.mirror.importer.converter.EntityIdSerializer;

@Data
@Entity
@NoArgsConstructor
public class CryptoTransfer implements Persistable<CryptoTransfer.Id> {

public CryptoTransfer(long consensusTimestamp, long amount, EntityId entityId) {
this.id = new CryptoTransfer.Id(amount, consensusTimestamp, entityId);
id = new CryptoTransfer.Id(amount, consensusTimestamp, entityId);
}

/*
Expand Down Expand Up @@ -74,7 +72,6 @@ public static class Id implements Serializable {
private long consensusTimestamp;

@Convert(converter = AccountIdConverter.class)
@JsonSerialize(using = EntityIdSerializer.class)
private EntityId entityId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,41 @@
* ‍
*/

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import javax.persistence.Convert;
import javax.persistence.Id;
import lombok.Data;
import lombok.ToString;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;

import com.hedera.mirror.importer.converter.AccountIdConverter;
import com.hedera.mirror.importer.converter.NullableStringSerializer;
import com.hedera.mirror.importer.util.Utility;

@Data
@javax.persistence.Entity
@Log4j2
@ToString(exclude = {"key", "submitKey"})
public class Entity {
@Id
private Long id;

@Convert(converter = AccountIdConverter.class)
private EntityId autoRenewAccountId;

private Long autoRenewPeriod;

private Long createdTimestamp;

private boolean deleted;
private Boolean deleted;

private Long expirationTimestamp;

@Id
private Long id;

private byte[] key;

private String memo = "";
@JsonSerialize(using = NullableStringSerializer.class)
steven-sheehy marked this conversation as resolved.
Show resolved Hide resolved
private String memo;

private Long modifiedTimestamp;

Expand All @@ -59,6 +63,7 @@ public class Entity {
@Convert(converter = AccountIdConverter.class)
private EntityId proxyAccountId;

@JsonSerialize(using = NullableStringSerializer.class)
private String publicKey;

private Long realm;
Expand All @@ -75,7 +80,7 @@ public void setKey(byte[] key) {
}

public void setMemo(String memo) {
this.memo = Utility.sanitize(memo);
this.memo = StringUtils.isEmpty(memo) ? "" : Utility.sanitize(memo);
}

public EntityId toEntityId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
@Value
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class EntityId implements Serializable, Comparable<EntityId> {

private static final Comparator<EntityId> COMPARATOR = Comparator
.nullsFirst(Comparator.comparingLong(EntityId::getId));
public static final EntityId EMPTY = new EntityId(0L, 0L, 0L, EntityTypeEnum.ACCOUNT.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Id;
Expand All @@ -31,7 +30,6 @@
import lombok.ToString;
import org.springframework.data.domain.Persistable;

import com.hedera.mirror.importer.converter.EntityIdSerializer;
import com.hedera.mirror.importer.converter.FileIdConverter;

@Data
Expand All @@ -47,7 +45,6 @@ public class FileData implements Persistable<Long> {
private byte[] fileData;

@Convert(converter = FileIdConverter.class)
@JsonSerialize(using = EntityIdSerializer.class)
private EntityId entityId;

private Integer transactionType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.io.Serializable;
import javax.persistence.Convert;
import javax.persistence.Embeddable;
Expand All @@ -34,7 +33,6 @@
import org.springframework.data.domain.Persistable;

import com.hedera.mirror.importer.converter.AccountIdConverter;
import com.hedera.mirror.importer.converter.EntityIdSerializer;

@Data
@Entity
Expand Down Expand Up @@ -65,7 +63,6 @@ public static class Id implements Serializable {
private long consensusTimestamp;

@Convert(converter = AccountIdConverter.class)
@JsonSerialize(using = EntityIdSerializer.class)
private EntityId entityId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* ‍
*/

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Id;
Expand All @@ -29,7 +28,6 @@
import lombok.ToString;

import com.hedera.mirror.importer.converter.AccountIdConverter;
import com.hedera.mirror.importer.converter.EntityIdSerializer;
import com.hedera.mirror.importer.converter.ScheduleIdConverter;

@Data
Expand All @@ -40,17 +38,14 @@ public class Schedule {
private Long consensusTimestamp;

@Convert(converter = AccountIdConverter.class)
@JsonSerialize(using = EntityIdSerializer.class)
private EntityId creatorAccountId;

private Long executedTimestamp;

@Convert(converter = AccountIdConverter.class)
@JsonSerialize(using = EntityIdSerializer.class)
private EntityId payerAccountId;

@Convert(converter = ScheduleIdConverter.class)
@JsonSerialize(using = EntityIdSerializer.class)
private EntityId scheduleId;

@ToString.Exclude
Expand Down
Loading