00001 #ifndef SHADOW_SEGMENT_H
00002 #define SHADOW_SEGMENT_H
00003
00009 #include"errorclass.h"
00010 #include"pmseg.h"
00011 #include"rpointer.h"
00012 #include"bitmap.h"
00013 #include"reliable.h"
00014
00015 #ifndef PAGESIZE
00016 #define PAGESIZE 4096
00017 #endif
00018
00019
00020 #define MAXPAGES 1024
00021
00022 typedef unsigned long Pageno;
00023 typedef unsigned long index_t;
00024 struct Pageentry
00025 {
00026 unsigned long shadowbit:1;
00027 unsigned long pageno:31;
00028 };
00029
00030 const unsigned long UNDEFINED_PAGE=0x7fffffff;
00031
00032
00033 inline off_t index2offset(index_t in) { return in<<12; }
00034 inline index_t offset2index(off_t o) { return o>>12; }
00035
00042 class SegmentVersion
00043 {
00044 size_t count_;
00045 Pageentry entry[1];
00046 public:
00047 size_t maxcount() { return (PAGESIZE-sizeof(size_t))/sizeof(Pageentry); }
00048 Pageentry &operator[](index_t i) { return entry[i]; }
00049 size_t rsize() { return sizeof(size_t)+count_*sizeof(Pageentry); }
00050 size_t size() { return PAGESIZE; }
00051 size_t count() { return count_; }
00052 void grow(int anz) { assert(count_+anz <= maxcount()); count_+=anz; }
00053 int clearallshadowbits();
00054 static SegmentVersion *init(char *puffer,int len);
00055
00057 void print(ostream& str);
00058 };
00059
00063 struct MasterLayout
00064 {
00065 off_t mc;
00066 off_t m0;
00067 off_t m1;
00068 long status;
00069
00070
00071 };
00072
00078 class ShadowSegMaster
00079 {
00080 TwinblockStrategy tws;
00081 ReliableSegment rseg;
00082 RAMS::RPointer<BitMap> mc,m0,m1;
00083
00084 public:
00085 ShadowSegMaster();
00089 int open(char *name);
00090 BitMap& CurrentM() { return *(mc.ptr()); }
00091 BitMap& M0() { return *(m0.ptr()); }
00092 BitMap& M1() { return *(m1.ptr()); }
00093 void save();
00094 int getstatus() { return ((MasterLayout *)rseg.begin())->status; }
00095 void setstatus(int s) { ((MasterLayout *)rseg.begin())->status=s; }
00096 void copyandswitchm();
00097 void druckebelegtliste();
00098 };
00099
00103 class ShadowSegment : public PMSeg
00104 {
00105 char svpuffer[2*PAGESIZE];
00106 SegmentVersion *vw[2];
00107 ShadowSegMaster ssm;
00109 int sfd;
00111 int vfd;
00112 SegmentVersion &Vwork() { return *vw[0]; }
00113 SegmentVersion &Vold() { return *vw[1]; }
00114 void readsegversions() throw(Systemerror);
00120 void savesegversion(int nr,int snr) throw(Systemerror);
00121 void save();
00123 void reopen();
00125 void clearshadowbitsandfree();
00126
00128 void recover();
00129
00130 public:
00131 ShadowSegment() { sfd=-1; vfd=-1; }
00132 void init();
00133 void open(const char *name) throw(Systemerror);
00134
00135 void close() { save(); }
00136 void checkpoint() { save(); reopen(); }
00137 void rollback();
00138
00140 void handle(void *page,void *addr);
00141 };
00142 #endif
00143
00144
00145
00146
00147