Skip to content

Commit

Permalink
Revert "Updating pull run handling for a paralleized execution (#57)"
Browse files Browse the repository at this point in the history
This reverts commit 0919ff3.
  • Loading branch information
maallen committed Jan 18, 2024
1 parent 0919ff3 commit a4f229b
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 134 deletions.
38 changes: 0 additions & 38 deletions docker/Dockerfile-bk17

This file was deleted.

34 changes: 20 additions & 14 deletions docker/docker-compose-api-worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,28 @@ services:
- --collation-server=utf8mb4_bin
- --max-connections=1000
- --log_error_verbosity=2
volumes:
- mysql-data:/var/lib/mysql

api:
deploy:
mode: replicated
replicas: 1
endpoint_mode: vip
resources:
# limits:
# cpus: '2'
# memory: 1G
limits:
cpus: '2'
memory: 1G
reservations:
cpus: '1'
memory: 200M
healthcheck:
test: [ "CMD", "curl", "localhost:8080/" ]
interval: 5s
timeout: 10s
retries: 50
depends_on:
db:
condition: service_healthy
build:
dockerfile: docker/Dockerfile-bk17
dockerfile: docker/Dockerfile-bk8
context: ../
image: mojito:latest
pull_policy: never
Expand Down Expand Up @@ -101,15 +103,22 @@ services:
replicas: 2
endpoint_mode: vip
resources:
# limits:
# cpus: '2'
# memory: 1G
limits:
cpus: '2'
memory: 1G
reservations:
cpus: '1'
memory: 200M
healthcheck:
test: [ "CMD", "curl", "localhost:8080/" ]
interval: 5s
timeout: 10s
retries: 50
depends_on:
db:
condition: service_healthy
api:
condition: service_healthy
image: mojito:latest
pull_policy: never
links:
Expand Down Expand Up @@ -163,7 +172,4 @@ services:
"logging.level.com.box.l10n.mojito.quartz.QuartzPollableTaskScheduler" : "DEBUG",
"logging.level.com.box.l10n.mojito.service.repository.statistics.RepositoryStatisticsJob" : "DEBUG",
"logging.level.com.box.l10n.mojito.service.thirdparty.smartling.quartz" : "DEBUG"
}'

volumes:
mysql-data:
}'
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ForeignKey;
import javax.persistence.Index;
Expand All @@ -26,8 +25,8 @@
name = "pull_run_text_unit_variant",
indexes = {
@Index(
name = "UK__PULL_RUN_TEXT_UNIT_VARIANT__LOCALE_ID__PRA_ID__TUV_ID__TAG",
columnList = "pull_run_asset_id, locale_id, output_bcp47_tag, tm_text_unit_variant_id",
name = "UK__PULL_RUN_TEXT_UNIT_VARIANT__PRA_ID__TUV_ID__LOCALE_ID",
columnList = "pull_run_asset_id, tm_text_unit_variant_id, locale_id",
unique = true)
})
@BatchSize(size = 1000)
Expand All @@ -53,9 +52,6 @@ public class PullRunTextUnitVariant extends SettableAuditableEntity {
foreignKey = @ForeignKey(name = "FK__PULL_RUN_TEXT_UNIT_VARIANT__TM_TEXT_UNIT_VARIANT_ID"))
private TMTextUnitVariant tmTextUnitVariant;

@Column(name = "output_bcp47_tag", length = 10)
private String outputBcp47Tag;

public PullRunAsset getPullRunAsset() {
return pullRunAsset;
}
Expand All @@ -71,12 +67,4 @@ public TMTextUnitVariant getTmTextUnitVariant() {
public void setTmTextUnitVariant(TMTextUnitVariant tmTextUnitVariant) {
this.tmTextUnitVariant = tmTextUnitVariant;
}

public String getOutputBcp47Tag() {
return outputBcp47Tag;
}

public void setOutputBcp47Tag(String outputBcp47Tag) {
this.outputBcp47Tag = outputBcp47Tag;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.google.common.collect.Lists;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tags;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -47,58 +48,46 @@ public PullRunAsset getOrCreate(PullRun pullRun, Asset asset) {
.orElseGet(() -> createPullRunAsset(pullRun, asset));
}

@Transactional
public void replaceTextUnitVariants(
PullRunAsset pullRunAsset,
Long localeId,
List<Long> uniqueTmTextUnitVariantIds,
String outputBcp47Tag) {
PullRunAsset pullRunAsset, Long localeId, List<Long> uniqueTmTextUnitVariantIds) {
Repository repository = pullRunAsset.getPullRun().getRepository();
meterRegistry
.timer(
"PullRunAssetService.saveTextUnitVariantsMultiRow",
Tags.of("repositoryId", Objects.toString(repository.getId())))
.record(
() -> {
deleteExistingVariants(pullRunAsset, localeId, outputBcp47Tag);
Instant now = Instant.now();
jdbcTemplate.update(
"delete from pull_run_text_unit_variant where pull_run_asset_id = ? and locale_id = ?",
pullRunAsset.getId(),
localeId);
Lists.partition(uniqueTmTextUnitVariantIds, BATCH_SIZE)
.forEach(
tuvIdsBatch ->
saveTextUnitVariantsMultiRowBatch(
pullRunAsset, localeId, tuvIdsBatch, outputBcp47Tag));
pullRunAsset, localeId, tuvIdsBatch, now));
});
}

