about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-12-09 11:35:25 +0000
committerEric Wong <normalperson@yhbt.net>2011-12-09 11:47:01 +0000
commit83aa5dede6f0f9b04a631d0875d3e4d4f7927a8c (patch)
tree7fe3ee8020d3a864cf3ebf61196b67170b9c447f
parent01c200204400c4373c5b5edeb11d1c70a8119795 (diff)
downloadmogilefs-client-83aa5dede6f0f9b04a631d0875d3e4d4f7927a8c.tar.gz
An upload could've taken a long time, ping and try to ensure
socket is valid to minimize (but not completely eliminate) the
chance create_close hits a stale socket (while reading the
response after writing to it) and becomes non-retryable.  We
treat create_close specially as its less idempotent than any
other command (even other non-idempotent ones).  There may be no
hope of retrying the upload at all if data was streamed and
calling create_close twice will hurt us...
-rw-r--r--lib/mogilefs/backend.rb1
-rw-r--r--lib/mogilefs/new_file_common.rb14
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/mogilefs/backend.rb b/lib/mogilefs/backend.rb
index b48764c..e546350 100644
--- a/lib/mogilefs/backend.rb
+++ b/lib/mogilefs/backend.rb
@@ -98,6 +98,7 @@ class MogileFS::Backend
   add_command :create_open
   add_command :create_close
   add_idempotent_command :get_paths
+  add_idempotent_command :noop
   add_command :delete
   add_idempotent_command :sleep
   add_command :rename
diff --git a/lib/mogilefs/new_file_common.rb b/lib/mogilefs/new_file_common.rb
index c0bdc81..9db6aec 100644
--- a/lib/mogilefs/new_file_common.rb
+++ b/lib/mogilefs/new_file_common.rb
@@ -48,7 +48,19 @@ module MogileFS::NewFileCommon
       args[:checksum] = "MD5:#{hex}"
     end
     args[:checksumverify] = 1 if @opts[:checksumverify]
-    @opts[:backend].create_close(args)
+    backend = @opts[:backend]
+
+    # upload could've taken a long time, ping and try to ensure socket
+    # is valid to minimize (but not completely eliminate) the chance
+    # create_close hits a stale socket (while reading the response after
+    # writing to it) and becomes non-retryable.  We treat create_close
+    # specially as its less idempotent than any other command
+    # (even other non-idempotent ones).  There may be no hope of retrying
+    # the upload at all if data was streamed and calling create_close
+    # twice will hurt us...
+    backend.noop
+
+    backend.create_close(args)
     bytes_uploaded
   end