yangwwei commented on a change in pull request #152:
URL: 
https://github.com/apache/incubator-yunikorn-core/pull/152#discussion_r428802247



##########
File path: pkg/cache/application_info.go
##########
@@ -73,6 +73,23 @@ func (ai *ApplicationInfo) GetAllAllocations() 
[]*AllocationInfo {
        return allocations
 }
 
+// Return the allocation for the allocation key. This will return the first 
allocation for the
+// allocation key. It will only work for the case that the repeat is 1.
+func (ai *ApplicationInfo) GetAllocationUUID(allocKey string) string {
+       ai.lock.RLock()
+       defer ai.lock.RUnlock()
+
+       // just get the first one, ignore multiple repeats for now.
+       // we cannot detect multiple repeats easily here.
+       for uuid, alloc := range ai.allocations {
+               if alloc.AllocationProto.AllocationKey == allocKey {
+                       return uuid
+               }
+       }
+       // not found return an empty string
+       return ""
+}
+

Review comment:
       > We have no proper support multiple repeats at the moment.
   
   I agree. But we should not break the semantics as much as possible.
   
   >In the proposed code of PR #151 you are not only cancelling the inflight 
allocation but also all confirmed allocations, that would be an unexpected 
behaviour of cancelling an ask.
   
   To get more consistency, we can do the following
   
   From the cache, it first generates the allocation, and then send exact same 
message to the scheduler for confirmation. along with the proposal itself. Each 
time it only handles one allocation for one proposal.
   
   ```
   
m.EventHandlers.SchedulerEventHandler.HandleEvent(&schedulerevent.SchedulerAllocationUpdatesEvent{
     AcceptedAllocations: []*schedulerevent.AcceptedAllocationProposal{
       {
         AllocationProposal: proposal,
         Allocation: allocInfo.AllocationProto,
       },
     },
   })
   ```
   
   In the scheduler, it processes the proposal, if it fails, notify cache to 
release the allocation:
   
   ```
   alloc := ev.AcceptedAllocations[0]
   // Update pending resource
   if err := s.confirmAllocationProposal(alloc.AllocationProposal); err != nil {
     log.Logger().Error("failed to confirm allocation proposal", zap.Error(err))
     // if the scheduler could not confirm the proposal,
     // we need to notify the cache to revert the allocations                   
 
    
s.eventHandlers.CacheEventHandler.HandleEvent(&cacheevent.ReleaseAllocationsEvent{
       AllocationsToRelease: []*commonevents.ReleaseAllocation{
         {
            UUID:          alloc.Allocation.UUID,
         ApplicationID: alloc.AllocationProposal.ApplicationID,
         PartitionName: alloc.AllocationProposal.PartitionName,
         Message:       "scheduler is unable to confirm the allocation",
         ReleaseType:   si.AllocationReleaseResponse_STOPPED_BY_RM,
         },
         },
     })
   }
   ```
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to