@Transactional
void deleteExistingVariants(PullRunAsset pullRunAsset, Long localeId, String outputBcp47Tag) {
// Delete and insert steps split into two transactions to avoid deadlocks occurring
jdbcTemplate.update(
"delete from pull_run_text_unit_variant where pull_run_asset_id = ? and locale_id = ? and output_bcp47_tag = ?",
pullRunAsset.getId(),
localeId,
outputBcp47Tag);
}

@Transactional
void saveTextUnitVariantsMultiRowBatch(
PullRunAsset pullRunAsset,
Long localeId,
List<Long> uniqueTmTextUnitVariantIds,
String outputBcp47Tag) {

Instant now) {
ZonedDateTime createdTime = ZonedDateTime.now();

String sql =
"insert into pull_run_text_unit_variant(pull_run_asset_id, locale_id, tm_text_unit_variant_id, created_date, output_bcp47_tag) values "
"insert into pull_run_text_unit_variant(pull_run_asset_id, locale_id, tm_text_unit_variant_id, created_date) values "
+ uniqueTmTextUnitVariantIds.stream()
.map(
tuvId ->
String.format(
"(%s, %s, %s, '%s', '%s') ",
"(%s, %s, %s, '%s') ",
pullRunAsset.getId(),
localeId,
tuvId,
JSR310Migration.toRawSQL(createdTime),
outputBcp47Tag))
JSR310Migration.toRawSQL(createdTime)))
.collect(Collectors.joining(","));
jdbcTemplate.update(sql);
}
Expand Down
27 changes: 7 additions & 20 deletions webapp/src/main/java/com/box/l10n/mojito/service/tm/TMService.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import com.box.l10n.mojito.okapi.steps.FilterEventsToInMemoryRawDocumentStep;
import com.box.l10n.mojito.quartz.QuartzJobInfo;
import com.box.l10n.mojito.quartz.QuartzPollableTaskScheduler;
import com.box.l10n.mojito.retry.DataIntegrityViolationExceptionRetryTemplate;
import com.box.l10n.mojito.security.AuditorAwareImpl;
import com.box.l10n.mojito.service.WordCountService;
import com.box.l10n.mojito.service.asset.AssetRepository;
Expand Down Expand Up @@ -145,9 +144,6 @@ public class TMService {

@Autowired PullRunAssetService pullRunAssetService;

@Autowired
DataIntegrityViolationExceptionRetryTemplate dataIntegrityViolationExceptionRetryTemplate;

@Value("${l10n.tmService.quartz.schedulerName:" + DEFAULT_SCHEDULER_NAME + "}")
String schedulerName;

Expand Down Expand Up @@ -1049,27 +1045,18 @@ public String generateLocalized(
asset, content, filterConfigIdOverride, filterOptions, translateStep, bcp47Tag);

if (replaceUsedTmTextUnitVariantIds) {
dataIntegrityViolationExceptionRetryTemplate.execute(
context -> {
replaceUsedTmTextUnitVariantIds(
asset,
pullRunName,
repositoryLocale.getLocale(),
translateStep.getUsedTmTextUnitVariantIds(),
outputBcp47tag);
return null;
});
replaceUsedTmTextUnitVariantIds(
asset,
pullRunName,
repositoryLocale.getLocale(),
translateStep.getUsedTmTextUnitVariantIds());
}

return generateLocalizedBase;
}

void replaceUsedTmTextUnitVariantIds(
Asset asset,
String pullRunName,
Locale locale,
List<Long> usedTmTextUnitVariantIds,
String outputBcp47tag) {
Asset asset, String pullRunName, Locale locale, List<Long> usedTmTextUnitVariantIds) {
logger.debug(
"Replace used TmTextUnitVariantIds for pull run name: {} and locale: {}",
pullRunName,
Expand All @@ -1079,7 +1066,7 @@ void replaceUsedTmTextUnitVariantIds(
List<Long> uniqueUsedTmTextUnitVariantIds =
usedTmTextUnitVariantIds.stream().distinct().collect(Collectors.toList());
pullRunAssetService.replaceTextUnitVariants(
pullRunAsset, locale.getId(), uniqueUsedTmTextUnitVariantIds, outputBcp47tag);
pullRunAsset, locale.getId(), uniqueUsedTmTextUnitVariantIds);
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,6 @@ private void associatePullRunToTextUnitIds(
Collectors.mapping(TMTextUnitVariant::getId, Collectors.toList())))
.forEach(
(localeId, perLocale) ->
pullRunAssetService.replaceTextUnitVariants(
pullRunAsset, localeId, perLocale, "test"));
pullRunAssetService.replaceTextUnitVariants(pullRunAsset, localeId, perLocale));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void testCleanOldPushPullData() throws Exception {
tmTextUnit1.getId(), frFR.getId(), "le hello_world 2");

pullRunAssetService.replaceTextUnitVariants(
pullRunAsset, frFR.getId(), Arrays.asList(tuv1.getId(), tuv2.getId()), "fr-FR");
pullRunAsset, frFR.getId(), Arrays.asList(tuv1.getId(), tuv2.getId()));
List<TMTextUnitVariant> recordedVariants =
pullRunTextUnitVariantRepository.findByPullRun(pullRun, Pageable.unpaged());
Assert.assertEquals(2, recordedVariants.size());
Expand Down

0 comments on commit a4f229b

Please sign in to comment.