You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2014/04/14 18:16:42 UTC

[1/2] git commit: Updated protobuf::read to support reading from pipe, socket or FIFO.

Repository: mesos
Updated Branches:
  refs/heads/master 48dd007c4 -> 9e9bf44c7


Updated protobuf::read to support reading from pipe, socket or FIFO.

Updates stout's protobuf::read by introducing the "undoFailed" flag
which should be set towards false (default) on file descriptors that
are connected to a pipe, socket or FIFO. This flag may be set towards
true on file descriptors supporting random access, enabling seek
position reverting (aka undoing) on failed read attempts.

Review: https://reviews.apache.org/r/20216


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/012818ba
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/012818ba
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/012818ba

Branch: refs/heads/master
Commit: 012818ba1e7e22c7183d8dfeee40dba08f328e66
Parents: 48dd007
Author: Till Toenshoff <to...@me.com>
Authored: Sun Apr 13 22:14:21 2014 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Apr 13 22:14:21 2014 -0700

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/protobuf.hpp   | 49 ++++++++++++++------
 1 file changed, 35 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/012818ba/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
index 36b7f1a..ea5665a 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
@@ -96,26 +96,40 @@ inline Try<Nothing> write(
 // the "size" followed by the contents (as written by 'write' above).
 // If 'ignorePartial' is true, None() is returned when we unexpectedly
 // hit EOF while reading the protobuf (e.g., partial write).
+// If 'undoFailed' is true, failed read attempts will restore the file
+// read/write file offset towards the initial callup position.
 template <typename T>
-inline Result<T> read(int fd, bool ignorePartial = false)
+inline Result<T> read(
+    int fd,
+    bool ignorePartial = false,
+    bool undoFailed = false)
 {
-  // Save the offset so we can re-adjust if something goes wrong.
-  off_t offset = lseek(fd, 0, SEEK_CUR);
-  if (offset == -1) {
-    return ErrnoError("Failed to lseek to SEEK_CUR");
+  off_t offset = 0;
+
+  if (undoFailed) {
+    // Save the offset so we can re-adjust if something goes wrong.
+    offset = lseek(fd, 0, SEEK_CUR);
+    if (offset == -1) {
+      return ErrnoError("Failed to lseek to SEEK_CUR");
+    }
   }
 
   uint32_t size;
   Result<std::string> result = os::read(fd, sizeof(size));
 
   if (result.isError()) {
-    lseek(fd, offset, SEEK_SET);
+    if (undoFailed) {
+      lseek(fd, offset, SEEK_SET);
+    }
     return Error("Failed to read size: " + result.error());
   } else if (result.isNone()) {
     return None(); // No more protobufs to read.
   } else if (result.get().size() < sizeof(size)) {
-    // Hit EOF unexpectedly. Restore the offset to before the size read.
-    lseek(fd, offset, SEEK_SET);
+    // Hit EOF unexpectedly.
+    if (undoFailed) {
+      // Restore the offset to before the size read.
+      lseek(fd, offset, SEEK_SET);
+    }
     if (ignorePartial) {
       return None();
     }
@@ -132,12 +146,17 @@ inline Result<T> read(int fd, bool ignorePartial = false)
   result = os::read(fd, size);
 
   if (result.isError()) {
-    // Restore the offset to before the size read.
-    lseek(fd, offset, SEEK_SET);
+    if (undoFailed) {
+      // Restore the offset to before the size read.
+      lseek(fd, offset, SEEK_SET);
+    }
     return Error("Failed to read message: " + result.error());
   } else if (result.isNone() || result.get().size() < size) {
-    // Hit EOF unexpectedly. Restore the offset to before the size read.
-    lseek(fd, offset, SEEK_SET);
+    // Hit EOF unexpectedly.
+    if (undoFailed) {
+      // Restore the offset to before the size read.
+      lseek(fd, offset, SEEK_SET);
+    }
     if (ignorePartial) {
       return None();
     }
@@ -154,8 +173,10 @@ inline Result<T> read(int fd, bool ignorePartial = false)
   google::protobuf::io::ArrayInputStream stream(data.data(), data.size());
 
   if (!message.ParseFromZeroCopyStream(&stream)) {
-    // Restore the offset to before the size read.
-    lseek(fd, offset, SEEK_SET);
+    if (undoFailed) {
+      // Restore the offset to before the size read.
+      lseek(fd, offset, SEEK_SET);
+    }
     return Error("Failed to deserialize message");
   }
 


[2/2] git commit: Updated uses of protobuf::read towards explicit undo where needed.

Posted by be...@apache.org.
Updated uses of protobuf::read towards explicit undo where needed.

Review: https://reviews.apache.org/r/20237


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9e9bf44c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9e9bf44c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9e9bf44c

Branch: refs/heads/master
Commit: 9e9bf44c706f004ac9fda79b82afeac00b484941
Parents: 012818b
Author: Till Toenshoff <to...@me.com>
Authored: Sun Apr 13 22:17:23 2014 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Apr 13 22:17:23 2014 -0700

----------------------------------------------------------------------
 src/slave/state.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/9e9bf44c/src/slave/state.cpp
----------------------------------------------------------------------
diff --git a/src/slave/state.cpp b/src/slave/state.cpp
index 21d1fb7..a2af33c 100644
--- a/src/slave/state.cpp
+++ b/src/slave/state.cpp
@@ -578,8 +578,9 @@ Try<TaskState> TaskState::recover(
   // Now, read the updates.
   Result<StatusUpdateRecord> record = None();
   while (true) {
-    // Ignore errors due to partial protobuf read.
-    record = ::protobuf::read<StatusUpdateRecord>(fd.get(), true);
+    // Ignore errors due to partial protobuf read and enable undoing
+    // failed reads by reverting to the previous seek position.
+    record = ::protobuf::read<StatusUpdateRecord>(fd.get(), true, true);
 
     if (!record.isSome()) {
       break;