Skip to content

Commit

Permalink
[Spark] Integrate ICT into Managed Commits (delta-io#3108)
Browse files Browse the repository at this point in the history
<!--
Thanks for sending a pull request!  Here are some tips for you:
1. If this is your first time, please read our contributor guidelines:
https://github.com/delta-io/delta/blob/master/CONTRIBUTING.md
2. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]
Your PR title ...'.
  3. Be sure to keep the PR description updated to reflect all changes.
  4. Please write your PR title to summarize what this PR proposes.
5. If possible, provide a concise example to reproduce the issue for a
faster review.
6. If applicable, include the corresponding issue number in the PR title
and link it in the body.
-->

#### Which Delta project/connector is this regarding?
<!--
Please add the component selected below to the beginning of the pull
request title
For example: [Spark] Title of my pull request
-->

- [X] Spark
- [ ] Standalone
- [ ] Flink
- [ ] Kernel
- [ ] Other (fill in here)

## Description

<!--
- Describe what this PR changes.
- Describe why we need the change.
 
If this PR resolves an issue be sure to include "Resolves #XXX" to
correctly link and close the issue upon merge.
-->

Resolves TODOs around ICT <-> MC integration.

## How was this patch tested?

<!--
If tests were added, say they were added here. Please make sure to test
the changes thoroughly including negative and positive cases if
possible.
If the changes were tested in any way other than unit tests, please
clarify how you tested step by step (ideally copy and paste-able, so
that other reviewers can test and check, and descendants can verify in
the future).
If the changes were not tested, please explain why.
-->
Updated existing tests.

## Does this PR introduce _any_ user-facing changes?

<!--
If yes, please clarify the previous behavior and the change this PR
proposes - provide the console output, description and/or an example to
show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change
compared to the released Delta Lake versions or within the unreleased
branches such as master.
If no, write 'No'.
-->
No
  • Loading branch information
dhruvarya-db authored and longvu-db committed May 28, 2024
1 parent 2e9412e commit 6862e27
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2102,11 +2102,18 @@ trait OptimisticTransactionImpl extends TransactionalWrite
val commitFileStatus =
doCommit(logStore, hadoopConf, logPath, commitFile, commitVersion, actions)
executionObserver.beginBackfill()
// TODO(managed-commits): Integrate with ICT and pass the correct commitTimestamp
val ictEnabled = updatedActions.getNewMetadata.getConfiguration.getOrElse(
DeltaConfigs.IN_COMMIT_TIMESTAMPS_ENABLED.key, "false") == "true"
val commitTimestamp = if (ictEnabled) {
// CommitInfo.getCommitTimestamp will return the inCommitTimestamp.
updatedActions.getCommitInfo.getCommitTimestamp
} else {
commitFileStatus.getModificationTime
}
CommitResponse(Commit(
commitVersion,
fileStatus = commitFileStatus,
commitTimestamp = commitFileStatus.getModificationTime
commitTimestamp = commitTimestamp
))
}

Expand Down Expand Up @@ -2182,10 +2189,6 @@ trait OptimisticTransactionImpl extends TransactionalWrite
val commitResponse = TransactionExecutionObserver.withObserver(executionObserver) {
tableCommitOwnerClient.commit(attemptVersion, jsonActions, updatedActions)
}
// TODO(managed-commits): Use the right timestamp method on top of CommitInfo once ICT is
// merged.
val commitTimestamp = commitResponse.getCommit.getFileStatus.getModificationTime
val commitFile = commitResponse.getCommit.copy(commitTimestamp = commitTimestamp)
if (attemptVersion == 0L) {
val expectedPathForCommitZero = unsafeDeltaFile(deltaLog.logPath, version = 0L).toUri
val actualCommitPath = commitResponse.getCommit.getFileStatus.getPath.toUri
Expand All @@ -2194,7 +2197,7 @@ trait OptimisticTransactionImpl extends TransactionalWrite
s"$expectedPathForCommitZero but was written to $actualCommitPath")
}
}
commitFile
commitResponse.getCommit
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.apache.spark.sql.delta.managedcommit
import java.nio.file.FileAlreadyExistsException
import java.util.UUID

import org.apache.spark.sql.delta.DeltaLog
import org.apache.spark.sql.delta.TransactionExecutionObserver
import org.apache.spark.sql.delta.actions.CommitInfo
import org.apache.spark.sql.delta.actions.Metadata
Expand Down Expand Up @@ -87,7 +88,7 @@ trait AbstractBatchBackfillingCommitOwnerClient extends CommitOwnerClient with L
logStore, hadoopConf, logPath, commitVersion, actions, generateUUID())

// Do the actual commit
val commitTimestamp = updatedActions.getCommitInfo.asInstanceOf[CommitInfo].getTimestamp
val commitTimestamp = updatedActions.getCommitInfo.getCommitTimestamp
var commitResponse =
commitImpl(
logStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import scala.collection.mutable.ArrayBuffer
import com.databricks.spark.util.Log4jUsageLogger
import org.apache.spark.sql.delta.{DeltaOperations, ManagedCommitTableFeature, V2CheckpointTableFeature}
import org.apache.spark.sql.delta.CommitOwnerGetCommitsFailedException
import org.apache.spark.sql.delta.DeltaConfigs.{CHECKPOINT_INTERVAL, MANAGED_COMMIT_OWNER_CONF, MANAGED_COMMIT_OWNER_NAME, ROW_TRACKING_ENABLED}
import org.apache.spark.sql.delta.DeltaConfigs.{CHECKPOINT_INTERVAL, MANAGED_COMMIT_OWNER_CONF, MANAGED_COMMIT_OWNER_NAME, MANAGED_COMMIT_TABLE_CONF}
import org.apache.spark.sql.delta.DeltaLog
import org.apache.spark.sql.delta.DeltaTestUtils.createTestAddFile
import org.apache.spark.sql.delta.InitialSnapshot
Expand Down Expand Up @@ -774,7 +774,14 @@ class ManagedCommitSuite
// Downgrade the table
// [upgradeExistingTable = false] Commit-3
// [upgradeExistingTable = true] Commit-5
val newMetadata2 = Metadata().copy(configuration = Map("downgraded_at" -> "v2"))
val commitOwnerConfKeys = Seq(
MANAGED_COMMIT_OWNER_NAME.key,
MANAGED_COMMIT_OWNER_CONF.key,
MANAGED_COMMIT_TABLE_CONF.key
)
val newConfig = log.snapshot.metadata.configuration
.filterKeys(!commitOwnerConfKeys.contains(_)) ++ Map("downgraded_at" -> "v2")
val newMetadata2 = log.snapshot.metadata.copy(configuration = newConfig.toMap)
log.startTransaction().commitManually(newMetadata2)
assert(log.unsafeVolatileSnapshot.version === upgradeStartVersion + 3)
assert(log.unsafeVolatileSnapshot.tableCommitOwnerClientOpt.isEmpty)
Expand Down

0 comments on commit 6862e27

Please sign in to comment.