2010-05-19 23:42:06 +00:00
|
|
|
/*
|
|
|
|
* mergeManager.h
|
|
|
|
*
|
|
|
|
* Created on: May 19, 2010
|
|
|
|
* Author: sears
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MERGEMANAGER_H_
|
|
|
|
#define MERGEMANAGER_H_
|
|
|
|
|
|
|
|
#include <stasis/common.h>
|
|
|
|
#undef try
|
|
|
|
#undef end
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <stdio.h>
|
2010-05-21 23:43:17 +00:00
|
|
|
#include <datatuple.h>
|
|
|
|
|
|
|
|
template<class TUPLE>
|
|
|
|
class logtable;
|
2010-05-19 23:42:06 +00:00
|
|
|
class mergeStats;
|
|
|
|
|
|
|
|
class mergeManager {
|
2010-05-26 00:58:17 +00:00
|
|
|
public:
|
2010-06-21 22:59:05 +00:00
|
|
|
static const int UPDATE_PROGRESS_DELTA = 10 * 1024 * 1024;
|
2010-07-14 21:46:27 +00:00
|
|
|
const double UPDATE_PROGRESS_PERIOD; // in seconds, defined in constructor.
|
2010-06-21 22:59:05 +00:00
|
|
|
static const int FORCE_INTERVAL = 25 * 1024 * 1024;
|
2010-06-02 21:47:58 +00:00
|
|
|
static double tv_to_double(struct timeval * tv) {
|
2010-05-19 23:42:06 +00:00
|
|
|
return (double)tv->tv_sec + ((double)tv->tv_usec)/1000000.0;
|
|
|
|
}
|
2010-06-02 21:47:58 +00:00
|
|
|
static double ts_to_double(struct timespec * ts) {
|
2010-05-19 23:42:06 +00:00
|
|
|
return (double)ts->tv_sec + ((double)ts->tv_nsec)/1000000000.0;
|
|
|
|
}
|
2010-06-02 21:47:58 +00:00
|
|
|
static void double_to_ts(struct timespec *ts, double time) {
|
2010-05-19 23:42:06 +00:00
|
|
|
ts->tv_sec = (time_t)(time);
|
|
|
|
ts->tv_nsec = (long)((time - (double)ts->tv_sec) * 1000000000.0);
|
|
|
|
}
|
|
|
|
uint64_t long_tv(struct timeval& tv) {
|
|
|
|
return (1000000ULL * (uint64_t)tv.tv_sec) + ((uint64_t)tv.tv_usec);
|
|
|
|
}
|
2010-05-21 23:43:17 +00:00
|
|
|
mergeManager(logtable<datatuple> *ltable);
|
2010-05-19 23:42:06 +00:00
|
|
|
|
|
|
|
~mergeManager();
|
|
|
|
|
2010-06-02 21:47:58 +00:00
|
|
|
void new_merge(int mergelevel);
|
2010-05-19 23:42:06 +00:00
|
|
|
void set_c0_size(int64_t size);
|
2010-06-05 00:41:52 +00:00
|
|
|
void update_progress(mergeStats *s, int delta);
|
|
|
|
void tick(mergeStats * s, bool block, bool force = false);
|
2010-05-26 00:58:17 +00:00
|
|
|
mergeStats* get_merge_stats(int mergeLevel);
|
2010-06-02 21:47:58 +00:00
|
|
|
void read_tuple_from_small_component(int merge_level, datatuple * tup);
|
2010-06-05 00:41:52 +00:00
|
|
|
void read_tuple_from_large_component(int merge_level, datatuple * tup);
|
2010-06-02 21:47:58 +00:00
|
|
|
void wrote_tuple(int merge_level, datatuple * tup);
|
|
|
|
void finished_merge(int merge_level);
|
|
|
|
void pretty_print(FILE * out);
|
2010-05-19 23:42:06 +00:00
|
|
|
|
|
|
|
private:
|
2010-05-21 23:43:17 +00:00
|
|
|
logtable<datatuple>* ltable;
|
2010-05-19 23:42:06 +00:00
|
|
|
double throttle_seconds;
|
2010-05-26 00:58:17 +00:00
|
|
|
// double elapsed_seconds;
|
2010-05-19 23:42:06 +00:00
|
|
|
double last_throttle_seconds;
|
2010-05-26 00:58:17 +00:00
|
|
|
// double last_elapsed_seconds;
|
2010-05-19 23:42:06 +00:00
|
|
|
mergeStats * c0;
|
|
|
|
mergeStats * c1;
|
|
|
|
mergeStats * c2;
|
|
|
|
pthread_mutex_t throttle_mut;
|
|
|
|
pthread_mutex_t dummy_throttle_mut;
|
|
|
|
pthread_cond_t dummy_throttle_cond;
|
2010-05-27 23:15:24 +00:00
|
|
|
pthread_cond_t throttle_wokeup_cond;
|
|
|
|
bool sleeping[3];
|
2010-05-19 23:42:06 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
#endif /* MERGEMANAGER_H_ */
|