-
Notifications
You must be signed in to change notification settings - Fork 3
generate snapshot in background #364
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
Conversation
1f65183
to
03bcb66
Compare
logger.debug("Stored successfully {}", storedSuccessfully); | ||
return storedSuccessfully; | ||
} catch (SerializationException e) { | ||
logger.error("Error creating snapshot for %s".formatted(streamId), e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't know you could do this kind of formatting. Nice :-)
@@ -26,7 +26,7 @@ public class AggregateSnapshotTest { | |||
public void shouldCreateAnAggregateSnapshot() throws Exception { | |||
final TestAggregate aggregate = new TestAggregate("STATE1"); | |||
|
|||
final AggregateSnapshot<TestAggregate> snapshot = new AggregateSnapshot<>(STREAM_ID, VERSION_ID, aggregate); | |||
final AggregateSnapshot<TestAggregate> snapshot = new AggregateSnapshot<>(STREAM_ID, VERSION_ID, aggregate, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I like passing in null like this. I've found nulls usually lead to tears and pain. Can this be an Optional instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
} | ||
|
||
public AggregateSnapshot(final UUID streamId, final Long versionId, final String type, final byte[] aggregateByteRepresentation) { | ||
public AggregateSnapshot(final UUID streamId, final Long versionId, final String type, final byte[] aggregateByteRepresentation, final ZonedDateTime createdAt) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the aggregateByteRepresentation byte array and createdAt date are linked, should they be but into a new single Object, AggregateByteArray or something. Also, if it's not always been created, should that Object be Optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed
bf76db3
to
3c87402
Compare
@@ -52,12 +59,18 @@ public class SnapshotJdbcRepository implements SnapshotRepository { | |||
public boolean storeSnapshot(final AggregateSnapshot aggregateSnapshot) { | |||
|
|||
try (final Connection connection = eventStoreDataSourceProvider.getDefaultDataSource().getConnection(); | |||
final PreparedStatement ps = connection.prepareStatement(SQL_INSERT_EVENT_LOG)) { | |||
final PreparedStatement ps = connection.prepareStatement(SQL_UPSERT_SNAPSHOT)) { | |||
final Timestamp sqlTimestamp = toSqlTimestamp(clock.now()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to rename this variable with what exactly it represents, may be something like nowTime?
|
||
@Inject | ||
@Value(key = "snapshot.background.saving.threshold", defaultValue = "" + SNAPSHOT_BACKGROUND_SAVING_THRESHOLD) | ||
private long snapshotBackgroundSavingThreshold; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on how this JNDI variable is going to be configured and if type is configured as java.lang.String auto conversion may not happen out of the box (I might be wrong with my assumption, worth checking it).
It's uncommon to define type as Long in standalone.xml at least by looking at existing practice. If this auto conversion won't happen and if JNDI variable type is configured as String, it may fail
Example of existing ocnfig practice:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @santhosh-kumar3 for the comment.
On SIT:
name="java:/app/material-service/material.sasUrlExpiryInMinutes"
type="java.lang.String"
value="30"
/>
and the java code looks like this:
@Inject
@Value(key = "material.sasUrlExpiryInMinutes", defaultValue = "30")
private long expiryMinutes;
Also just for testing this, I have edited the docker project to add JNDI value
<simple name="java:/app/results-service/snapshot.background.saving.threshold" value="10000" type="java.lang.String"/>
and I have changed the code to log the value
logger.info("==== snapshotBackgroundSavingThreshold is {}", snapshotBackgroundSavingThreshold);
after redeploying results, I can see the output
==== snapshotBackgroundSavingThreshold is 10000
so, the automatic long/in conversion seems to be working
return false; | ||
} | ||
|
||
final long threshold = snapshotBackgroundSavingThreshold <= 0 ? SNAPSHOT_BACKGROUND_SAVING_THRESHOLD : snapshotBackgroundSavingThreshold; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason for checking for negative value? I suppose if variable is not configured it gets initialised to default value defined in class level static variable, so either it will have 0 or default value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, the threshold should never be zero (throws arithmetic-err : division-by-zero) and nothing is preventing a negative value
62c11fc
to
bfedc7e
Compare
bfedc7e
to
ceab499
Compare
|
No description provided.