2011-06-23 19:17:08 +05:30
|
|
|
#ifndef TRANSACTION_MANAGER_H
|
|
|
|
#define TRANSACTION_MANAGER_H
|
|
|
|
|
|
|
|
#include "block.h"
|
|
|
|
#include "space_map.h"
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace persistent_data {
|
2011-07-22 20:39:56 +05:30
|
|
|
class transaction_manager : boost::noncopyable {
|
2011-06-23 19:17:08 +05:30
|
|
|
public:
|
2011-08-31 17:18:41 +05:30
|
|
|
typedef boost::shared_ptr<transaction_manager> ptr;
|
|
|
|
typedef typename block_manager<>::read_ref read_ref;
|
|
|
|
typedef typename block_manager<>::write_ref write_ref;
|
|
|
|
typedef typename block_manager<>::validator::ptr validator;
|
2011-06-23 19:17:08 +05:30
|
|
|
|
2011-07-14 20:01:00 +05:30
|
|
|
// If the space map is persistent, then the caller should
|
|
|
|
// hold onto a reference and remember to call sm_->commit()
|
|
|
|
// and update the superblock before dropping the superblock
|
|
|
|
// reference.
|
2011-08-31 17:18:41 +05:30
|
|
|
transaction_manager(typename block_manager<>::ptr bm,
|
2011-06-23 19:17:08 +05:30
|
|
|
space_map::ptr sm);
|
|
|
|
~transaction_manager();
|
|
|
|
|
2011-07-14 20:01:00 +05:30
|
|
|
// Drop the superblock reference to commit
|
|
|
|
write_ref begin(block_address superblock);
|
|
|
|
write_ref begin(block_address superblock, validator v);
|
2011-06-23 19:17:08 +05:30
|
|
|
|
|
|
|
write_ref new_block();
|
2011-07-14 20:01:00 +05:30
|
|
|
write_ref new_block(validator v);
|
2011-06-23 19:17:08 +05:30
|
|
|
|
2011-07-14 20:01:00 +05:30
|
|
|
// shadowing returns a new write_ref, and a boolean which
|
|
|
|
// indicates whether the children should be incremented.
|
|
|
|
std::pair<write_ref, bool> shadow(block_address orig);
|
|
|
|
std::pair<write_ref, bool> shadow(block_address orig, validator v);
|
2011-06-23 19:17:08 +05:30
|
|
|
|
|
|
|
read_ref read_lock(block_address b);
|
2011-07-14 20:01:00 +05:30
|
|
|
read_ref read_lock(block_address b, validator v);
|
2011-06-23 19:17:08 +05:30
|
|
|
|
2011-07-14 20:01:00 +05:30
|
|
|
space_map::ptr get_sm() {
|
|
|
|
return sm_;
|
|
|
|
}
|
2011-06-23 19:17:08 +05:30
|
|
|
|
2011-08-31 17:18:41 +05:30
|
|
|
typename block_manager<>::ptr get_bm() {
|
2011-07-22 20:39:56 +05:30
|
|
|
return bm_;
|
|
|
|
}
|
|
|
|
|
2011-06-23 19:17:08 +05:30
|
|
|
private:
|
|
|
|
void add_shadow(block_address b);
|
2011-07-14 20:01:00 +05:30
|
|
|
void remove_shadow(block_address b);
|
|
|
|
bool is_shadow(block_address b) const;
|
2011-06-23 19:17:08 +05:30
|
|
|
void wipe_shadow_table();
|
|
|
|
|
2011-08-31 17:18:41 +05:30
|
|
|
typename block_manager<>::ptr bm_;
|
2011-06-23 19:17:08 +05:30
|
|
|
space_map::ptr sm_;
|
|
|
|
|
|
|
|
std::set<block_address> shadows_;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
#endif
|