-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-14214][SQL] Update state to provide get/put interface #12013
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,7 +81,7 @@ private[state] class HDFSBackedStateStoreProvider( | |
| trait STATE | ||
| case object UPDATING extends STATE | ||
| case object COMMITTED extends STATE | ||
| case object CANCELLED extends STATE | ||
| case object ABORTED extends STATE | ||
|
|
||
| private val newVersion = version + 1 | ||
| private val tempDeltaFile = new Path(baseDir, s"temp-${Random.nextLong}") | ||
|
|
@@ -94,15 +94,14 @@ private[state] class HDFSBackedStateStoreProvider( | |
|
|
||
| override def id: StateStoreId = HDFSBackedStateStoreProvider.this.id | ||
|
|
||
| /** | ||
| * Update the value of a key using the value generated by the update function. | ||
| * @note Do not mutate the retrieved value row as it will unexpectedly affect the previous | ||
| * versions of the store data. | ||
| */ | ||
| override def update(key: UnsafeRow, updateFunc: Option[UnsafeRow] => UnsafeRow): Unit = { | ||
| verify(state == UPDATING, "Cannot update after already committed or cancelled") | ||
| val oldValueOption = Option(mapToUpdate.get(key)) | ||
| val value = updateFunc(oldValueOption) | ||
| override def get(key: UnsafeRow): Option[UnsafeRow] = { | ||
| Option(mapToUpdate.get(key)) | ||
| } | ||
|
|
||
| override def put(key: UnsafeRow, value: UnsafeRow): Unit = { | ||
| verify(state == UPDATING, "Cannot remove after already committed or cancelled") | ||
|
|
||
| val isNewKey = !mapToUpdate.containsKey(key) | ||
| mapToUpdate.put(key, value) | ||
|
|
||
| Option(allUpdates.get(key)) match { | ||
|
|
@@ -115,8 +114,7 @@ private[state] class HDFSBackedStateStoreProvider( | |
| case None => | ||
| // There was no prior update, so mark this as added or updated according to its presence | ||
| // in previous version. | ||
| val update = | ||
| if (oldValueOption.nonEmpty) ValueUpdated(key, value) else ValueAdded(key, value) | ||
| val update = if (isNewKey) ValueAdded(key, value) else ValueUpdated(key, value) | ||
| allUpdates.put(key, update) | ||
| } | ||
| writeToDeltaFile(tempDeltaFileStream, ValueUpdated(key, value)) | ||
|
|
@@ -148,7 +146,7 @@ private[state] class HDFSBackedStateStoreProvider( | |
|
|
||
| /** Commit all the updates that have been made to the store, and return the new version. */ | ||
| override def commit(): Long = { | ||
| verify(state == UPDATING, "Cannot commit again after already committed or cancelled") | ||
| verify(state == UPDATING, "Cannot commit after already committed or cancelled") | ||
|
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. nit: cancelled -> aborted |
||
|
|
||
| try { | ||
| finalizeDeltaFile(tempDeltaFileStream) | ||
|
|
@@ -164,8 +162,8 @@ private[state] class HDFSBackedStateStoreProvider( | |
| } | ||
|
|
||
| /** Cancel all the updates made on this store. This store will not be usable any more. */ | ||
| override def cancel(): Unit = { | ||
| state = CANCELLED | ||
| override def abort(): Unit = { | ||
| state = ABORTED | ||
| if (tempDeltaFileStream != null) { | ||
| tempDeltaFileStream.close() | ||
| } | ||
|
|
@@ -176,8 +174,8 @@ private[state] class HDFSBackedStateStoreProvider( | |
| } | ||
|
|
||
| /** | ||
| * Get an iterator of all the store data. This can be called only after committing the | ||
| * updates. | ||
| * Get an iterator of all the store data. | ||
| * This can be called only after committing all the updates made in the current thread. | ||
| */ | ||
| override def iterator(): Iterator[(UnsafeRow, UnsafeRow)] = { | ||
| verify(state == COMMITTED, "Cannot get iterator of store data before comitting") | ||
|
|
@@ -186,7 +184,7 @@ private[state] class HDFSBackedStateStoreProvider( | |
|
|
||
| /** | ||
| * Get an iterator of all the updates made to the store in the current version. | ||
| * This can be called only after committing the updates. | ||
| * This can be called only after committing all the updates made in the current thread. | ||
| */ | ||
| override def updates(): Iterator[StoreUpdate] = { | ||
| verify(state == COMMITTED, "Cannot get iterator of updates before committing") | ||
|
|
@@ -196,7 +194,7 @@ private[state] class HDFSBackedStateStoreProvider( | |
| /** | ||
| * Whether all updates have been committed | ||
| */ | ||
| override def hasCommitted: Boolean = { | ||
| override private[state] def hasCommitted: Boolean = { | ||
| state == COMMITTED | ||
| } | ||
| } | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,17 +54,10 @@ class StateStoreRDD[T: ClassTag, U: ClassTag]( | |
|
|
||
| override def compute(partition: Partition, ctxt: TaskContext): Iterator[U] = { | ||
| var store: StateStore = null | ||
|
|
||
| Utils.tryWithSafeFinally { | ||
| val storeId = StateStoreId(checkpointLocation, operatorId, partition.index) | ||
| store = StateStore.get( | ||
| storeId, keySchema, valueSchema, storeVersion, storeConf, confBroadcast.value.value) | ||
| val inputIter = dataRDD.iterator(partition, ctxt) | ||
| val outputIter = storeUpdateFunction(store, inputIter) | ||
| assert(store.hasCommitted) | ||
| outputIter | ||
| } { | ||
| if (store != null) store.cancel() | ||
| } | ||
| val storeId = StateStoreId(checkpointLocation, operatorId, partition.index) | ||
| store = StateStore.get( | ||
| storeId, keySchema, valueSchema, storeVersion, storeConf, confBroadcast.value.value) | ||
| val inputIter = dataRDD.iterator(partition, ctxt) | ||
| storeUpdateFunction(store, inputIter) | ||
|
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. The finally was removed to allow commits to be done lazily. |
||
| } | ||
| } | ||
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.
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.
nit: remove -> put