[ 
https://issues.apache.org/jira/browse/FLUME-2973?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16497883#comment-16497883
 ] 

Peter Turcsanyi commented on FLUME-2973:
----------------------------------------

The original patch ([^FLUME-2973.patch]) seems better to me, because in that 
solution the order of acquiring / releasing the locks and the scope of the 
locks are the same from both sides (both in {{HDFSEventSink}} and in 
{{BucketWriter}}):
 # acquiring lock on {{sfWriters}} map
 # acquiring lock on {{BucketWriter}} instance
 # releasing {{BucketWriter}} instance lock
 # releasing {{sfWriters}} map lock

This was the original order in {{HDFSEventSink}} and the {{BucketWriter}} 
implementation has been adjusted to it in [^FLUME-2973.patch].

The other patch ([^FLUME-2973-1.patch]) resolves the deadlock through 
reordering the locking in {{BucketWriter}}, but in a different way as it was/is 
in {{HDFSEventSink}}:
 # acquiring lock on {{sfWriters}} map
 # releasing {{sfWriters}} map lock
 # acquiring lock on {{BucketWriter}} instance
 # releasing {{BucketWriter}} instance lock

This solution prevents the deadlock too, but the different locking order might 
lead to side effects / changed functionality.

For this reason, I would vote for [^FLUME-2973.patch].

However, it would be worth applying the test clean-up ({{BucketWriterBuilder}}) 
fromĀ [^FLUME-2973-1.patch].

> Deadlock in hdfs sink
> ---------------------
>
>                 Key: FLUME-2973
>                 URL: https://issues.apache.org/jira/browse/FLUME-2973
>             Project: Flume
>          Issue Type: Bug
>          Components: Sinks+Sources
>    Affects Versions: 1.7.0
>            Reporter: Denes Arvay
>            Assignee: Denes Arvay
>            Priority: Critical
>              Labels: hdfssink
>             Fix For: 1.9.0
>
>         Attachments: FLUME-2973-1.patch, FLUME-2973.patch
>
>
> Automatic close of BucketWriters (when open file count reached 
> {{hdfs.maxOpenFiles}}) and the file rolling thread can end up in deadlock.
> When creating a new {{BucketWriter}} in {{HDFSEventSink}} it locks 
> {{HDFSEventSink.sfWritersLock}} and the {{close()}} called in 
> {{HDFSEventSink.sfWritersLock.removeEldestEntry}} tries to lock the 
> {{BucketWriter}} instance.
> On the other hand if the file is being rolled in 
> {{BucketWriter.close(boolean)}} it locks the {{BucketWriter}} instance first 
> and in the close callback it tries to lock the {{sfWritersLock}}.
> The chances for this deadlock is higher when the {{hdfs.maxOpenFiles}}'s 
> value is low (1).
> Script to reproduce: 
> https://gist.github.com/adenes/96503a6e737f9604ab3ee9397a5809ff
> (put to 
> {{flume-ng-sinks/flume-hdfs-sink/src/main/java/org/apache/flume/sink/hdfs}})
> Deadlock usually occurs before ~30 iterations.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to