Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hypercube Searches #198

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ noinst_HEADERS += common/attribute_check.h
noinst_HEADERS += common/attribute.h
noinst_HEADERS += common/auth_wallet.h
noinst_HEADERS += common/configuration.h
noinst_HEADERS += common/hypercube.h
noinst_HEADERS += common/configuration_flags.h
noinst_HEADERS += common/coordinator_link.h
noinst_HEADERS += common/coordinator_returncode.h
Expand Down Expand Up @@ -229,6 +230,7 @@ hyperdex_daemon_SOURCES += common/attribute.cc
hyperdex_daemon_SOURCES += common/attribute_check.cc
hyperdex_daemon_SOURCES += common/auth_wallet.cc
hyperdex_daemon_SOURCES += common/configuration.cc
hyperdex_daemon_SOURCES += common/hypercube.cc
hyperdex_daemon_SOURCES += common/coordinator_link.cc
hyperdex_daemon_SOURCES += common/coordinator_returncode.cc
hyperdex_daemon_SOURCES += common/datatype_document.cc
Expand Down Expand Up @@ -397,6 +399,7 @@ noinst_HEADERS += client/pending_group_del.h
noinst_HEADERS += client/pending.h
noinst_HEADERS += client/pending_search_describe.h
noinst_HEADERS += client/pending_search.h
noinst_HEADERS += client/pending_volume_search.h
noinst_HEADERS += client/pending_sorted_search.h
noinst_HEADERS += client/util.h

Expand All @@ -405,6 +408,7 @@ libhyperdex_client_la_SOURCES += common/attribute.cc
libhyperdex_client_la_SOURCES += common/attribute_check.cc
libhyperdex_client_la_SOURCES += common/auth_wallet.cc
libhyperdex_client_la_SOURCES += common/configuration.cc
libhyperdex_client_la_SOURCES += common/hypercube.cc
libhyperdex_client_la_SOURCES += common/coordinator_link.cc
libhyperdex_client_la_SOURCES += common/datatype_document.cc
libhyperdex_client_la_SOURCES += common/datatype_float.cc
Expand Down Expand Up @@ -447,6 +451,7 @@ libhyperdex_client_la_SOURCES += client/pending_group_del.cc
libhyperdex_client_la_SOURCES += client/pending_search.cc
libhyperdex_client_la_SOURCES += client/pending_search_describe.cc
libhyperdex_client_la_SOURCES += client/pending_sorted_search.cc
libhyperdex_client_la_SOURCES += client/pending_volume_search.cc
libhyperdex_client_la_SOURCES += client/util.cc
libhyperdex_client_la_LIBADD =
libhyperdex_client_la_LIBADD += $(MACAROONS_LIBS)
Expand Down Expand Up @@ -499,6 +504,7 @@ libhyperdex_admin_la_SOURCES =
libhyperdex_admin_la_SOURCES += common/attribute.cc
libhyperdex_admin_la_SOURCES += common/attribute_check.cc
libhyperdex_admin_la_SOURCES += common/configuration.cc
libhyperdex_admin_la_SOURCES += common/hypercube.cc
libhyperdex_admin_la_SOURCES += common/coordinator_link.cc
libhyperdex_admin_la_SOURCES += common/datatype_document.cc
libhyperdex_admin_la_SOURCES += common/datatype_float.cc
Expand Down
13 changes: 13 additions & 0 deletions client/c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,19 @@ hyperdex_client_search(struct hyperdex_client* _cl,
);
}

HYPERDEX_API int64_t
hyperdex_client_volume_search(struct hyperdex_client* _cl,
const char* space,
const struct hyperdex_client_attribute_check* checks, size_t checks_sz,
enum hyperdex_client_returncode* status,
const struct hyperdex_client_attribute** attrs, size_t* attrs_sz,
const struct hyperdex_client_hypercube * cbs, size_t cbs_sz)
{
C_WRAP_EXCEPT(
return cl->volume_search(space, checks, checks_sz, status, attrs, attrs_sz,cbs,cbs_sz);
);
}

