You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by bo...@apache.org on 2016/02/01 14:09:34 UTC
[1/2] hadoop git commit: HDFS-9679: Fix inconsistencies with libhdfs
C API. Contributed by James Clampffer
Repository: hadoop
Updated Branches:
refs/heads/HDFS-8707 6df167c85 -> 2e0dd25cb
HDFS-9679: Fix inconsistencies with libhdfs C API. Contributed by James Clampffer
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/b0485f0a
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/b0485f0a
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/b0485f0a
Branch: refs/heads/HDFS-8707
Commit: b0485f0a02c7088a209617c8714e603532f282ae
Parents: 6df167c
Author: Bob Hansen <bo...@hp.com>
Authored: Mon Feb 1 07:49:41 2016 -0500
Committer: Bob Hansen <bo...@hp.com>
Committed: Mon Feb 1 07:49:41 2016 -0500
----------------------------------------------------------------------
.../main/native/libhdfspp/lib/bindings/c/hdfs.cc | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/b0485f0a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/bindings/c/hdfs.cc
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/bindings/c/hdfs.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/bindings/c/hdfs.cc
index d5b5d6e..3262c66 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/bindings/c/hdfs.cc
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/bindings/c/hdfs.cc
@@ -121,6 +121,9 @@ static int Error(const Status &stat) {
case Status::Code::kException:
ReportError(EINTR, "Exception raised");
break;
+ case Status::Code::kOperationCanceled:
+ ReportError(EINTR, "Operation canceled");
+ break;
default:
ReportError(ENOSYS, "Error: unrecognised code");
}
@@ -147,9 +150,9 @@ bool CheckSystemAndHandle(hdfsFS fs, hdfsFile file) {
int hdfsFileIsOpenForRead(hdfsFile file) {
/* files can only be open for reads at the moment, do a quick check */
if (file) {
- return true; // Update implementation when we get file writing
+ return 1; // Update implementation when we get file writing
}
- return false;
+ return 0;
}
hdfsFS hdfsConnect(const char *nn, tPort port) {
@@ -239,6 +242,7 @@ tSize hdfsRead(hdfsFS fs, hdfsFile file, void *buffer, tSize length) {
return (tSize)len;
}
+/* 0 on success, -1 on error*/
int hdfsSeek(hdfsFS fs, hdfsFile file, tOffset desiredPos) {
if (!CheckSystemAndHandle(fs, file)) {
return -1;
@@ -250,7 +254,7 @@ int hdfsSeek(hdfsFS fs, hdfsFile file, tOffset desiredPos) {
return Error(stat);
}
- return (int)desired;
+ return 0;
}
tOffset hdfsTell(hdfsFS fs, hdfsFile file) {
@@ -267,6 +271,7 @@ tOffset hdfsTell(hdfsFS fs, hdfsFile file) {
return offset;
}
+/* extended API */
int hdfsCancel(hdfsFS fs, hdfsFile file) {
if (!CheckSystemAndHandle(fs, file)) {
return -1;
@@ -340,10 +345,7 @@ int hdfsBuilderConfSetStr(struct hdfsBuilder *bld, const char *key,
void hdfsConfStrFree(char *val)
{
- if (val)
- {
- free(val);
- }
+ free(val);
}
hdfsFS hdfsBuilderConnect(struct hdfsBuilder *bld) {
[2/2] hadoop git commit: HDFS-9712. libhdfs++: Reimplement Status
object as a normal struct
Posted by bo...@apache.org.
HDFS-9712. libhdfs++: Reimplement Status object as a normal struct
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/2e0dd25c
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/2e0dd25c
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/2e0dd25c
Branch: refs/heads/HDFS-8707
Commit: 2e0dd25cbab627493e6c60f488adaac3f92a583f
Parents: b0485f0
Author: Bob Hansen <bo...@hp.com>
Authored: Mon Feb 1 07:57:29 2016 -0500
Committer: Bob Hansen <bo...@hp.com>
Committed: Mon Feb 1 07:57:29 2016 -0500
----------------------------------------------------------------------
.../native/libhdfspp/include/hdfspp/status.h | 68 +++++------------
.../main/native/libhdfspp/lib/common/status.cc | 80 ++++++++++++--------
2 files changed, 64 insertions(+), 84 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/2e0dd25c/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/include/hdfspp/status.h
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/include/hdfspp/status.h b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/include/hdfspp/status.h
index 89be771..a91ac9d 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/include/hdfspp/status.h
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/include/hdfspp/status.h
@@ -23,43 +23,30 @@
namespace hdfs {
-class StatusHelper;
class Status {
public:
// Create a success status.
- Status() : state_(NULL) { }
- ~Status() { delete[] state_; }
- explicit Status(int code, const char *msg);
+ Status() : code_(0) {};
+ Status(int code, const char *msg);
+ Status(int code, const char *msg1, const char *msg2);
- // Copy the specified status.
- Status(const Status& s);
- void operator=(const Status& s);
+ // Factory methods
+ static Status OK();
+ static Status InvalidArgument(const char *msg);
+ static Status ResourceUnavailable(const char *msg);
+ static Status Unimplemented();
+ static Status Exception(const char *expception_class_name, const char *error_message);
+ static Status Error(const char *error_message);
+ static Status Canceled();
- // Return a success status.
- static Status OK() { return Status(); }
- static Status InvalidArgument(const char *msg)
- { return Status(kInvalidArgument, msg); }
- static Status ResourceUnavailable(const char *msg)
- { return Status(kResourceUnavailable, msg); }
- static Status Unimplemented()
- { return Status(kUnimplemented, ""); }
- static Status Exception(const char *expception_class_name, const char *error_message)
- { return Status(kException, expception_class_name, error_message); }
- static Status Error(const char *error_message)
- { return Exception("Exception", error_message); }
- static Status Canceled()
- { return Status(kOperationCanceled,""); }
+ // success
+ bool ok() const { return code_ == 0; }
- // Returns true iff the status indicates success.
- bool ok() const { return (state_ == NULL); }
-
- // Return a string representation of this status suitable for printing.
// Returns the string "OK" for success.
std::string ToString() const;
- int code() const {
- return (state_ == NULL) ? kOk : static_cast<int>(state_[4]);
- }
+ // get error code
+ int code() const { return code_; }
enum Code {
kOk = 0,
@@ -71,31 +58,10 @@ class Status {
};
private:
- // OK status has a NULL state_. Otherwise, state_ is a new[] array
- // of the following form:
- // state_[0..3] == length of message
- // state_[4] == code
- // state_[5..] == message
- const char* state_;
-
- explicit Status(int code, const char *msg1, const char *msg2);
- static const char *CopyState(const char* s);
- static const char *ConstructState(int code, const char *msg1, const char *msg2);
+ int code_;
+ std::string msg_;
};
-inline Status::Status(const Status& s) {
- state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
-}
-
-inline void Status::operator=(const Status& s) {
- // The following condition catches both aliasing (when this == &s),
- // and the common case where both s and *this are ok.
- if (state_ != s.state_) {
- delete[] state_;
- state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
- }
-}
-
}
#endif
http://git-wip-us.apache.org/repos/asf/hadoop/blob/2e0dd25c/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/status.cc
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/status.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/status.cc
index 828f6aa..eb22247 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/status.cc
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/status.cc
@@ -19,48 +19,62 @@
#include "hdfspp/status.h"
#include <cassert>
-#include <cstring>
+#include <sstream>
namespace hdfs {
-Status::Status(int code, const char *msg1)
- : state_(ConstructState(code, msg1, nullptr)) {}
-
-Status::Status(int code, const char *msg1, const char *msg2)
- : state_(ConstructState(code, msg1, msg2)) {}
-
-const char *Status::ConstructState(int code, const char *msg1,
- const char *msg2) {
- assert(code != kOk);
- const uint32_t len1 = strlen(msg1);
- const uint32_t len2 = msg2 ? strlen(msg2) : 0;
- const uint32_t size = len1 + (len2 ? (2 + len2) : 0);
- char *result = new char[size + 8 + 2];
- *reinterpret_cast<uint32_t *>(result) = size;
- *reinterpret_cast<uint32_t *>(result + 4) = code;
- memcpy(result + 8, msg1, len1);
- if (len2) {
- result[8 + len1] = ':';
- result[9 + len1] = ' ';
- memcpy(result + 10 + len1, msg2, len2);
+Status::Status(int code, const char *msg1) : code_(code) {
+ if(msg1) {
+ msg_ = msg1;
}
- return result;
}
+Status::Status(int code, const char *msg1, const char *msg2) : code_(code) {
+ std::stringstream ss;
+ if(msg1) {
+ ss << msg1;
+ if(msg2) {
+ ss << ":" << msg2;
+ }
+ }
+ msg_ = ss.str();
+}
+
+
+Status Status::OK() {
+ return Status();
+}
+
+Status Status::InvalidArgument(const char *msg) {
+ return Status(kInvalidArgument, msg);
+}
+
+Status Status::ResourceUnavailable(const char *msg) {
+ return Status(kResourceUnavailable, msg);
+}
+
+Status Status::Unimplemented() {
+ return Status(kUnimplemented, "");
+}
+
+Status Status::Exception(const char *exception_class_name, const char *error_message) {
+ return Status(kException, exception_class_name, error_message);
+}
+
+Status Status::Error(const char *error_message) {
+ return Exception("Exception", error_message);
+}
+
+Status Status::Canceled() {
+ return Status(kOperationCanceled,"Operation canceled");
+}
+
+
std::string Status::ToString() const {
- if (!state_) {
+ if (code_ == kOk) {
return "OK";
- } else {
- uint32_t length = *reinterpret_cast<const uint32_t *>(state_);
- return std::string(state_ + 8, length);
}
+ return msg_;
}
-const char *Status::CopyState(const char *state) {
- uint32_t size;
- memcpy(&size, state, sizeof(size));
- char *result = new char[size + 8];
- memcpy(result, state, size + 8);
- return result;
-}
}