Skip to content

Commit

Permalink
Add possibility to disable client-side type conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Mast committed Feb 11, 2015
1 parent 8a1ca06 commit d9f8b88
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 20 deletions.
8 changes: 8 additions & 0 deletions client/c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ hyperdex_client_error_message(hyperdex_client* _cl)
return cl->error_message();
}

HYPERDEX_API void
hyperdex_client_set_type_conversion(hyperdex_client* _cl, bool enabled)
{
FAKE_STATUS;
hyperdex::client* cl = reinterpret_cast<hyperdex::client*>(_cl);
cl->set_type_conversion(enabled);
}

HYPERDEX_API const char*
hyperdex_client_error_location(hyperdex_client* _cl)
{
Expand Down
18 changes: 15 additions & 3 deletions client/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ client :: client(const char* coordinator, uint16_t port)
, m_last_error()
, m_macaroons(NULL)
, m_macaroons_sz(0)
, m_convert_types(true)
{
m_gc.register_thread(&m_gc_ts);
}
Expand All @@ -116,6 +117,7 @@ client :: client(const char* conn_str)
, m_last_error()
, m_macaroons(NULL)
, m_macaroons_sz(0)
, m_convert_types(true)
{
m_gc.register_thread(&m_gc_ts);
}
Expand Down Expand Up @@ -851,12 +853,15 @@ client :: prepare_funcs(const char* space, const schema& sc,
datatype_info* type = datatype_info::lookup(sc.attrs[attrnum].type);
datatype_info* a1type = datatype_info::lookup(o.arg1_datatype);

if (!a1type->client_to_server(o.arg1, memory, &o.arg1))
if (m_convert_types)
{
ERROR(WRONGTYPE) << "attribute \""
if (!a1type->client_to_server(o.arg1, memory, &o.arg1))
{
ERROR(WRONGTYPE) << "attribute \""
<< e::strescape(attrs[i].attr)
<< "\" does not meet the constraints of its type";
return i;
return i;
}
}

if (path != NULL)
Expand Down Expand Up @@ -1266,3 +1271,10 @@ operator << (std::ostream& lhs, hyperdex_client_returncode rhs)

return lhs;
}

// enable or disable type conversion on the client-side
void
client :: set_type_conversion(bool enabled)
{
m_convert_types = enabled;
}
3 changes: 3 additions & 0 deletions client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class client
// helpers for bindings
hyperdatatype attribute_type(const char* space, const char* name,
hyperdex_client_returncode* status);
// enable or disable type conversion on the client-side
void set_type_conversion(bool enabled);

private:
struct pending_server_pair
Expand Down Expand Up @@ -208,6 +210,7 @@ class client
e::error m_last_error;
const char** m_macaroons;
size_t m_macaroons_sz;
bool m_convert_types;

private:
client(const client&);
Expand Down
2 changes: 1 addition & 1 deletion client/pending_get.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pending_get :: handle_message(client* cl,
if (!value_to_attributes(*cl->m_coord.config(),
cl->m_coord.config()->get_region_id(vsi),
NULL, 0, value, &op_status, &op_error,
m_attrs, m_attrs_sz))
m_attrs, m_attrs_sz, cl->m_convert_types))
{
set_status(op_status);
set_error(op_error);
Expand Down
2 changes: 1 addition & 1 deletion client/pending_get_partial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pending_get_partial :: handle_message(client* cl,
if (!value_to_attributes(*cl->m_coord.config(),
cl->m_coord.config()->get_region_id(vsi),
value, &op_status, &op_error,
m_attrs, m_attrs_sz))
m_attrs, m_attrs_sz, cl->m_convert_types))
{
set_status(op_status);
set_error(op_error);
Expand Down
2 changes: 1 addition & 1 deletion client/pending_search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pending_search :: handle_message(client* cl,
if (!value_to_attributes(*cl->m_coord.config(),
cl->m_coord.config()->get_region_id(vsi),
key.data(), key.size(), value,
&op_status, &op_error, m_attrs, m_attrs_sz))
&op_status, &op_error, m_attrs, m_attrs_sz, cl->m_convert_types))
{
set_status(op_status);
set_error(op_error);
Expand Down
2 changes: 1 addition & 1 deletion client/pending_sorted_search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pending_sorted_search :: yield(hyperdex_client_returncode* status, e::error* err
++m_results_idx;

if (!value_to_attributes(*m_cl->m_coord.config(), m_ri, key.data(), key.size(),
value, &op_status, &op_error, m_attrs, m_attrs_sz))
value, &op_status, &op_error, m_attrs, m_attrs_sz, m_cl->m_convert_types))
{
set_status(op_status);
set_error(op_error);
Expand Down
30 changes: 19 additions & 11 deletions client/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ hyperdex :: value_to_attributes(const configuration& config,
hyperdex_client_returncode* op_status,
e::error* op_error,
const hyperdex_client_attribute** attrs,
size_t* attrs_sz)
size_t* attrs_sz,
bool convert_types)
{
std::vector<e::slice> value(_value);
const schema* sc = config.get_schema(rid);
Expand All @@ -63,14 +64,17 @@ hyperdex :: value_to_attributes(const configuration& config,
return false;
}

for (size_t i = 0; i < value.size(); ++i)
if (convert_types)
{
datatype_info* di = datatype_info::lookup(sc->attrs[i + 1].type);

if (!di->server_to_client(value[i], &memory, &value[i]))
for (size_t i = 0; i < value.size(); ++i)
{
UTIL_ERROR(SERVERERROR) << "cannot convert from server-side form";
return false;
datatype_info* di = datatype_info::lookup(sc->attrs[i + 1].type);

if (!di->server_to_client(value[i], &memory, &value[i]))
{
UTIL_ERROR(SERVERERROR) << "cannot convert from server-side form";
return false;
}
}
}

Expand Down Expand Up @@ -145,7 +149,8 @@ hyperdex :: value_to_attributes(const configuration& config,
hyperdex_client_returncode* op_status,
e::error* op_error,
const hyperdex_client_attribute** attrs,
size_t* attrs_sz)
size_t* attrs_sz,
bool convert_types)
{
std::vector<std::pair<uint16_t, e::slice> > value(_value);
const schema* sc = config.get_schema(rid);
Expand All @@ -168,10 +173,13 @@ hyperdex :: value_to_attributes(const configuration& config,
sz += strlen(sc->attrs[attr].name) + 1 + value[i].second.size();
datatype_info* di = datatype_info::lookup(sc->attrs[attr].type);

if (!di->server_to_client(value[i].second, &memory, &value[i].second))
if (convert_types)
{
UTIL_ERROR(SERVERERROR) << "cannot convert from server-side form";
return false;
if (!di->server_to_client(value[i].second, &memory, &value[i].second))
{
UTIL_ERROR(SERVERERROR) << "cannot convert from server-side form";
return false;
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions client/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ value_to_attributes(const configuration& config,
hyperdex_client_returncode* op_status,
e::error* op_error,
const hyperdex_client_attribute** attrs,
size_t* attrs_sz);
size_t* attrs_sz,
bool convert_types);

bool
value_to_attributes(const configuration& config,
Expand All @@ -59,7 +60,8 @@ value_to_attributes(const configuration& config,
hyperdex_client_returncode* op_status,
e::error* op_error,
const hyperdex_client_attribute** attrs,
size_t* attrs_sz);
size_t* attrs_sz,
bool convert_types);

END_HYPERDEX_NAMESPACE

Expand Down

0 comments on commit d9f8b88

Please sign in to comment.