Author: sbanacho
Date: Thu Oct 8 00:12:44 2009
New Revision: 822968
URL: http://svn.apache.org/viewvc?rev=822968&view=rev
Log:
AVRO-132. Fix multi-threading race condition when threads share schema objects.
Modified:
hadoop/avro/trunk/CHANGES.txt
hadoop/avro/trunk/src/c++/api/Boost.hh
hadoop/avro/trunk/src/c++/api/Node.hh
hadoop/avro/trunk/src/c++/api/ValidSchema.hh
hadoop/avro/trunk/src/c++/api/ValidatingReader.hh
hadoop/avro/trunk/src/c++/api/Validator.hh
hadoop/avro/trunk/src/c++/impl/NodeImpl.cc
hadoop/avro/trunk/src/c++/impl/ValidSchema.cc
hadoop/avro/trunk/src/c++/impl/ValidatingReader.cc
hadoop/avro/trunk/src/c++/impl/ValidatingWriter.cc
hadoop/avro/trunk/src/c++/impl/Validator.cc
Modified: hadoop/avro/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=822968&r1=822967&r2=822968&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Thu Oct 8 00:12:44 2009
@@ -70,6 +70,9 @@
BUG FIXES
+ AVRO-132. Fix multi-threading race condition when threads share schema
objects.
+ (sbanacho)
+
AVRO-113. Fix endian bug with C++ integer/long varint codec.
(Scott Banachowski via cutting)
Modified: hadoop/avro/trunk/src/c++/api/Boost.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/Boost.hh?rev=822968&r1=822967&r2=822968&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/Boost.hh (original)
+++ hadoop/avro/trunk/src/c++/api/Boost.hh Thu Oct 8 00:12:44 2009
@@ -55,7 +55,7 @@
typedef integral_constant<bool, true> true_type;
typedef integral_constant<bool, false> false_type;
-}
+} // namespace boost
#else
#include <boost/type_traits.hpp>
#endif // AVRO_BOOST_NO_TRAIT
@@ -93,7 +93,7 @@
private:
std::vector<T *> ptrs_;
};
-}
+} // namespace boost
#else
#include <boost/ptr_container/ptr_vector.hpp>
#endif // AVRO_BOOST_NO_PTRVECTOR
Modified: hadoop/avro/trunk/src/c++/api/Node.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/Node.hh?rev=822968&r1=822967&r2=822968&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/Node.hh (original)
+++ hadoop/avro/trunk/src/c++/api/Node.hh Thu Oct 8 00:12:44 2009
@@ -21,7 +21,7 @@
#include <cassert>
#include <boost/noncopyable.hpp>
-#include <boost/intrusive_ptr.hpp>
+#include <boost/shared_ptr.hpp>
#include "Exception.hh"
#include "Types.hh"
@@ -30,7 +30,7 @@
class Node;
-typedef boost::intrusive_ptr<Node> NodePtr;
+typedef boost::shared_ptr<Node> NodePtr;
/// Node is the building block for parse trees. Each node represents an avro
@@ -40,10 +40,9 @@
/// The user does not use the Node object directly, they interface with Schema
/// objects.
///
-/// The Node object has an embedded reference count for use in the
-/// boost::intrusive_ptr smart pointer. This is so that schemas may be reused
-/// in other other schemas, without needing to worry about memory deallocation
-/// for nodes that are added to multiple schema parse trees.
+/// The Node object uses reference-counted pointers. This is so that schemas
+/// may be reused in other other schemas, without needing to worry about memory
+/// deallocation for nodes that are added to multiple schema parse trees.
///
/// Node has minimal implementation, serving as an abstract base class for
/// different node types.
@@ -130,27 +129,11 @@
private:
- friend void intrusive_ptr_add_ref(Node *node);
- friend void intrusive_ptr_release(Node *node);
-
const Type type_;
int refCount_;
bool locked_;
};
-inline void
-intrusive_ptr_add_ref(Node *node) {
- ++(node->refCount_);
-}
-
-inline void
-intrusive_ptr_release(Node *node) {
- --(node->refCount_);
- if(node->refCount_ == 0) {
- delete node;
- }
-}
-
} // namespace avro
#endif
Modified: hadoop/avro/trunk/src/c++/api/ValidSchema.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/ValidSchema.hh?rev=822968&r1=822967&r2=822968&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/ValidSchema.hh (original)
+++ hadoop/avro/trunk/src/c++/api/ValidSchema.hh Thu Oct 8 00:12:44 2009
@@ -52,9 +52,9 @@
return node_;
}
- void toJson(std::ostream &os);
+ void toJson(std::ostream &os) const;
- void toFlatList(std::ostream &os);
+ void toFlatList(std::ostream &os) const;
NodePtr followSymbol(const std::string &name) const {
return symbolMap_.locateSymbol(name);
Modified: hadoop/avro/trunk/src/c++/api/ValidatingReader.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/ValidatingReader.hh?rev=822968&r1=822967&r2=822968&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/ValidatingReader.hh (original)
+++ hadoop/avro/trunk/src/c++/api/ValidatingReader.hh Thu Oct 8 00:12:44 2009
@@ -47,7 +47,7 @@
public:
- explicit ValidatingReader(const ValidSchema &schema, InputStreamer &in);
+ ValidatingReader(const ValidSchema &schema, InputStreamer &in);
template<typename T>
void getValue(T &val) {
Modified: hadoop/avro/trunk/src/c++/api/Validator.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/Validator.hh?rev=822968&r1=822967&r2=822968&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/Validator.hh (original)
+++ hadoop/avro/trunk/src/c++/api/Validator.hh Thu Oct 8 00:12:44 2009
@@ -42,7 +42,7 @@
public:
- Validator(const ValidSchema &schema);
+ explicit Validator(const ValidSchema &schema);
void advance();
void advanceWithCount(int64_t val);
@@ -80,7 +80,12 @@
void setupFlag(Type type);
const ValidSchema &schema_;
- NodePtr parseTree_;
+
+ // since this only keeps a reference to the schema, to ensure its parse
+ // tree is not deleted, keep a copy of a shared pointer to the root of the
+ // tree
+
+ const NodePtr parseTree_;
Type nextType_;
flag_t expectedTypesFlag_;
Modified: hadoop/avro/trunk/src/c++/impl/NodeImpl.cc
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/impl/NodeImpl.cc?rev=822968&r1=822967&r2=822968&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/impl/NodeImpl.cc (original)
+++ hadoop/avro/trunk/src/c++/impl/NodeImpl.cc Thu Oct 8 00:12:44 2009
@@ -159,36 +159,36 @@
switch(node.type()) {
case AVRO_ARRAY:
- ptr = ( new NodeArray(node));
+ ptr.reset ( new NodeArray(node));
break;
case AVRO_ENUM:
- ptr = ( new NodeEnum(node));
+ ptr.reset ( new NodeEnum(node));
break;
case AVRO_FIXED:
- ptr = ( new NodeFixed(node));
+ ptr.reset ( new NodeFixed(node));
break;
case AVRO_MAP:
- ptr = ( new NodeMap(node));
+ ptr.reset ( new NodeMap(node));
break;
case AVRO_RECORD:
- ptr = ( new NodeRecord(node));
+ ptr.reset ( new NodeRecord(node));
break;
case AVRO_UNION:
- ptr = ( new NodeUnion(node));
+ ptr.reset ( new NodeUnion(node));
break;
case AVRO_SYMBOLIC:
- ptr = ( new NodeSymbolic(node));
+ ptr.reset ( new NodeSymbolic(node));
break;
default:
if(isPrimitive(node.type())) {
- ptr = ( new NodePrimitive(node.type()));
+ ptr.reset ( new NodePrimitive(node.type()));
}
else {
throw Exception("Unknown type in nodeFromCompilerNode");
Modified: hadoop/avro/trunk/src/c++/impl/ValidSchema.cc
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/impl/ValidSchema.cc?rev=822968&r1=822967&r2=822968&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/impl/ValidSchema.cc (original)
+++ hadoop/avro/trunk/src/c++/impl/ValidSchema.cc Thu Oct 8 00:12:44 2009
@@ -46,7 +46,7 @@
ValidSchema::validate(const NodePtr &node)
{
if(!node) {
- node_ = new NodePrimitive(AVRO_NULL);
+ node_.reset(new NodePrimitive(AVRO_NULL));
}
if(!node->isValid()) {
@@ -78,14 +78,14 @@
}
void
-ValidSchema::toJson(std::ostream &os)
+ValidSchema::toJson(std::ostream &os) const
{
node_->printJson(os, 0);
os << '\n';
}
void
-ValidSchema::toFlatList(std::ostream &os)
+ValidSchema::toFlatList(std::ostream &os) const
{
node_->printBasicInfo(os);
}
Modified: hadoop/avro/trunk/src/c++/impl/ValidatingReader.cc
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/impl/ValidatingReader.cc?rev=822968&r1=822967&r2=822968&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/impl/ValidatingReader.cc (original)
+++ hadoop/avro/trunk/src/c++/impl/ValidatingReader.cc Thu Oct 8 00:12:44 2009
@@ -78,4 +78,4 @@
return getCount();
}
-} // namepspace avro
+} // namespace avro
Modified: hadoop/avro/trunk/src/c++/impl/ValidatingWriter.cc
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/impl/ValidatingWriter.cc?rev=822968&r1=822967&r2=822968&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/impl/ValidatingWriter.cc (original)
+++ hadoop/avro/trunk/src/c++/impl/ValidatingWriter.cc Thu Oct 8 00:12:44 2009
@@ -98,4 +98,4 @@
}
-} // namepspace avro
+} // namespace avro
Modified: hadoop/avro/trunk/src/c++/impl/Validator.cc
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/impl/Validator.cc?rev=822968&r1=822967&r2=822968&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/impl/Validator.cc (original)
+++ hadoop/avro/trunk/src/c++/impl/Validator.cc Thu Oct 8 00:12:44 2009
@@ -295,4 +295,4 @@
return found;
}
-} // namepspace avro
+} // namespace avro