Skip to content

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

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

arcadiushmcts
Copy link
Contributor

No description provided.

@arcadiushmcts arcadiushmcts force-pushed the dev/generate-snapshot-in-background branch 8 times, most recently from 1f65183 to 03bcb66 Compare November 18, 2024 15:14
logger.debug("Stored successfully {}", storedSuccessfully);
return storedSuccessfully;
} catch (SerializationException e) {
logger.error("Error creating snapshot for %s".formatted(streamId), e);
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Contributor

@arcadius arcadius Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed

@arcadiushmcts arcadiushmcts force-pushed the dev/generate-snapshot-in-background branch 2 times, most recently from bf76db3 to 3c87402 Compare November 19, 2024 10:05
@@ -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());
Copy link
Contributor

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;
Copy link
Contributor

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:

Copy link
Contributor

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;
Copy link
Contributor

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

Copy link
Contributor

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

@arcadiushmcts arcadiushmcts force-pushed the dev/generate-snapshot-in-background branch 2 times, most recently from 62c11fc to bfedc7e Compare November 19, 2024 18:27
@arcadiushmcts arcadiushmcts force-pushed the dev/generate-snapshot-in-background branch from bfedc7e to ceab499 Compare November 21, 2024 08:52
Copy link

@arcadiushmcts arcadiushmcts merged commit f52e052 into master Nov 21, 2024
3 checks passed
@arcadiushmcts arcadiushmcts deleted the dev/generate-snapshot-in-background branch November 21, 2024 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants