Skip to content

Commit

Permalink
Save the submission time in the command deduplication value [KVL-1173] (
Browse files Browse the repository at this point in the history
#11509)

CHANGELOG_BEGIN

CHANGELOG_END
  • Loading branch information
nicu-da authored Nov 3, 2021
1 parent 669186f commit a917520
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ message DamlCommandDedupKey {

message DamlCommandDedupValue {
reserved 1; // was record_time
// the time until when future commands with the same
// deduplication key will be rejected due to a duplicate submission
// The time until when future commands with the same
// deduplication key will be rejected due to a duplicate submission.
google.protobuf.Timestamp deduplicated_until = 2;
// The submission time of the initial command.
// We use submission time because record time is not available during pre-execution.
google.protobuf.Timestamp submission_time = 3;
}

message DamlSubmissionDedupKey {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,14 @@ private[kvutils] class TransactionCommitter(
if (!transactionEntry.submitterInfo.hasDeduplicationDuration) {
throw Err.InvalidSubmission("Deduplication duration is not set.")
}
val commandDedupBuilder = DamlCommandDedupValue.newBuilder.setDeduplicatedUntil(
Conversions.buildTimestamp(
transactionEntry.submissionTime
.add(parseDuration(transactionEntry.submitterInfo.getDeduplicationDuration))
.add(config.timeModel.minSkew)
)
val deduplicateUntil = Conversions.buildTimestamp(
transactionEntry.submissionTime
.add(parseDuration(transactionEntry.submitterInfo.getDeduplicationDuration))
.add(config.timeModel.minSkew)
)
val commandDedupBuilder = DamlCommandDedupValue.newBuilder
.setDeduplicatedUntil(deduplicateUntil)
.setSubmissionTime(Conversions.buildTimestamp(transactionEntry.submissionTime))
// Set a deduplication entry.
commitContext.set(
commandDedupKey(transactionEntry.submitterInfo),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ class TransactionCommitterSpec
"setting dedup context" should {
val deduplicateUntil = protobuf.Timestamp.newBuilder().setSeconds(30).build()
val submissionTime = protobuf.Timestamp.newBuilder().setSeconds(60).build()
val deduplicationDuration = time.Duration.ofSeconds(3)

"calculate deduplicate until based on deduplication duration" in {
val deduplicationDuration = time.Duration.ofSeconds(3)
val (context, transactionEntrySummary) =
buildContextAndTransaction(
submissionTime,
Expand All @@ -257,6 +257,21 @@ class TransactionCommitterSpec
.build()
}

"set the submission time in the committer context" in {
val (context, transactionEntrySummary) =
buildContextAndTransaction(
submissionTime,
_.setDeduplicationDuration(Conversions.buildDuration(deduplicationDuration)),
)
transactionCommitter.setDedupEntry(context, transactionEntrySummary)
context
.get(Conversions.commandDedupKey(transactionEntrySummary.submitterInfo))
.map(
_.getCommandDedup.getSubmissionTime
)
.value shouldBe submissionTime
}

"throw an error for unsupported deduplication periods" in {
forAll(
Table[DamlSubmitterInfo.Builder => DamlSubmitterInfo.Builder](
Expand Down

0 comments on commit a917520

Please sign in to comment.