-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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-51596][SS] Fix concurrent StateStoreProvider maintenance and closing #50391
Open
liviazhu-db
wants to merge
3
commits into
apache:master
Choose a base branch
from
liviazhu-db:liviazhu-db/stack/lock-hardening
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 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 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 | ||||
---|---|---|---|---|---|---|
|
@@ -122,6 +122,38 @@ private object FakeStateStoreProviderWithMaintenanceError { | |||||
val errorOnMaintenance = new AtomicBoolean(false) | ||||||
} | ||||||
|
||||||
class FakeStateStoreProviderTracksCloseThread extends StateStoreProvider { | ||||||
import FakeStateStoreProviderTracksCloseThread._ | ||||||
private var id: StateStoreId = null | ||||||
|
||||||
override def init( | ||||||
stateStoreId: StateStoreId, | ||||||
keySchema: StructType, | ||||||
valueSchema: StructType, | ||||||
keyStateEncoderSpec: KeyStateEncoderSpec, | ||||||
useColumnFamilies: Boolean, | ||||||
storeConfs: StateStoreConf, | ||||||
hadoopConf: Configuration, | ||||||
useMultipleValuesPerKey: Boolean = false, | ||||||
stateSchemaProvider: Option[StateSchemaProvider] = None): Unit = { | ||||||
id = stateStoreId | ||||||
} | ||||||
|
||||||
override def stateStoreId: StateStoreId = id | ||||||
|
||||||
override def close(): Unit = { | ||||||
closeThreadNames = Thread.currentThread.getName :: closeThreadNames | ||||||
} | ||||||
|
||||||
override def getStore(version: Long, uniqueId: Option[String]): StateStore = null | ||||||
|
||||||
override def doMaintenance(): Unit = {} | ||||||
} | ||||||
|
||||||
private object FakeStateStoreProviderTracksCloseThread { | ||||||
var closeThreadNames: List[String] = Nil | ||||||
} | ||||||
|
||||||
@ExtendedSQLTest | ||||||
class StateStoreSuite extends StateStoreSuiteBase[HDFSBackedStateStoreProvider] | ||||||
with BeforeAndAfter { | ||||||
|
@@ -563,8 +595,11 @@ class StateStoreSuite extends StateStoreSuiteBase[HDFSBackedStateStoreProvider] | |||||
StateStore.get(storeProviderId2, keySchema, valueSchema, | ||||||
NoPrefixKeyStateEncoderSpec(keySchema), | ||||||
0, None, None, useColumnFamilies = false, storeConf, hadoopConf) | ||||||
assert(!StateStore.isLoaded(storeProviderId1)) | ||||||
assert(StateStore.isLoaded(storeProviderId2)) | ||||||
// Close runs asynchronously, so we need to call eventually with a small timeout | ||||||
eventually(timeout(5.seconds)) { | ||||||
assert(!StateStore.isLoaded(storeProviderId1)) | ||||||
assert(StateStore.isLoaded(storeProviderId2)) | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -1082,7 +1117,7 @@ class StateStoreSuite extends StateStoreSuiteBase[HDFSBackedStateStoreProvider] | |||||
} | ||||||
|
||||||
abstract class StateStoreSuiteBase[ProviderClass <: StateStoreProvider] | ||||||
extends StateStoreCodecsTest with PrivateMethodTester { | ||||||
extends StateStoreCodecsTest with PrivateMethodTester with BeforeAndAfter { | ||||||
import StateStoreTestsHelper._ | ||||||
|
||||||
type MapType = mutable.HashMap[UnsafeRow, UnsafeRow] | ||||||
|
@@ -1718,6 +1753,60 @@ abstract class StateStoreSuiteBase[ProviderClass <: StateStoreProvider] | |||||
assert(encoderSpec == deserializedEncoderSpec) | ||||||
} | ||||||
|
||||||
test("SPARK-51596: unloading only occurs on maintenance thread but occurs promptly") { | ||||||
// Reset closeThreadNames | ||||||
FakeStateStoreProviderTracksCloseThread.closeThreadNames = Nil | ||||||
|
||||||
val sqlConf = getDefaultSQLConf( | ||||||
SQLConf.STATE_STORE_MIN_DELTAS_FOR_SNAPSHOT.defaultValue.get, | ||||||
SQLConf.MAX_BATCHES_TO_RETAIN_IN_MEMORY.defaultValue.get | ||||||
) | ||||||
// Make maintenance interval very large (30s) so that task thread runs before maintenance. | ||||||
sqlConf.setConf(SQLConf.STREAMING_MAINTENANCE_INTERVAL, 30000L) | ||||||
// Use the `MaintenanceErrorOnCertainPartitionsProvider` to run the test | ||||||
sqlConf.setConf( | ||||||
SQLConf.STATE_STORE_PROVIDER_CLASS, | ||||||
classOf[FakeStateStoreProviderTracksCloseThread].getName | ||||||
) | ||||||
|
||||||
val conf = new SparkConf().setMaster("local").setAppName("test") | ||||||
|
||||||
withSpark(SparkContext.getOrCreate(conf)) { sc => | ||||||
withCoordinatorRef(sc) { coordinatorRef => | ||||||
val rootLocation = s"${Utils.createTempDir().getAbsolutePath}/spark-48997" | ||||||
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
Suggested change
|
||||||
val providerId = | ||||||
StateStoreProviderId(StateStoreId(rootLocation, 0, 0), UUID.randomUUID) | ||||||
val providerId2 = | ||||||
StateStoreProviderId(StateStoreId(rootLocation, 0, 1), UUID.randomUUID) | ||||||
|
||||||
// Create provider to start the maintenance task + pool | ||||||
StateStore.get( | ||||||
providerId, | ||||||
keySchema, valueSchema, NoPrefixKeyStateEncoderSpec(keySchema), | ||||||
0, None, None, useColumnFamilies = false, new StateStoreConf(sqlConf), new Configuration() | ||||||
) | ||||||
|
||||||
// Report instance active on another executor | ||||||
coordinatorRef.reportActiveInstance(providerId, "otherhost", "otherexec", Seq.empty) | ||||||
|
||||||
// Load another provider to trigger task unload | ||||||
StateStore.get( | ||||||
providerId2, | ||||||
keySchema, valueSchema, NoPrefixKeyStateEncoderSpec(keySchema), | ||||||
0, None, None, useColumnFamilies = false, new StateStoreConf(sqlConf), new Configuration() | ||||||
) | ||||||
|
||||||
// Wait for close to occur. Timeout is less than maintenance interval, | ||||||
// so should only close by task triggering. | ||||||
eventually(timeout(5.seconds)) { | ||||||
assert(FakeStateStoreProviderTracksCloseThread.closeThreadNames.size == 1) | ||||||
FakeStateStoreProviderTracksCloseThread.closeThreadNames.foreach { name => | ||||||
assert(name.contains("state-store-maintenance-thread"))} | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
/** Return a new provider with a random id */ | ||||||
def newStoreProvider(): ProviderClass | ||||||
|
||||||
|
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 - this seems copied from below -- this should now be
FakeStateStoreProviderTracksCloseThread
right?