Skip to content

Commit

Permalink
[FIX] Fixing of persistent operators
Browse files Browse the repository at this point in the history
  • Loading branch information
mencagli committed Feb 27, 2024
1 parent a237dbe commit bb8d302
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 39 deletions.
2 changes: 1 addition & 1 deletion tests/rocksdb_tests/rocksdb_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ class WinSink_Functor
if (out) {
received++;
totalsum += (*out).value;
//std::cout << "Ricevuto risultato finestra wid: " << (*out).wid << ", chiave: " << (*out).key << ", valore: " << (*out).value << std::endl;
std::cout << "Ricevuto risultato finestra wid: " << (*out).wid << ", chiave: " << (*out).key << ", valore: " << (*out).value << std::endl;
}
else {
// printf("Received: %ld results, total sum: %ld\n", received, totalsum);
Expand Down
10 changes: 0 additions & 10 deletions tests/rocksdb_tests/test_rocksdb_6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,6 @@ int main(int argc, char *argv[])
cout << "| | (" << source_degree << ") +-->+ (" << filter_degree << ") +-->+ (" << flatmap_degree << ") +-->+ (" << map_degree << ") +-->+ (" << kw_degree << ") +-->+ (" << sink_degree << ") | |" << endl;
cout << "| +-----+ +-----+ +------+ +-----+ +--------+ +-----+ |" << endl;
cout << "+-----------------------------------------------------------------+" << endl;
auto tuple_serializer = [](tuple_t &t) -> std::string {
return std::to_string(t.key) + "," + std::to_string(t.value);
};
auto tuple_deserializer = [](std::string &s) -> tuple_t {
tuple_t t;
t.key = atoi(s.substr(0, s.find(",")).c_str());
t.value = atoi(s.substr(s.find(",")+1, s.length()-1).c_str());
return t;
};
auto result_serializer = [](result_t &r) -> std::string {
return std::to_string(r.key) + "," + std::to_string(r.value) + ";" + std::to_string(r.wid);
};
Expand Down Expand Up @@ -160,7 +151,6 @@ int main(int argc, char *argv[])
.withParallelism(kw_degree)
.withKeyBy([](const tuple_t &t) -> size_t { return t.key; })
.withCBWindows(win_len, win_slide)
.withTupleSerializerAndDeserializer(tuple_serializer, tuple_deserializer)
.withResultSerializerAndDeserializer(result_serializer, result_deserializer)
.build();
#else
Expand Down
10 changes: 0 additions & 10 deletions tests/rocksdb_tests/test_rocksdb_8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,6 @@ int main(int argc, char *argv[])
cout << "| | (" << source_degree << ") +-->+ (" << filter_degree << ") +-->+ (" << flatmap_degree << ") +-->+ (" << map_degree << ") +-->+ (" << kw_degree << ") +-->+ (" << sink_degree << ") | |" << endl;
cout << "| +-----+ +-----+ +------+ +-----+ +--------+ +-----+ |" << endl;
cout << "+-----------------------------------------------------------------+" << endl;
auto tuple_serializer = [](tuple_t &t) -> std::string {
return std::to_string(t.key) + "," + std::to_string(t.value);
};
auto tuple_deserializer = [](std::string &s) -> tuple_t {
tuple_t t;
t.key = atoi(s.substr(0, s.find(",")).c_str());
t.value = atoi(s.substr(s.find(",")+1, s.length()-1).c_str());
return t;
};
auto result_serializer = [](result_t &r) -> std::string {
return std::to_string(r.key) + "," + std::to_string(r.value) + ";" + std::to_string(r.wid);
};
Expand Down Expand Up @@ -165,7 +156,6 @@ int main(int argc, char *argv[])
.withParallelism(kw_degree)
.withKeyBy([](const tuple_t &t) -> size_t { return t.key; })
.withTBWindows(microseconds(win_len), microseconds(win_slide))
.withTupleSerializerAndDeserializer(tuple_serializer, tuple_deserializer)
.withResultSerializerAndDeserializer(result_serializer, result_deserializer)
.build();
#else
Expand Down
22 changes: 21 additions & 1 deletion wf/persistent/builders_rocksdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ class P_Keyed_Windows_Builder: public P_Basic_Builder<P_Keyed_Windows_Builder, w
keyextr_func_t key_extr = [](const tuple_t &t) -> key_t { return key_t(); }; // key extractor
bool isKeyBySet = false; // true if a key extractor has been provided
size_t frag_bytes = sizeof(tuple_t) * 16; // size in bytes of each archive fragment of the stream
bool results_in_memory = true; // flag stating if results must be kepts on memory or on RocksDB
bool results_in_memory = true; // flag stating if results must be kepts in memory or on RocksDB
bool isTupleFunctions = false; // flag stating if the tuple serializer/deserializer have been provided
bool isResultFunctions = false; // flag stating if the result serializer/deserializer have been provided
uint64_t win_len=0; // window length in number of tuples or in time units
Expand Down Expand Up @@ -1428,6 +1428,7 @@ class P_Keyed_Windows_Builder: public P_Basic_Builder<P_Keyed_Windows_Builder, w
result_serialize = _result_serialize;
result_deserialize = _result_deserialize;
isResultFunctions = true;
results_in_memory = false;
return *this;
}

