Skip to content
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

[Spark] InCommitTimestamp: Use clock.currentTimeMillis() instead of nanoTime() in commitLarge #3111

Merged
merged 7 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1337,10 +1337,11 @@ trait OptimisticTransactionImpl extends TransactionalWrite

try {
val tags = Map.empty[String, String]
val commitTimestampMs = clock.getTimeMillis()
val commitInfo = CommitInfo(
NANOSECONDS.toMillis(commitStartNano),
commitTimestampMs,
operation = op.name,
generateInCommitTimestampForFirstCommitAttempt(NANOSECONDS.toMillis(commitStartNano)),
generateInCommitTimestampForFirstCommitAttempt(commitTimestampMs),
operationParameters = op.jsonEncodedValues,
context,
readVersion = Some(readVersion),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,33 @@ class InCommitTimestampSuite
}
}

test("commitLarge should use clock.currentTimeMillis() for ICT") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we have a similar test for txn.commit API?

withTempDir { tempDir =>
spark.range(2).write.format("delta").save(tempDir.getAbsolutePath)
// Clear the DeltaLog cache so that a new DeltaLog is created with the manual clock.
DeltaLog.clearCache()
val expectedCommit1Time = System.currentTimeMillis()
val clock = new ManualClock(expectedCommit1Time)
val deltaLog = DeltaLog.forTable(spark, new Path(tempDir.getCanonicalPath), clock)
val ver0Snapshot = deltaLog.snapshot
assert(DeltaConfigs.IN_COMMIT_TIMESTAMPS_ENABLED.fromMetaData(ver0Snapshot.metadata))
val usageRecords = Log4jUsageLogger.track {
deltaLog.startTransaction().commitLarge(
spark,
Seq(createTestAddFile("1")).toIterator,
None,
DeltaOperations.ManualUpdate,
Map.empty,
Map.empty)
}
val ver1Snapshot = deltaLog.snapshot
val retrievedTimestamp = getInCommitTimestamp(deltaLog, version = 1)
assert(ver1Snapshot.timestamp == retrievedTimestamp)
assert(ver1Snapshot.timestamp == expectedCommit1Time)
assert(filterUsageRecords(usageRecords, "delta.commit.large").length == 1)
}
}

test("Missing CommitInfo should result in a DELTA_MISSING_COMMIT_INFO exception") {
withTempDir { tempDir =>
spark.range(10).write.format("delta").save(tempDir.getAbsolutePath)
Expand Down
Loading