improved logging (#4217)
Co-authored-by: Ken Stevens <ken@smilecdr.com>
This commit is contained in:
parent
c6c095219d
commit
bd28730c7d
|
@ -55,7 +55,7 @@ public class HapiMigrationLock implements AutoCloseable {
|
|||
return;
|
||||
}
|
||||
retryCount++;
|
||||
ourLog.info("Waiting for lock on " + this);
|
||||
ourLog.info("Waiting for lock on {}. Retry {}/{}", myMigrationStorageSvc.getMigrationTablename(), retryCount, MAX_RETRY_ATTEMPTS);
|
||||
Thread.sleep(SLEEP_MILLIS_BETWEEN_LOCK_RETRIES);
|
||||
} catch (InterruptedException ex) {
|
||||
// Ignore - if interrupted, we still need to wait for lock to become available
|
||||
|
@ -72,6 +72,7 @@ public class HapiMigrationLock implements AutoCloseable {
|
|||
try {
|
||||
return myMigrationStorageSvc.insertLockRecord(myLockDescription);
|
||||
} catch (Exception e) {
|
||||
ourLog.warn("Failed to insert lock record: {}", e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package ca.uhn.fhir.jpa.migrate;
|
||||
|
||||
import ca.uhn.fhir.interceptor.api.HookParams;
|
||||
import ca.uhn.fhir.jpa.migrate.dao.MigrationQueryBuilder;
|
||||
import ca.uhn.fhir.jpa.migrate.entity.HapiMigrationEntity;
|
||||
import ca.uhn.fhir.jpa.migrate.taskdef.BaseTask;
|
||||
import ca.uhn.test.concurrency.IPointcutLatch;
|
||||
import ca.uhn.test.concurrency.PointcutLatch;
|
||||
|
@ -108,6 +110,41 @@ class HapiMigratorIT {
|
|||
assertThat(result2.succeededTasks, hasSize(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_twoSequentialCalls_noblock() throws InterruptedException, ExecutionException {
|
||||
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
LatchMigrationTask latchMigrationTask = new LatchMigrationTask("first", "1");
|
||||
|
||||
HapiMigrator migrator = buildMigrator(latchMigrationTask);
|
||||
assertEquals(0, countLockRecords());
|
||||
|
||||
{
|
||||
latchMigrationTask.setExpectedCount(1);
|
||||
Future<MigrationResult> future = executor.submit(() -> migrator.migrate());
|
||||
latchMigrationTask.awaitExpected();
|
||||
assertEquals(1, countLockRecords());
|
||||
latchMigrationTask.release("1");
|
||||
|
||||
MigrationResult result = future.get();
|
||||
assertEquals(0, countLockRecords());
|
||||
assertThat(result.succeededTasks, hasSize(1));
|
||||
}
|
||||
|
||||
{
|
||||
Future<MigrationResult> future = executor.submit(() -> migrator.migrate());
|
||||
|
||||
MigrationResult result = future.get();
|
||||
assertEquals(0, countLockRecords());
|
||||
assertThat(result.succeededTasks, hasSize(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int countLockRecords() {
|
||||
return myJdbcTemplate.queryForObject("SELECT COUNT(*) FROM " + MIGRATION_TABLENAME + " WHERE \"installed_rank\" = " + HapiMigrationStorageSvc.LOCK_PID, Integer.class);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private HapiMigrator buildMigrator(LatchMigrationTask theLatchMigrationTask) {
|
||||
HapiMigrator retval = buildMigrator();
|
||||
|
|
Loading…
Reference in New Issue