Expand All @@ -1452,6 +1453,25 @@ class P_Keyed_Windows_Builder: public P_Basic_Builder<P_Keyed_Windows_Builder, w
std::cerr << RED << "WindFlow Error: P_Keyed_Windows with paralellism > 1 requires a key extractor" << DEFAULT_COLOR << std::endl;
exit(EXIT_FAILURE);
}
// check the presence of the tuple/result serializer/deserializer according to type of the window processing logic
if constexpr (std::is_invocable<decltype(func), const Iterable<tuple_t> &, result_t &>::value ||
std::is_invocable<decltype(func), const Iterable<tuple_t> &, result_t &, RuntimeContext &>::value) {
if (!isTupleFunctions) {
std::cerr << RED << "WindFlow Error: P_Keyed_Windows instantiated with a non-incremental logic without tuple serializer/serializer" << DEFAULT_COLOR << std::endl;
exit(EXIT_FAILURE);
}
}
else if constexpr (std::is_invocable<decltype(func), const tuple_t &, result_t &>::value ||
std::is_invocable<decltype(func), const tuple_t &, result_t &, RuntimeContext &>::value) {
if (isTupleFunctions) {
std::cerr << RED << "WindFlow Error: P_Keyed_Windows receives tuple serializer/deserializer with an incremental logic" << DEFAULT_COLOR << std::endl;
exit(EXIT_FAILURE);
}
if (!isResultFunctions) {
std::cerr << RED << "WindFlow Error: P_Keyed_Windows instantiated with an incremental logic without result serializer/serializer" << DEFAULT_COLOR << std::endl;
exit(EXIT_FAILURE);
}
}
return p_keyed_wins_t(func,
key_extr,
this->parallelism,
Expand Down
19 changes: 5 additions & 14 deletions wf/persistent/p_window_replica.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ class P_Window_Replica: public Basic_Replica
return final_range;
}

#if 0
// getDistance method
size_t getDistance(const wrapper_t &_w1,
const wrapper_t &_w2,
Expand All @@ -254,6 +255,7 @@ class P_Window_Replica: public Basic_Replica
its.second = history_buffer.end();
return std::distance(its.first, its.second);
}
#endif

// getEnd method
input_iterator_t getEnd(Key_Descriptor &_kd)
Expand Down Expand Up @@ -336,17 +338,6 @@ class P_Window_Replica: public Basic_Replica
delete mydb_results;
}

/*
template<typename X>
rocksdb::DB *get_operator_internal_db()
{
if (std::is_same<X, tuple_t>::value) {
return mydb_wrappers->get_internal_db();
}
return mydb_results->get_internal_db();
}
*/

// svc (utilized by the FastFlow runtime)
void *svc(void *_in) override
{
Expand Down Expand Up @@ -504,9 +495,9 @@ class P_Window_Replica: public Basic_Replica
(this->context).setContextParameters(_timestamp, _watermark); // set the parameter of the RuntimeContext
func(iter, res, this->context);
}
}
if (t_s) { // purge tuples from the archive
purge(*t_s, key_d, key);
if (t_s) { // purge tuples from the archive
purge(*t_s, key_d, key);
}
}
cnt_fired++;
key_d.last_lwid++;
Expand Down
6 changes: 3 additions & 3 deletions wf/window_replica.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ class Window_Replica: public Basic_Replica
(this->context).setContextParameters(_timestamp, _watermark); // set the parameter of the RuntimeContext
func(iter, win.getResult(), this->context);
}
}
if (t_s) { // purge tuples from the archive
(key_d.archive).purge(*t_s);
if (t_s) { // purge tuples from the archive
(key_d.archive).purge(*t_s);
}
}
cnt_fired++;
key_d.last_lwid++;
Expand Down

0 comments on commit bb8d302

Please sign in to comment.