HYPERDEX_API int64_t
hyperdex_client_search_describe(struct hyperdex_client* _cl,
const char* space,
Expand Down
85 changes: 83 additions & 2 deletions client/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include "client/pending_search.h"
#include "client/pending_search_describe.h"
#include "client/pending_sorted_search.h"
#include "client/pending_volume_search.h"

#define ERROR(CODE) \
*status = HYPERDEX_CLIENT_ ## CODE; \
Expand All @@ -78,6 +79,7 @@
return false;

using hyperdex::client;
using hyperdex::hypercube;

client :: client(const char* coordinator, uint16_t port)
: m_coord(coordinator, port)
Expand Down Expand Up @@ -268,9 +270,10 @@ client :: get_partial(const char* space, const char* _key, size_t _key_sz,
return -1; \
} \
std::vector<attribute_check> checks; \
std::vector<hypercube> cubes; \
std::vector<virtual_server_id> servers; \
arena_t allocate; \
int64_t ret = prepare_searchop(*sc, space, chks, chks_sz, &allocate, status, &checks, &servers); \
int64_t ret = prepare_searchop(*sc, space, chks, chks_sz, NULL, 0, &allocate, status, &checks, &cubes, &servers); \
if (ret < 0) \
{ \
return ret; \
Expand All @@ -294,6 +297,43 @@ client :: search(const char* space,
return perform_aggregation(servers, op, REQ_SEARCH_START, msg, status);
}

int64_t
client :: volume_search(const char* space,
const hyperdex_client_attribute_check* chks, size_t chks_sz,
hyperdex_client_returncode* status,
const hyperdex_client_attribute** attrs, size_t* attrs_sz,
const hyperdex_client_hypercube * cbs, size_t cbs_sz)
{
if (!maintain_coord_connection(status))
{
return -1; \
}
const schema* sc = m_coord.config()->get_schema(space);
if (!sc)
{
ERROR(UNKNOWNSPACE) << "space \"" << e::strescape(space) << "\" does not exist";
return -1;
}
std::vector<attribute_check> checks;
std::vector<hypercube> cubes;
std::vector<virtual_server_id> servers;
arena_t allocate;
int64_t ret = prepare_searchop(*sc, space, chks, chks_sz, cbs, cbs_sz, &allocate, status, &checks, &cubes, &servers);
if (ret < 0)
{
return ret;
}
int64_t client_id = m_next_client_id++;
e::intrusive_ptr<pending_aggregation> op;
op = new pending_volume_search(client_id, status, attrs, attrs_sz,cubes);
size_t sz = HYPERDEX_CLIENT_HEADER_SIZE_REQ
+ sizeof(uint64_t)
+ pack_size(checks);
std::auto_ptr<e::buffer> msg(e::buffer::create(sz));
msg->pack_at(HYPERDEX_CLIENT_HEADER_SIZE_REQ) << client_id << checks;
return perform_aggregation(servers, op, REQ_SEARCH_START, msg, status);
}

int64_t
client :: search_describe(const char* space,
const hyperdex_client_attribute_check* chks, size_t chks_sz,
Expand Down Expand Up @@ -728,6 +768,38 @@ client :: attribute_type(const char* space, const char* name,
return sc->attrs[attrnum].type;
}

size_t
client :: prepare_cubes(const char* space, const schema& sc,
const hyperdex_client_hypercube* cbs, size_t cbs_sz,
arena_t* allocate,
hyperdex_client_returncode* status,
std::vector<hypercube>* cubes)
{
cubes->reserve(cubes->size() + cbs_sz);

for (size_t i = 0; i < cbs_sz; ++i)
{
uint16_t attrnum[cbs[i].dims];
for (size_t j = 0; j < cbs[i].dims; ++j)
{
attrnum[j] = sc.lookup_attr(cbs[i].attrs[j]);
if (attrnum[j] >= sc.attrs_sz)
{
ERROR(UNKNOWNATTR) << "\"" << e::strescape(cbs[i].attrs[j])
<< "\" is not an attribute of space \""
<< e::strescape(space) << "\"";
return i;
}
}


hypercube cube(attrnum, cbs[i].dims, cbs[i].lower_coord, cbs[i].upper_coord);

cubes->push_back(cube);
}

return cbs_sz;
}
size_t
client :: prepare_checks(const char* space, const schema& sc,
const hyperdex_client_attribute_check* chks, size_t chks_sz,
Expand Down Expand Up @@ -939,13 +1011,16 @@ client :: prepare_funcs(const char* space, const schema& sc,
return mapattrs_sz;
}


size_t
client :: prepare_searchop(const schema& sc,
const char* space,
const hyperdex_client_attribute_check* chks, size_t chks_sz,
const hyperdex_client_hypercube* cbs, size_t cbs_sz,
arena_t* allocate,
hyperdex_client_returncode* status,
std::vector<attribute_check>* checks,
std::vector<hypercube>* cubes,
std::vector<virtual_server_id>* servers)
{
size_t num_checks = prepare_checks(space, sc, chks, chks_sz, allocate, status, checks);
Expand All @@ -954,9 +1029,15 @@ client :: prepare_searchop(const schema& sc,
{
return -1 - num_checks;
}
size_t num_cubes= prepare_cubes(space, sc, cbs, cbs_sz, allocate, status, cubes);

if (num_cubes != cbs_sz)
{
return -1 - num_cubes;
}

std::stable_sort(checks->begin(), checks->end());
m_coord.config()->lookup_search(space, *checks, servers); // XXX search guaranteed empty vs. search encounters offline server
m_coord.config()->lookup_search(space, *checks, *cubes, servers); // XXX search guaranteed empty vs. search encounters offline server

if (servers->empty())
{
Expand Down
13 changes: 13 additions & 0 deletions client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ class client
const hyperdex_client_attribute_check* checks, size_t checks_sz,
hyperdex_client_returncode* status,
const hyperdex_client_attribute** attrs, size_t* attrs_sz);
int64_t volume_search(const char* space,
const hyperdex_client_attribute_check* checks, size_t checks_sz,
hyperdex_client_returncode* status,
const hyperdex_client_attribute** attrs, size_t* attrs_sz,
const hyperdex_client_hypercube * cbs, size_t cbs_sz);
int64_t search_describe(const char* space,
const hyperdex_client_attribute_check* checks, size_t checks_sz,
hyperdex_client_returncode* status, const char** description);
Expand Down Expand Up @@ -129,9 +134,15 @@ class client
friend class pending_get;
friend class pending_get_partial;
friend class pending_search;
friend class pending_volume_search;
friend class pending_sorted_search;

private:
size_t prepare_cubes(const char* space, const schema& sc,
const hyperdex_client_hypercube* cbs, size_t cbs_sz,
arena_t* allocate,
hyperdex_client_returncode* status,
std::vector<hypercube>* cubes);
size_t prepare_checks(const char* space, const schema& sc,
const hyperdex_client_attribute_check* chks, size_t chks_sz,
arena_t* allocate,
Expand All @@ -152,9 +163,11 @@ class client
size_t prepare_searchop(const schema& sc,
const char* space,
const hyperdex_client_attribute_check* chks, size_t chks_sz,
const hyperdex_client_hypercube* cbs, size_t cbs_sz,
arena_t* allocate,
hyperdex_client_returncode* status,
std::vector<attribute_check>* checks,
std::vector<hypercube>* cubes,
std::vector<virtual_server_id>* servers);
int64_t perform_aggregation(const std::vector<virtual_server_id>& servers,
e::intrusive_ptr<pending_aggregation> op,
Expand Down
Loading