mirror of
https://github.com/google/nomulus.git
synced 2025-04-30 03:57:51 +02:00
Remove aggressive check in RegistryJpaIO.Write (#1889)
This commit is contained in:
parent
6a1fd3491f
commit
61389a66bb
2 changed files with 4 additions and 15 deletions
|
@ -14,7 +14,6 @@
|
||||||
|
|
||||||
package google.registry.beam.common;
|
package google.registry.beam.common;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
|
||||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||||
import static org.apache.beam.sdk.values.TypeDescriptors.integers;
|
import static org.apache.beam.sdk.values.TypeDescriptors.integers;
|
||||||
|
|
||||||
|
@ -345,8 +344,7 @@ public final class RegistryJpaIO {
|
||||||
try {
|
try {
|
||||||
tm().transact(
|
tm().transact(
|
||||||
() -> {
|
() -> {
|
||||||
// Don't modify existing objects as it could lead to race conditions
|
// TODO(b/263502442): properly handle creations and blind-writes.
|
||||||
entities.forEach(this::verifyObjectNonexistence);
|
|
||||||
tm().putAll(entities);
|
tm().putAll(entities);
|
||||||
});
|
});
|
||||||
counter.inc(entities.size());
|
counter.inc(entities.size());
|
||||||
|
@ -364,8 +362,7 @@ public final class RegistryJpaIO {
|
||||||
try {
|
try {
|
||||||
tm().transact(
|
tm().transact(
|
||||||
() -> {
|
() -> {
|
||||||
// Don't modify existing objects as it could lead to race conditions
|
// TODO(b/263502442): properly handle creations and blind-writes.
|
||||||
verifyObjectNonexistence(entity);
|
|
||||||
tm().put(entity);
|
tm().put(entity);
|
||||||
});
|
});
|
||||||
counter.inc();
|
counter.inc();
|
||||||
|
@ -391,15 +388,5 @@ public final class RegistryJpaIO {
|
||||||
return "Non-SqlEntity: " + entity;
|
return "Non-SqlEntity: " + entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** SqlBatchWriter should not re-write existing entities due to potential race conditions. */
|
|
||||||
private void verifyObjectNonexistence(Object obj) {
|
|
||||||
// We cannot rely on calling "insert" on the objects because the underlying JPA persist call
|
|
||||||
// adds the input object to the persistence context, meaning that any modifications (e.g.
|
|
||||||
// updateTimestamp) are reflected in the input object. Beam doesn't allow modification of
|
|
||||||
// input objects, so this throws an exception.
|
|
||||||
// TODO(go/non-datastore-allocateid): also check that all the objects have IDs
|
|
||||||
checkArgument(!tm().exists(obj), "Entities created in SqlBatchWriter must not already exist");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import java.io.Serializable;
|
||||||
import org.apache.beam.sdk.Pipeline.PipelineExecutionException;
|
import org.apache.beam.sdk.Pipeline.PipelineExecutionException;
|
||||||
import org.apache.beam.sdk.transforms.Create;
|
import org.apache.beam.sdk.transforms.Create;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
|
@ -67,6 +68,7 @@ class RegistryJpaWriteTest implements Serializable {
|
||||||
.containsExactlyElementsIn(contacts);
|
.containsExactlyElementsIn(contacts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Disabled("b/263502442")
|
||||||
@Test
|
@Test
|
||||||
void testFailure_writeExistingEntity() {
|
void testFailure_writeExistingEntity() {
|
||||||
// RegistryJpaIO.Write actions should not write existing objects to the database because the
|
// RegistryJpaIO.Write actions should not write existing objects to the database because the
|
||||||
|
|
Loading…
Add table
Reference in a new issue