1
0
Fork 0

removed some code

This commit is contained in:
Jan Steemann 2014-01-15 17:22:13 +01:00
parent c0e185c859
commit 3b192782c5
4 changed files with 100 additions and 304 deletions

View File

@ -51,53 +51,15 @@ using triagens::basics::JsonHelper;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CollectionInfo::CollectionInfo () CollectionInfo::CollectionInfo ()
: _id(), : _json(0) {
_name(),
_type(TRI_COL_TYPE_UNKNOWN),
_status(TRI_VOC_COL_STATUS_CORRUPTED),
_maximalSize(0),
_deleted(false),
_doCompact(false),
_isSystem(false),
_isVolatile(false),
_waitForSync(false),
_keyOptions(0),
_shardKeys(),
_shardIds() {
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief creates a collection info object from json /// @brief creates a collection info object from json
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CollectionInfo::CollectionInfo (std::string const& data) { CollectionInfo::CollectionInfo (TRI_json_t* json)
TRI_json_t* json = JsonHelper::fromString(data); : _json(json) {
if (json != 0) {
if (JsonHelper::isArray(json)) {
if (! createFromJson(json)) {
invalidate();
}
}
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief creates a collection info object from json
////////////////////////////////////////////////////////////////////////////////
CollectionInfo::CollectionInfo (TRI_json_t* json) {
if (json != 0) {
if (JsonHelper::isArray(json)) {
if (! createFromJson(json)) {
invalidate();
}
}
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -105,22 +67,10 @@ CollectionInfo::CollectionInfo (TRI_json_t* json) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CollectionInfo::CollectionInfo (CollectionInfo const& other) : CollectionInfo::CollectionInfo (CollectionInfo const& other) :
_id(other._id), _json(other._json) {
_name(other._name),
_type(other._type),
_status(other._status),
_maximalSize(other._maximalSize),
_deleted(other._deleted),
_doCompact(other._doCompact),
_isSystem(other._isSystem),
_isVolatile(other._isVolatile),
_waitForSync(other._waitForSync),
_keyOptions(0),
_shardKeys(other._shardKeys),
_shardIds(other._shardIds) {
if (other._keyOptions != 0) { if (other._json != 0) {
_keyOptions = TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, other._keyOptions); _json = TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, other._json);
} }
} }
@ -129,22 +79,11 @@ CollectionInfo::CollectionInfo (CollectionInfo const& other) :
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CollectionInfo& CollectionInfo::operator= (CollectionInfo const& other) { CollectionInfo& CollectionInfo::operator= (CollectionInfo const& other) {
_id = other._id; if (other._json != 0 && this != &other) {
_name = other._name; _json = TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, other._json);
_type = other._type; }
_status = other._status; else {
_maximalSize = other._maximalSize; _json = 0;
_deleted = other._deleted;
_doCompact = other._doCompact;
_isSystem = other._isSystem;
_isVolatile = other._isVolatile;
_waitForSync = other._waitForSync;
_shardKeys = other._shardKeys;
_shardIds = other._shardIds;
_keyOptions = 0;
if (other._keyOptions != 0) {
_keyOptions = TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, other._keyOptions);
} }
return *this; return *this;
@ -155,8 +94,8 @@ CollectionInfo& CollectionInfo::operator= (CollectionInfo const& other) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CollectionInfo::~CollectionInfo () { CollectionInfo::~CollectionInfo () {
if (_keyOptions != 0) { if (_json != 0) {
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, _keyOptions); TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, _json);
} }
} }
@ -164,159 +103,6 @@ CollectionInfo::~CollectionInfo () {
// --SECTION-- private methods // --SECTION-- private methods
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief invalidates a collection info object
////////////////////////////////////////////////////////////////////////////////
void CollectionInfo::invalidate () {
_id = 0;
_name = "";
_type = TRI_COL_TYPE_UNKNOWN;
_status = TRI_VOC_COL_STATUS_CORRUPTED;
_maximalSize = 0;
_deleted = false;
_doCompact = false;
_isSystem = false;
_isVolatile = false;
_waitForSync = false;
_shardKeys.clear();
_shardIds.clear();
if (_keyOptions != 0) {
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, _keyOptions);
}
_keyOptions = 0;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief populate object properties from the JSON given
////////////////////////////////////////////////////////////////////////////////
bool CollectionInfo::createFromJson (TRI_json_t const* json) {
// id
const std::string id = JsonHelper::getStringValue(json, "id", "");
if (id.empty()) {
return false;
}
_id = triagens::basics::StringUtils::uint64(id.c_str(), id.size());
// name
_name = JsonHelper::getStringValue(json, "name", "");
if (_name.empty()) {
return false;
}
// type
_type = (TRI_col_type_e) JsonHelper::getNumericValue<int>(json,
"type",
(int) TRI_COL_TYPE_UNKNOWN);
if (_type == TRI_COL_TYPE_UNKNOWN) {
return false;
}
// status
_status = (TRI_vocbase_col_status_e) JsonHelper::getNumericValue<int>(json,
"status",
(int) TRI_VOC_COL_STATUS_NEW_BORN);
if (_status == TRI_VOC_COL_STATUS_CORRUPTED ||
_status == TRI_VOC_COL_STATUS_NEW_BORN) {
return false;
}
_maximalSize = JsonHelper::getNumericValue<TRI_voc_size_t>(json, "maximalSize", 0);
_doCompact = JsonHelper::getBooleanValue(json, "doCompact", false);
_isSystem = JsonHelper::getBooleanValue(json, "isSystem", false);
_isVolatile = JsonHelper::getBooleanValue(json, "isVolatile", false);
_waitForSync = JsonHelper::getBooleanValue(json, "waitForSync", false);
TRI_json_t const* keyOptions = JsonHelper::getArrayElement(json, "keyOptions");
if (JsonHelper::isArray(keyOptions)) {
_keyOptions = TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, keyOptions);
}
else {
_keyOptions = 0;
}
// TODO: indexes
// shardKeys
TRI_json_t const* value = TRI_LookupArrayJson(json, "shardKeys");
if (! JsonHelper::isList(value)) {
return false;
}
_shardKeys = JsonHelper::stringList(value);
// shards
value = TRI_LookupArrayJson(json, "shards");
if (! JsonHelper::isArray(value)) {
return false;
}
_shardIds = JsonHelper::stringObject(value);
return true;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief create a JSON string from the object
////////////////////////////////////////////////////////////////////////////////
TRI_json_t* CollectionInfo::toJson (TRI_memory_zone_t* zone) {
TRI_json_t* json = TRI_CreateArrayJson(zone);
if (json == 0) {
return json;
}
char* data = TRI_StringUInt64(_id);
if (data == 0) {
TRI_FreeJson(zone, json);
return 0;
}
TRI_Insert3ArrayJson(zone, json, "id", TRI_CreateStringJson(zone, data));
TRI_Insert3ArrayJson(zone, json, "name", TRI_CreateStringCopyJson(zone, _name.c_str()));
TRI_Insert3ArrayJson(zone, json, "type", TRI_CreateNumberJson(zone, (int) _type));
TRI_Insert3ArrayJson(zone, json, "status", TRI_CreateNumberJson(zone, (int) _status));
TRI_Insert3ArrayJson(zone, json, "maximalSize", TRI_CreateNumberJson(zone, (int) _maximalSize));
TRI_Insert3ArrayJson(zone, json, "doCompact", TRI_CreateBooleanJson(zone, _doCompact));
TRI_Insert3ArrayJson(zone, json, "isSystem", TRI_CreateBooleanJson(zone, _isSystem));
TRI_Insert3ArrayJson(zone, json, "isVolatile", TRI_CreateBooleanJson(zone, _isVolatile));
TRI_Insert3ArrayJson(zone, json, "waitForSync", TRI_CreateBooleanJson(zone, _waitForSync));
if (_keyOptions != 0) {
TRI_Insert3ArrayJson(zone, json, "keyOptions", TRI_CopyJson(zone, _keyOptions));
}
// TODO: indexes
TRI_json_t* values = JsonHelper::stringList(zone, _shardKeys);
if (values == 0) {
TRI_FreeJson(zone, json);
return 0;
}
TRI_Insert3ArrayJson(zone, json, "shardKeys", values);
values = JsonHelper::stringObject(zone, _shardIds);
if (values == 0) {
TRI_FreeJson(zone, json);
return 0;
}
TRI_Insert3ArrayJson(zone, json, "shards", values);
return json;
}
// -----------------------------------------------------------------------------
// --SECTION-- ClusterInfo class
// -----------------------------------------------------------------------------
ClusterInfo* ClusterInfo::_theinstance = 0; ClusterInfo* ClusterInfo::_theinstance = 0;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -763,23 +549,19 @@ CollectionInfo ClusterInfo::getCollection (DatabaseID const& databaseID,
TRI_col_info_t ClusterInfo::getCollectionProperties (CollectionInfo const& collection) { TRI_col_info_t ClusterInfo::getCollectionProperties (CollectionInfo const& collection) {
TRI_col_info_t info; TRI_col_info_t info;
info._type = collection._type; info._type = collection.type();
info._cid = collection._id; info._cid = collection.id();
info._revision = 0; // TODO info._revision = 0; // TODO
info._maximalSize = collection._maximalSize; info._maximalSize = collection.maximalSize();
memcpy(info._name, collection._name.c_str(), collection._name.size());
info._deleted = collection._deleted;
info._doCompact = collection._doCompact;
info._isSystem = collection._isSystem;
info._isVolatile = collection._isVolatile;
info._waitForSync = collection._waitForSync;
if (collection._keyOptions != 0) { const std::string name = collection.name();
info._keyOptions = TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, collection._keyOptions); memcpy(info._name, name.c_str(), name.size());
} info._deleted = collection.deleted();
else { info._doCompact = collection.doCompact();
info._keyOptions = 0; info._isSystem = collection.isSystem();
} info._isVolatile = collection.isVolatile();
info._waitForSync = collection.waitForSync();
info._keyOptions = collection.keyOptions();
return info; return info;
} }

View File

@ -30,6 +30,7 @@
#define TRIAGENS_CLUSTER_CLUSTER_INFO_H 1 #define TRIAGENS_CLUSTER_CLUSTER_INFO_H 1
#include "Basics/Common.h" #include "Basics/Common.h"
#include "Basics/JsonHelper.h"
#include "Cluster/AgencyComm.h" #include "Cluster/AgencyComm.h"
#include "VocBase/collection.h" #include "VocBase/collection.h"
#include "VocBase/voc-types.h" #include "VocBase/voc-types.h"
@ -69,8 +70,6 @@ namespace triagens {
CollectionInfo (); CollectionInfo ();
CollectionInfo (std::string const&);
CollectionInfo (struct TRI_json_s*); CollectionInfo (struct TRI_json_s*);
CollectionInfo (CollectionInfo const&); CollectionInfo (CollectionInfo const&);
@ -89,8 +88,8 @@ namespace triagens {
/// @brief returns the collection id /// @brief returns the collection id
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_voc_cid_t cid () const { TRI_voc_cid_t id () const {
return _id; return triagens::basics::JsonHelper::stringUInt64(_json, "id");
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -98,7 +97,7 @@ namespace triagens {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string name () const { std::string name () const {
return _name; return triagens::basics::JsonHelper::getStringValue(_json, "name", "");
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -106,7 +105,7 @@ namespace triagens {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_col_type_e type () const { TRI_col_type_e type () const {
return _type; return triagens::basics::JsonHelper::getNumericValue<TRI_col_type_e>(_json, "type", TRI_COL_TYPE_UNKNOWN);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -114,39 +113,87 @@ namespace triagens {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_vocbase_col_status_e status () const { TRI_vocbase_col_status_e status () const {
return _status; return triagens::basics::JsonHelper::getNumericValue<TRI_vocbase_col_status_e>(_json, "status", TRI_VOC_COL_STATUS_CORRUPTED);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief returns the collection status /// @brief returns the collection status as a string
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string statusString () const { std::string statusString () const {
return TRI_GetStatusStringCollectionVocBase(_status); return TRI_GetStatusStringCollectionVocBase(status());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief returns the properties /// @brief returns the deleted flag
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_col_info_t properties () const; bool deleted () const {
return triagens::basics::JsonHelper::getBooleanValue(_json, "deleted", false);
//////////////////////////////////////////////////////////////////////////////// }
/// @brief TODO: returns the indexes
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief returns the docompact flag
/* ////////////////////////////////////////////////////////////////////////////////
std::vector<std::string> indexes () const {
return _indexes; bool doCompact () const {
return triagens::basics::JsonHelper::getBooleanValue(_json, "doCompact", false);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the issystem flag
////////////////////////////////////////////////////////////////////////////////
bool isSystem () const {
return triagens::basics::JsonHelper::getBooleanValue(_json, "isSystem", false);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the isvolatile flag
////////////////////////////////////////////////////////////////////////////////
bool isVolatile () const {
return triagens::basics::JsonHelper::getBooleanValue(_json, "isVolatile", false);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns a copy of the key options
/// the caller is responsible for freeing it
////////////////////////////////////////////////////////////////////////////////
TRI_json_t* keyOptions () const {
TRI_json_t const* keyOptions = triagens::basics::JsonHelper::getArrayElement(_json, "keyOptions");
if (keyOptions != 0) {
return TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, keyOptions);
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the waitforsync flag
////////////////////////////////////////////////////////////////////////////////
bool waitForSync () const {
return triagens::basics::JsonHelper::getBooleanValue(_json, "waitForSync", false);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the maximal journal size
////////////////////////////////////////////////////////////////////////////////
TRI_voc_size_t maximalSize () const {
return triagens::basics::JsonHelper::getNumericValue<TRI_voc_size_t>(_json, "maximalSize", 0);
} }
*/
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief returns the shard keys /// @brief returns the shard keys
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::vector<std::string> shardKeys () const { std::vector<std::string> shardKeys () const {
return _shardKeys; TRI_json_t* const node = triagens::basics::JsonHelper::getArrayElement(_json, "shardKeys");
return triagens::basics::JsonHelper::stringList(node);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -154,54 +201,21 @@ namespace triagens {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::map<std::string, std::string> shardIds () const { std::map<std::string, std::string> shardIds () const {
return _shardIds; TRI_json_t* const node = triagens::basics::JsonHelper::getArrayElement(_json, "shards");
return triagens::basics::JsonHelper::stringObject(node);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- private methods // --SECTION-- private methods
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
private:
////////////////////////////////////////////////////////////////////////////////
/// @brief invalidates a collection info object
////////////////////////////////////////////////////////////////////////////////
void invalidate ();
////////////////////////////////////////////////////////////////////////////////
/// @brief populate object properties from the JSON given
////////////////////////////////////////////////////////////////////////////////
bool createFromJson (struct TRI_json_s const*);
////////////////////////////////////////////////////////////////////////////////
/// @brief create a JSON string from the object
////////////////////////////////////////////////////////////////////////////////
struct TRI_json_s* toJson (struct TRI_memory_zone_s*);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- private variables // --SECTION-- private variables
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
TRI_voc_cid_t _id; private:
std::string _name;
TRI_col_type_e _type; TRI_json_t* _json;
TRI_vocbase_col_status_e _status;
TRI_voc_size_t _maximalSize;
bool _deleted;
bool _doCompact;
bool _isSystem;
bool _isVolatile;
bool _waitForSync;
TRI_json_t* _keyOptions;
// TODO: indexes
std::vector<std::string> _shardKeys;
std::map<std::string, std::string> _shardIds;
}; };

View File

@ -738,7 +738,7 @@ static v8::Handle<v8::Value> JS_GetCollectionInfoClusterInfo (v8::Arguments cons
TRI_ObjectToString(argv[1])); TRI_ObjectToString(argv[1]));
v8::Handle<v8::Object> result = v8::Object::New(); v8::Handle<v8::Object> result = v8::Object::New();
const std::string cid = triagens::basics::StringUtils::itoa(ci.cid()); const std::string cid = triagens::basics::StringUtils::itoa(ci.id());
const std::string& name = ci.name(); const std::string& name = ci.name();
result->Set(v8::String::New("id"), v8::String::New(cid.c_str(), cid.size())); result->Set(v8::String::New("id"), v8::String::New(cid.c_str(), cid.size()));
result->Set(v8::String::New("name"), v8::String::New(name.c_str(), name.size())); result->Set(v8::String::New("name"), v8::String::New(name.c_str(), name.size()));

View File

@ -251,7 +251,7 @@ static TRI_vocbase_col_t* CollectionInfoToVocBaseCol (TRI_vocbase_t* vocbase,
c->_isLocal = false; c->_isLocal = false;
c->_vocbase = vocbase; c->_vocbase = vocbase;
c->_type = ci.type(); c->_type = ci.type();
c->_cid = ci.cid(); c->_cid = ci.id();
c->_status = ci.status(); c->_status = ci.status();
c->_collection = 0; c->_collection = 0;