This repository was archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 116
Update index log entry for enforce delete during read time #170
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
55f146b
Metadata changes for enforce delete on read
e9e6e33
fix IndexLogEntry test
777b57e
add signature update to enforce delete on read
fcc3952
fix test cleanup
8a36e60
changes in excluded files update
821ccd5
changes in refresh delete validate
f27a8a7
minor code refactor in IndexLogEntry
bf21c8d
add code comments
a047982
Changes in enforce delete on read and its tests
a38ac88
Merge branch 'master' into pouriap/deleteOnRead
2720656
Action rename and misc test fixes for delete on read
e93217f
Add appended files to index metadata and rename action
91a136f
add RefreshLogEntryAction
a6f6fc0
Action and config renames
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/scala/com/microsoft/hyperspace/actions/RefreshDeleteActionBase.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * Copyright (2020) The Hyperspace Project Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.microsoft.hyperspace.actions | ||
|
|
||
| import org.apache.hadoop.fs.Path | ||
| import org.apache.spark.sql.SparkSession | ||
|
|
||
| import com.microsoft.hyperspace.HyperspaceException | ||
| import com.microsoft.hyperspace.index.{Content, IndexDataManager, IndexLogManager} | ||
|
|
||
| private[actions] abstract class RefreshDeleteActionBase( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To Reviewers:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To Reviewers This class needs a rename, as its children are no longer dealing only with delete-related items. Any suggestion? |
||
| spark: SparkSession, | ||
| logManager: IndexLogManager, | ||
| dataManager: IndexDataManager) | ||
| extends RefreshActionBase(spark, logManager, dataManager) { | ||
|
|
||
| /** | ||
| * Validate index has lineage column, and it is in active state for refreshing. | ||
| */ | ||
| override def validate(): Unit = { | ||
| super.validate() | ||
| if (!previousIndexLogEntry.hasLineageColumn(spark)) { | ||
| throw HyperspaceException( | ||
| "Index refresh to update source content in index metadata is " + | ||
| "only supported on an index with lineage.") | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Compare list of source data files from previous IndexLogEntry to list | ||
| * of current source data files, validate fileInfo for existing files and | ||
| * identify deleted and appended source data files. | ||
| */ | ||
| protected lazy val sourceFilesDiff: (Seq[String], Seq[String]) = { | ||
| val rels = previousIndexLogEntry.relations | ||
| val originalFiles = rels.head.data.properties.content.fileInfos | ||
| val currentFiles = rels.head.rootPaths | ||
| .flatMap { p => | ||
| Content | ||
| .fromDirectory(path = new Path(p), throwIfNotExists = true) | ||
| .fileInfos | ||
| } | ||
| .map(f => f.name -> f) | ||
| .toMap | ||
|
|
||
| var delFiles = Seq[String]() | ||
| originalFiles.foreach { f => | ||
| currentFiles.get(f.name) match { | ||
| case Some(v) => | ||
| if (!f.equals(v)) { | ||
| throw HyperspaceException( | ||
| "Index refresh (to handle deleted or appended source data) aborted. " + | ||
| s"Existing source data file info is changed (file: ${f.name}).") | ||
| } | ||
| case None => delFiles :+= f.name | ||
| } | ||
| } | ||
|
|
||
| (delFiles, (currentFiles.keySet diff originalFiles.map(_.name)).toSeq) | ||
| } | ||
| } | ||
114 changes: 114 additions & 0 deletions
114
src/main/scala/com/microsoft/hyperspace/actions/RefreshSourceContentAction.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /* | ||
| * Copyright (2020) The Hyperspace Project Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.microsoft.hyperspace.actions | ||
|
|
||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.sql.SparkSession | ||
|
|
||
| import com.microsoft.hyperspace.HyperspaceException | ||
| import com.microsoft.hyperspace.index._ | ||
| import com.microsoft.hyperspace.telemetry.{AppInfo, HyperspaceEvent, RefreshSourceContentActionEvent} | ||
|
|
||
| /** | ||
| * Refresh index by updating list of deleted and appended source data files and | ||
| * index signature in index metadata. | ||
| * If some original source data file(s) are deleted or appended between previous | ||
| * version of index and now, this Action refreshes index as follows: | ||
| * 1. Deleted and appended source data files are identified. | ||
| * 2. New index fingerprint is computed w.r.t latest source data files. This captures | ||
| * both deleted source data files and appended ones. | ||
| * 3. IndexLogEntry is updated by modifying list of deleted and appended source data | ||
| * files and index fingerprint, computed in above steps. | ||
| * | ||
| * @param spark SparkSession. | ||
| * @param logManager Index LogManager for index being refreshed. | ||
| * @param dataManager Index DataManager for index being refreshed. | ||
| */ | ||
| class RefreshSourceContentAction( | ||
| spark: SparkSession, | ||
| logManager: IndexLogManager, | ||
| dataManager: IndexDataManager) | ||
| extends RefreshDeleteActionBase(spark, logManager, dataManager) | ||
| with Logging { | ||
|
|
||
| private lazy val newDeletedFiles: Seq[String] = | ||
| sourceFilesDiff._1 diff previousIndexLogEntry.deletedFiles | ||
|
|
||
| private lazy val newAppendedFiles: Seq[String] = | ||
| sourceFilesDiff._2 diff previousIndexLogEntry.appendedFiles | ||
|
|
||
| final override protected def event(appInfo: AppInfo, message: String): HyperspaceEvent = { | ||
| RefreshSourceContentActionEvent(appInfo, logEntry.asInstanceOf[IndexLogEntry], message) | ||
| } | ||
|
|
||
| override def validate(): Unit = { | ||
| super.validate() | ||
| if (newDeletedFiles.isEmpty && newAppendedFiles.isEmpty) { | ||
| throw HyperspaceException( | ||
| "Refresh aborted as no new deleted or appended source data file found.") | ||
| } | ||
| } | ||
|
|
||
| final override def op(): Unit = { | ||
| logInfo( | ||
| "Refresh index is updating index metadata by adding " + | ||
| s"${newDeletedFiles.length} new files to the list of deleted source data files and " + | ||
| s"${newAppendedFiles.length} new files to the list of appended source data files.") | ||
| } | ||
|
|
||
| /** | ||
| * Compute new index fingerprint using latest source data files and create | ||
| * new IndexLogEntry with updated list of deleted and appended source data | ||
| * files and new index fingerprint. | ||
| * | ||
| * @return Updated IndexLogEntry. | ||
| */ | ||
| final override def logEntry: LogEntry = { | ||
| // Compute index fingerprint using current source data file. | ||
| val signatureProvider = LogicalPlanSignatureProvider.create() | ||
| val newSignature = signatureProvider.signature(df.queryExecution.optimizedPlan) match { | ||
| case Some(s) => | ||
| LogicalPlanFingerprint( | ||
| LogicalPlanFingerprint.Properties(Seq(Signature(signatureProvider.name, s)))) | ||
|
|
||
| case None => throw HyperspaceException("Invalid source plan found during index refresh.") | ||
| } | ||
|
|
||
| // Grab nested structures from previous IndexLogEntry. | ||
| val source = previousIndexLogEntry.source | ||
| val plan = source.plan | ||
| val planProps = plan.properties | ||
| val relation = planProps.relations.head | ||
| val data = relation.data | ||
| val dataProps = data.properties | ||
| val deleted = dataProps.deleted | ||
| val appended = dataProps.appended | ||
|
|
||
| // Create a new IndexLogEntry by updating deleted files and fingerprint. | ||
| previousIndexLogEntry.copy( | ||
| source = source.copy( | ||
| plan = plan.copy( | ||
| properties = planProps.copy( | ||
| fingerprint = newSignature, | ||
| relations = Seq( | ||
| relation.copy( | ||
| data = data.copy( | ||
| properties = dataProps.copy( | ||
| deleted = deleted ++ newDeletedFiles, | ||
| appended = appended ++ newAppendedFiles)))))))) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
To Reviewers:
validateis moved to (new) classRefreshDeleteActionBase.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.
Cool, thanks for letting us know.