-
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?
Fix a bug in loadTasks which wasn't abiding by compare-and-swap semantics when updating TaskEntities #1134
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1966,9 +1966,12 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( | |
}, | ||
Function.identity()); | ||
|
||
List<PolarisBaseEntity> loadedTasks = new ArrayList<>(); | ||
availableTasks.forEach( | ||
task -> { | ||
PolarisBaseEntity originalTask = new PolarisBaseEntity(task); | ||
// Make a copy to avoid mutating someone else's reference. | ||
// TODO: Refactor into immutable/Builder pattern. | ||
PolarisBaseEntity updatedTask = new PolarisBaseEntity(task); | ||
Map<String, String> properties = | ||
PolarisObjectMapperUtil.deserializeProperties(callCtx, task.getProperties()); | ||
properties.put(PolarisTaskConstants.LAST_ATTEMPT_EXECUTOR_ID, executorId); | ||
|
@@ -1980,11 +1983,22 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( | |
String.valueOf( | ||
Integer.parseInt(properties.getOrDefault(PolarisTaskConstants.ATTEMPT_COUNT, "0")) | ||
+ 1)); | ||
task.setEntityVersion(task.getEntityVersion() + 1); | ||
task.setProperties(PolarisObjectMapperUtil.serializeProperties(callCtx, properties)); | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, |
||
if (result.getReturnStatus() == BaseResult.ReturnStatus.SUCCESS) { | ||
loadedTasks.add(result.getEntity()); | ||
} else { | ||
// TODO: Consider performing incremental leasing of individual tasks one at a time | ||
// instead of requiring all-or-none semantics for all the tasks we think we listed, | ||
// or else contention could be very bad. | ||
ms.rollback(); | ||
throw new RetryOnConcurrencyException( | ||
"Failed to lease available task with status %s, info: %s", | ||
result.getReturnStatus(), result.getExtraInformation()); | ||
} | ||
}); | ||
return new EntitiesResult(availableTasks); | ||
return new EntitiesResult(loadedTasks); | ||
} | ||
|
||
@Override | ||
|
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