OK, i understood. It seemd that this works well.

But this code looks hard to understand. How do you think to fix here like this for simplicity?:

```ruby
def send_data(path, data)
  # @client.append or @client.create without any retries or any rescue of WebHDFS::IOError
end

def namenode_status(client)
  # do client.list('/') and returns true (success to get '/') or false (any failure raised)
end

def write(chunk)
  hdfs_path = path_format(...)
  failovered = false
  begin
    send_data(hdfs_path, chunk_read)
  rescue => e
    raise e if failovered
    if e.is_a?(WebHDFS::IOError) && e.is_ipc_StandbyException && namenode_status(@client_standby)
      failovered = true
      # failover immediately to secondary namenode
      # and retry begin block
    end
    if (@error_history.size + 1 >= @failure_before_use_standby) && namenode_status(@client_standby)
      failovered = true
      # failover and retry
    end
    raise  e
  end
  hdfs_path
end
```