-
Notifications
You must be signed in to change notification settings - Fork 199
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
Fix a bug in loadTasks which wasn't abiding by compare-and-swap semantics when updating TaskEntities #1134
base: main
Are you sure you want to change the base?
Conversation
…tics when updating TaskEntities. Additionally, fix the PolarisTreeMapMetaStoreSessionImpl to avoid "cheating" by using its entire PolarisBaseEntit it happens to store in entitiesActive when performing a listing; in general, entitiesActive is assumed to *only* contain the name lookup records, so it is not explicitly updated unless a parent or name changes. The existing tests happened to pass because of a coincidence of several bugs: 1. Since the entitiesActive and entities happens to share the same PolarisBaseEntity instance by-reference, any in-place edits to "entities" *happens* to reflect in entitiesActive, but in general entities *should not be mutable* and usually a copy of an entity is mutated instead of mutating in place anyways 2. Because of the blind-writes in loadTasks, the "prepare entity" step where an instance is updated with a new entityVersion coincidentally immediately causes the main entities *and* entitiesAcitve slices to have the updated entity even before the call to writeEntity happens 3. Since TreeMap uses "synchronized" for runInTransaction, the loadTasksInParallel doesn't detect interleaving of threads So without the fix in the treemap store, simply fixing PolarisMetaStoreManagerImpl causes the test to run forever because tasks never get updated in entitiesActive so the same initial 5 tasks keep getting listed forever. Also fix the test to actually timeout eventually; the Future::get calls were willing to block forever before getting to the await. Reduce the wait time from 10 minutes to something more reasonable.
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.
The change LGTM, although I must admit I did not quite understand the original bug that it is supposed to fix 😅
ms.writeEntity(callCtx, task, false, originalTask); | ||
updatedTask.setProperties( | ||
PolarisObjectMapperUtil.serializeProperties(callCtx, properties)); | ||
EntityResult result = updateEntityPropertiesIfNotChanged(callCtx, ms, null, updatedTask); |
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.
Question: why do we need to update task entities in a "load" call?
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.
Yeah, loadTasks
probably is just a bad name. It is more correctly leaseTasks
. Should I rename in this PR?
@@ -1966,9 +1966,12 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( | |||
}, | |||
Function.identity()); | |||
|
|||
List<PolarisBaseEntity> loadedTasks = new ArrayList<>(); |
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.
This loadTasks
method appears to be called only from test code... Is that expected?
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.
I think @collado-mike had some plans for this. I believe it's what's needed next to have better than "best-effort in-memory attempt at cleanup of tables after purge".
For now I'm just trying to have the tests passing while implementing the NonTransactionalMetaStoreManager that also needs to support loadTasks
to pass the base MetaStoreManager test :)
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.
On the plus side, task-leasing happens to be the most intensive concurrency set of unittests we have, so this TaskEntity stuff was what helped discover the missing pieces and bugs in my NonTransactionalMetaStoreManager
implementation
Fix a bug in loadTasks which wasn't abiding by compare-and-swap semantics when updating TaskEntities
Additionally, fix the PolarisTreeMapMetaStoreSessionImpl to avoid "cheating" by using its entire PolarisBaseEntit it happens to store in entitiesActive when performing a listing; in general, entitiesActive is assumed to only contain the name lookup records, so it is not explicitly updated unless a parent or name changes.
The existing tests happened to pass because of a coincidence of several bugs:
So without the fix in the treemap store, simply fixing PolarisMetaStoreManagerImpl causes the test to run forever because tasks never get updated in entitiesActive so the same initial 5 tasks keep getting listed forever.
Also fix the test to actually timeout eventually; the Future::get calls were willing to block forever before getting to the await. Reduce the wait time from 10 minutes to something more reasonable.