Skip to content

Commit

Permalink
First attempt to restore tests & index documents
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Mast committed Feb 14, 2015
1 parent c5b4a1e commit f4a17f9
Show file tree
Hide file tree
Showing 31 changed files with 506 additions and 255 deletions.
6 changes: 3 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ AM_CPPFLAGS = -I${abs_top_srcdir}/include $(PO6_CFLAGS) $(E_CFLAGS) $(BUSYBEE_C
AM_CFLAGS = -fvisibility=hidden $(WANAL_CFLAGS)
AM_CXXFLAGS = -fvisibility=hidden -fvisibility-inlines-hidden $(PO6_CFLAGS) $(E_CFLAGS) $(BUSYBEE_CFLAGS) $(HYPERLEVELDB_CFLAGS) $(REPLICANT_CFLAGS) $(MACAROONS_CFLAGS) $(TREADSTONE_CFLAGS) $(WANAL_CXXFLAGS)
AM_MAKEFLAGS = --no-print-directory
AM_YFLAGS = -d
AM_YFLAGS = -dk
HELP2MAN_FLAGS = --no-discard-stderr --libtool --no-info --version-string=$(VERSION) --manual="HyperDex User Manual"
TESTS_ENVIRONMENT = . $(abs_top_srcdir)/test/env.sh "${abs_top_srcdir}" "${abs_top_builddir}" "${VERSION}";
AM_DISTCHECK_CONFIGURE_FLAGS = --enable-python-bindings --enable-java-bindings --enable-ruby-bindings
Expand Down Expand Up @@ -844,11 +844,11 @@ stress_wrappers += test/sh/search.combination.keytype=string,daemons=4.fault-tol
shell_wrappers += $(stress_wrappers)

python_wrappers =
#python_wrappers += test/sh/bindings.python.Admin.sh
python_wrappers += test/sh/bindings.python.Admin.sh
python_wrappers += test/sh/bindings.python.BasicSearch.sh
python_wrappers += test/sh/bindings.python.Basic.sh
python_wrappers += test/sh/bindings.python.CondPut.sh
#python_wrappers += test/sh/bindings.python.DataTypeDocument.sh
python_wrappers += test/sh/bindings.python.DataTypeDocument.sh
python_wrappers += test/sh/bindings.python.DataTypeFloat.sh
python_wrappers += test/sh/bindings.python.DataTypeInt.sh
python_wrappers += test/sh/bindings.python.DataTypeListFloat.sh
Expand Down
49 changes: 49 additions & 0 deletions common/datatype_document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ datatype_document :: apply(const e::slice& old_value,
datatype_float::pack(d, &scratch, &v);
type = HYPERDATATYPE_FLOAT;
}

if (func.name != FUNC_SET &&
func.name != FUNC_DOC_UNSET &&
func.name != FUNC_DOC_RENAME)
{
// More complex modifications (string append etc)
// only work with the same type
if(type != func.arg1_datatype)
{
return false;
}
}
}

datatype_info* di = datatype_info::lookup(type);
Expand Down Expand Up @@ -449,6 +461,43 @@ datatype_document :: coerce_primitive_to_binary(hyperdatatype type,
*value = e::slice(&(*scratch)[0], v_sz);
}

bool
datatype_document :: comparable() const
{
return true;
}

// Same as string compare
static int
compare(const e::slice& lhs,
const e::slice& rhs)
{
int cmp = memcmp(lhs.data(), rhs.data(), std::min(lhs.size(), rhs.size()));

if (cmp == 0)
{
if (lhs.size() < rhs.size())
{
return -1;
}

if (lhs.size() > rhs.size())
{
return 1;
}

return 0;
}

return cmp;
}

int
datatype_document :: compare(const e::slice& lhs, const e::slice& rhs) const
{
return ::compare(lhs, rhs);
}

