2013-09-12 17:03:32 +05:30
|
|
|
#ifndef CACHE_HINT_ARRAY_H
|
|
|
|
#define CACHE_HINT_ARRAY_H
|
|
|
|
|
|
|
|
#include "persistent-data/data-structures/array.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace caching {
|
2013-10-08 15:13:20 +05:30
|
|
|
namespace hint_array_damage {
|
|
|
|
class damage_visitor;
|
2013-09-12 17:03:32 +05:30
|
|
|
|
2013-10-08 15:13:20 +05:30
|
|
|
class damage {
|
|
|
|
public:
|
|
|
|
damage(std::string const &desc)
|
|
|
|
: desc_(desc) {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~damage() {}
|
|
|
|
virtual void visit(damage_visitor &v) const = 0;
|
|
|
|
|
|
|
|
std::string get_desc() const {
|
|
|
|
return desc_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string desc_;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct missing_hints : public damage {
|
|
|
|
missing_hints(std::string const desc, run<uint32_t> const &keys);
|
|
|
|
virtual void visit(damage_visitor &v) const;
|
|
|
|
|
|
|
|
run<uint32_t> keys_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class damage_visitor {
|
|
|
|
public:
|
|
|
|
virtual ~damage_visitor() {}
|
|
|
|
|
2013-10-08 17:09:34 +05:30
|
|
|
void visit(damage const &d) {
|
2013-10-08 15:13:20 +05:30
|
|
|
d.visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void visit(missing_hints const &d) = 0;
|
|
|
|
};
|
2013-09-12 17:03:32 +05:30
|
|
|
}
|
|
|
|
|
2013-10-09 14:15:17 +05:30
|
|
|
class hint_visitor {
|
|
|
|
public:
|
|
|
|
virtual ~hint_visitor() {}
|
|
|
|
virtual void visit(block_address cblock, std::vector<unsigned char> const &data) = 0;
|
|
|
|
};
|
|
|
|
|
2013-09-24 16:30:09 +05:30
|
|
|
class hint_array {
|
|
|
|
public:
|
2020-04-30 19:32:43 +05:30
|
|
|
typedef std::shared_ptr<hint_array> ptr;
|
2013-09-24 16:30:09 +05:30
|
|
|
|
2014-08-26 15:44:49 +05:30
|
|
|
hint_array(transaction_manager &tm, unsigned width);
|
|
|
|
hint_array(transaction_manager &tm, unsigned width, block_address root, unsigned nr_entries);
|
2013-09-24 16:30:09 +05:30
|
|
|
|
|
|
|
unsigned get_nr_entries() const;
|
|
|
|
|
2013-10-08 15:13:20 +05:30
|
|
|
|
2013-09-24 16:30:09 +05:30
|
|
|
void grow(unsigned new_nr_entries, void const *v);
|
|
|
|
|
|
|
|
block_address get_root() const;
|
|
|
|
void get_hint(unsigned index, vector<unsigned char> &data) const;
|
|
|
|
void set_hint(unsigned index, vector<unsigned char> const &data);
|
|
|
|
|
2013-09-24 16:42:57 +05:30
|
|
|
void grow(unsigned new_nr_entries, vector<unsigned char> const &value);
|
2013-10-09 14:15:17 +05:30
|
|
|
void walk(hint_visitor &hv, hint_array_damage::damage_visitor &dv);
|
2013-10-08 15:30:05 +05:30
|
|
|
void check(hint_array_damage::damage_visitor &visitor);
|
2013-09-24 16:42:57 +05:30
|
|
|
|
2013-09-24 16:30:09 +05:30
|
|
|
private:
|
2013-10-14 17:10:13 +05:30
|
|
|
static uint32_t check_width(uint32_t width);
|
|
|
|
|
2013-09-24 16:30:09 +05:30
|
|
|
unsigned width_;
|
2020-04-30 19:32:43 +05:30
|
|
|
std::shared_ptr<persistent_data::array_base> impl_;
|
2013-09-24 16:30:09 +05:30
|
|
|
};
|
2013-09-12 17:03:32 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
#endif
|