incubator-uniffle icon indicating copy to clipboard operation
incubator-uniffle copied to clipboard

[BUGFIX] Fix flush event bug which cause app resource delete not clean

Open sfwang218 opened this issue 3 years ago • 7 comments

What changes were proposed in this pull request?

Modify the interface ShuffleWriteHandler

  • change the method "write", add a param "valid" which check whether the shuffleBlocks is valid

Why are the changes needed?

There is a bug when multi thread which use the same ShuffleWriteHandler flush event to storage concurrently.

for example:

  • there are two event with the same appId、shuffleId and partitionId in ShuffleFlushManager.flushQueue
  • because the same appId、shuffleId and partitionId, two event will get the same ShuffleWriteHandler in method ShuffleFlushManager.flushToFile 图片
  • as shown below, both them check is valid in the method ShuffleFlushManager.flushToFile 图片
  • suppose the writeHandler is instance of HdfsShuffleWriteHandler, when the first event execute method write the second event will be block 图片
  • the first event is executing write method while the app is expire, so the hdfs path will be deleted
  • then the second event will execute write method. Normally the shuffleBlocks of the second event will be Marked as invalid, but we don't check in this method, so the hdfs path will be recreated, and the second event will still flush to hdfs

to fix this bug, we should double chech the valid of the event, so I add add a param "valid" which check whether the shuffleBlocks is valid in method ShuffleWriteHandler.write.

Does this PR introduce any user-facing change?

No

How was this patch tested?

No need

sfwang218 avatar Aug 09 '22 14:08 sfwang218

Em....if we remove the app after we judge whether the event is valid, some app resource still won't be deleted. I feel that this pr don't solve the problems totally.

jerqi avatar Aug 09 '22 15:08 jerqi

Em....if we remove the app after we judge whether the event is valid, some app resource still won't be deleted. I feel that this pr don't solve the problems totally.

In this case, there are two situations:

  1. We judge the event is valid and the 'write' method is finished, and then we remove the app. In this way, the app resource will be deleted cleanly
  2. We judge the event is valid and the 'write' method is not finished, and then we remove the app. In this way, the 'write' method will throw exception because the shuffle file being written is deleted, and will retry later as shown below 图片 when the event retry, we will judge whether it is valid again as shown below 图片

In summary, i think this pr can solve the problems totally, I don't know if I'm right, Please correct.

sfwang218 avatar Aug 10 '22 02:08 sfwang218

If we remove the app, the progress run at the line https://github.com/apache/incubator-uniffle/blob/d5cb8ccf47fec2e90ed24d97e4fd687d07f0bcd4/storage/src/main/java/org/apache/uniffle/storage/handler/impl/LocalFileWriteHandler.java#L100, we won't delete the shuffle file totally.

jerqi avatar Aug 10 '22 14:08 jerqi

@sfwang218 For such problem, how about to check basePath before write, it was created when init handler and will be removed if app expired. I think it still will have the problem you mentioned caused by multi threads in some cases, but it's better to make the writer handler more independent. I prefer to add easy way for handler to check if the data should be written.

colinmjj avatar Aug 11 '22 03:08 colinmjj

If we remove the app, the progress run at the line

https://github.com/apache/incubator-uniffle/blob/d5cb8ccf47fec2e90ed24d97e4fd687d07f0bcd4/storage/src/main/java/org/apache/uniffle/storage/handler/impl/LocalFileWriteHandler.java#L100 , we won't delete the shuffle file totally.

Yes, It seems that this situation exists, do you have any suggestions?

sfwang218 avatar Aug 11 '22 03:08 sfwang218

Maybe a period thread to clean shuffle data is an alternative way.

colinmjj avatar Aug 11 '22 03:08 colinmjj

@sfwang218 For such problem, how about to check basePath before write, it was created when init handler and will be removed if app expired. I think it still will have the problem you mentioned caused by multi threads in some cases, but it's better to make the writer handler more independent. I prefer to add easy way for handler to check if the data should be written.

OK, It seems like a good idea, thx.

sfwang218 avatar Aug 11 '22 11:08 sfwang218

@sfwang218 Do you want to continue this pr? I raise a new issue https://github.com/apache/incubator-uniffle/issues/282 according to the problem which this pr mentioned. If you want to continue this pr, I will assign this issue to you.

jerqi avatar Oct 27 '22 07:10 jerqi

@sfwang218 Do you want to continue this pr? I raise a new issue #282 according to the problem which this pr mentioned. If you want to continue this pr, I will assign this issue to you.

OK, I want try

sfwang218 avatar Oct 27 '22 12:10 sfwang218

@sfwang218 Do you want to continue this pr? I raise a new issue #282 according to the problem which this pr mentioned. If you want to continue this pr, I will assign this issue to you.

OK, I want try

You need to comment the issue https://github.com/apache/incubator-uniffle/issues/282, otherwise I can't assign to you.

jerqi avatar Oct 27 '22 12:10 jerqi