bool
datatype_document :: coerce_binary_to_primitive(const e::slice& in,
hyperdatatype* type,
Expand Down
4 changes: 4 additions & 0 deletions common/datatype_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class datatype_document : public datatype_info
virtual bool document_check(const attribute_check& check,
const e::slice& value) const;

public:
bool comparable() const;
int compare(const e::slice& lhs, const e::slice& rhs) const;

public:
bool extract_value(const char* path,
const e::slice& data,
Expand Down
8 changes: 4 additions & 4 deletions daemon/datalayer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,8 @@ datalayer :: make_search_iterator(snapshot snap,
// pull a set of range queries from checks
std::vector<range> ranges;
range_searches(sc, checks, &ranges);
index_encoding* key_ie = index_encoding::lookup(sc.attrs[0].type);
index_info* key_ii = index_info::lookup(sc.attrs[0].type);
const index_encoding* key_ie = index_encoding::lookup(sc.attrs[0].type);
const index_info* key_ii = index_info::lookup(sc.attrs[0].type);

// for each range query, construct an iterator
for (size_t i = 0; i < ranges.size(); ++i)
Expand All @@ -719,7 +719,7 @@ datalayer :: make_search_iterator(snapshot snap,
{
assert(indices[j]->attr == ranges[i].attr);
const index* idx = indices[j];
index_info* ii = index_info::lookup(ranges[i].type);
const index_info* ii = index_info::lookup(ranges[i].type);

if (!ii)
{
Expand Down Expand Up @@ -749,7 +749,7 @@ datalayer :: make_search_iterator(snapshot snap,
for (size_t j = 0; j < indices.size(); ++j)
{
const index* idx = indices[j];
index_info* ii = index_info::lookup(sc.attrs[checks[i].attr].type);
const index_info* ii = index_info::lookup(sc.attrs[checks[i].attr].type);

if (!ii)
{
Expand Down
6 changes: 3 additions & 3 deletions daemon/datalayer_encodings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ hyperdex :: encode_key(const region_id& ri,
std::vector<char>* scratch,
leveldb::Slice* out)
{
index_encoding* ie(index_encoding::lookup(key_type));
const index_encoding* ie(index_encoding::lookup(key_type));
size_t sz = object_prefix_sz(ri) + ie->encoded_size(key);

if (scratch->size() < sz)
Expand Down Expand Up @@ -291,7 +291,7 @@ hyperdex :: create_index_changes(const schema& sc,
assert(!old_value || !new_value || old_value->size() == new_value->size());
assert(!old_value || old_value->size() + 1 == sc.attrs_sz);
assert(!new_value || new_value->size() + 1 == sc.attrs_sz);
index_encoding* key_ie = index_encoding::lookup(sc.attrs[0].type);
const index_encoding* key_ie = index_encoding::lookup(sc.attrs[0].type);

for (size_t i = 0; i < indices.size(); ++i)
{
Expand All @@ -300,7 +300,7 @@ hyperdex :: create_index_changes(const schema& sc,
assert(idx->attr > 0);
assert(idx->attr < sc.attrs_sz);

index_info* ai = index_info::lookup(sc.attrs[idx->attr].type);
const index_info* ai = index_info::lookup(sc.attrs[idx->attr].type);
assert(ai);

const e::slice* old_attr = NULL;
Expand Down
2 changes: 1 addition & 1 deletion daemon/datalayer_indexer_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ datalayer :: indexer_thread :: play(const region_id& ri, const schema* sc)
leveldb::ReadOptions ro;
ro.fill_cache = false;
iip.reset(leveldb_snapshot_ptr(db, NULL), db->NewIterator(ro));
index_encoding* ie = index_encoding::lookup(sc->attrs[0].type);
const index_encoding* ie = index_encoding::lookup(sc->attrs[0].type);
return new region_iterator(iip, ri, ie);
}

Expand Down
8 changes: 4 additions & 4 deletions daemon/datalayer_iterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ datalayer :: iterator :: ~iterator() throw ()

datalayer :: replay_iterator :: replay_iterator(const region_id& ri,
leveldb_replay_iterator_ptr ptr,
index_encoding* ie)
const index_encoding* ie)
: m_ri(ri)
, m_iter(ptr.get())
, m_ptr(ptr)
Expand Down Expand Up @@ -218,7 +218,7 @@ datalayer :: dummy_iterator :: ~dummy_iterator() throw ()

datalayer :: region_iterator :: region_iterator(leveldb_iterator_ptr iter,
const region_id& ri,
index_encoding* ie)
const index_encoding* ie)
: iterator(iter.snap())
, m_iter(iter)
, m_ri(ri)
Expand Down Expand Up @@ -337,8 +337,8 @@ datalayer :: range_index_iterator :: range_index_iterator(leveldb_snapshot_ptr s
const e::slice& range_upper,
bool has_value_lower,
bool has_value_upper,
index_encoding* val_ie,
index_encoding* key_ie)
const index_encoding* val_ie,
const index_encoding* key_ie)
: index_iterator(s)
, m_iter()
, m_val_ie(val_ie)
Expand Down
16 changes: 8 additions & 8 deletions daemon/datalayer_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class datalayer::iterator
class datalayer::replay_iterator
{
public:
replay_iterator(const region_id& ri, leveldb_replay_iterator_ptr ptr, index_encoding* ie);
replay_iterator(const region_id& ri, leveldb_replay_iterator_ptr ptr, const index_encoding* ie);

public:
bool valid();
Expand All @@ -86,7 +86,7 @@ class datalayer::replay_iterator
leveldb::ReplayIterator* m_iter;
leveldb_replay_iterator_ptr m_ptr;
std::vector<char> m_decoded;
index_encoding* m_ie;
const index_encoding *const m_ie;

private:
replay_iterator(const replay_iterator&);
Expand Down Expand Up @@ -114,7 +114,7 @@ class datalayer::region_iterator : public iterator
public:
region_iterator(leveldb_iterator_ptr iter,
const region_id& ri,
index_encoding* ie);
const index_encoding* ie);
virtual ~region_iterator() throw ();

public:
Expand All @@ -132,7 +132,7 @@ class datalayer::region_iterator : public iterator
leveldb_iterator_ptr m_iter;
region_id m_ri;
std::vector<char> m_decoded;
index_encoding* m_ie;
const index_encoding *const m_ie;
};

class datalayer::index_iterator : public iterator
Expand All @@ -159,8 +159,8 @@ class datalayer::range_index_iterator : public index_iterator
const e::slice& range_upper,
bool has_value_lower,
bool has_value_upper,
index_encoding* val_ie,
index_encoding* key_ie);
const index_encoding* val_ie,
const index_encoding* key_ie);
virtual ~range_index_iterator() throw ();

public:
Expand All @@ -187,8 +187,8 @@ class datalayer::range_index_iterator : public index_iterator

private:
leveldb_iterator_ptr m_iter;
index_encoding* m_val_ie;
index_encoding* m_key_ie;
const index_encoding *const m_val_ie;
const index_encoding *const m_key_ie;
e::slice m_range_prefix;
e::slice m_range_lower;
e::slice m_range_upper;
Expand Down
10 changes: 4 additions & 6 deletions daemon/index_container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,14 @@ index_container :: ~index_container() throw ()
void
index_container :: index_changes(const index* idx,
const region_id& ri,
index_encoding* key_ie,
const index_encoding* key_ie,
const e::slice& key,
const e::slice* old_value,
const e::slice* new_value,
leveldb::WriteBatch* updates)
leveldb::WriteBatch* updates) const
{
std::vector<e::slice> old_elems;
std::vector<e::slice> new_elems;
std::vector<char> scratch;
leveldb::Slice slice;

if (old_value)
{
Expand All @@ -79,7 +77,7 @@ index_container :: index_changes(const index* idx,
new_elems.resize(it - new_elems.begin());
size_t old_idx = 0;
size_t new_idx = 0;
index_info* ii = this->element_index_info();
const index_info* ii = this->element_index_info();

while (old_idx < old_elems.size() &&
new_idx < new_elems.size())
Expand Down Expand Up @@ -126,7 +124,7 @@ index_container :: iterator_from_check(leveldb_snapshot_ptr snap,
const region_id& ri,
const index_id& ii,
const attribute_check& c,
index_encoding* key_ie)
const index_encoding* key_ie) const
{
if (c.predicate == HYPERPREDICATE_CONTAINS &&
c.datatype == this->element_datatype_info()->datatype())
Expand Down
12 changes: 6 additions & 6 deletions daemon/index_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ class index_container : public index_info
public:
virtual void index_changes(const index* idx,
const region_id& ri,
index_encoding* key_ie,
const index_encoding* key_ie,
const e::slice& key,
const e::slice* old_value,
const e::slice* new_value,
leveldb::WriteBatch* updates);
leveldb::WriteBatch* updates) const;
virtual datalayer::index_iterator* iterator_from_check(leveldb_snapshot_ptr snap,
const region_id& ri,
const index_id& ii,
const attribute_check& c,
index_encoding* key_ie);
const index_encoding* key_ie) const;

private:
virtual void extract_elements(const e::slice& container,
std::vector<e::slice>* elems) = 0;
virtual datatype_info* element_datatype_info() = 0;
virtual index_info* element_index_info() = 0;
std::vector<e::slice>* elems) const = 0;
virtual const datatype_info* element_datatype_info() const = 0;
virtual const index_info* element_index_info() const = 0;
};

END_HYPERDEX_NAMESPACE
Expand Down
Loading

0 comments on commit f4a17f9

Please sign in to comment.