2007-06-07 21:53:09 +00:00
|
|
|
#include <assert.h>
|
2008-04-13 04:02:57 +00:00
|
|
|
#include <stasis/page.h>
|
|
|
|
#include <stasis/page/fixed.h>
|
2007-06-07 21:53:09 +00:00
|
|
|
/** @todo should page implementations provide readLSN / writeLSN??? */
|
2007-06-11 21:36:57 +00:00
|
|
|
#include <stasis/truncation.h>
|
2004-10-06 06:08:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2007-10-02 00:18:33 +00:00
|
|
|
int stasis_fixed_records_per_page(size_t size) {
|
2004-10-06 06:08:09 +00:00
|
|
|
return (USABLE_SIZE_OF_PAGE - 2*sizeof(short)) / size;
|
|
|
|
}
|
2007-10-02 00:18:33 +00:00
|
|
|
/** @todo CORRECTNESS Locking for stasis_fixed_initialize_page? (should hold writelock)*/
|
|
|
|
void stasis_fixed_initialize_page(Page * page, size_t size, int count) {
|
2007-06-07 21:53:09 +00:00
|
|
|
assertlocked(page->rwlatch);
|
2007-11-12 07:27:49 +00:00
|
|
|
stasis_page_cleanup(page);
|
2007-10-02 00:18:33 +00:00
|
|
|
*stasis_page_type_ptr(page) = FIXED_PAGE;
|
2004-10-06 06:08:09 +00:00
|
|
|
*recordsize_ptr(page) = size;
|
2007-10-02 00:18:33 +00:00
|
|
|
assert(count <= stasis_fixed_records_per_page(size));
|
2004-10-06 06:08:09 +00:00
|
|
|
*recordcount_ptr(page)= count;
|
|
|
|
}
|
|
|
|
|
2007-06-07 21:53:09 +00:00
|
|
|
static void checkRid(Page * page, recordid rid) {
|
2007-06-01 21:32:33 +00:00
|
|
|
assertlocked(page->rwlatch);
|
2008-10-04 15:53:19 +00:00
|
|
|
assert(*stasis_page_type_ptr(page)); // any more specific breaks pages based on this one
|
2007-06-07 21:53:09 +00:00
|
|
|
assert(page->id == rid.page);
|
|
|
|
assert(*recordsize_ptr(page) == rid.size);
|
2007-10-02 00:18:33 +00:00
|
|
|
assert(stasis_fixed_records_per_page(rid.size) > rid.slot);
|
2004-10-06 06:08:09 +00:00
|
|
|
}
|
|
|
|
|
2007-06-07 21:53:09 +00:00
|
|
|
//-------------- New API below this line
|
|
|
|
|
|
|
|
static const byte* fixedRead(int xid, Page *p, recordid rid) {
|
|
|
|
assertlocked(p->rwlatch);
|
|
|
|
checkRid(p, rid);
|
|
|
|
assert(rid.slot < *recordcount_ptr(p));
|
|
|
|
return fixed_record_ptr(p, rid.slot);
|
2004-10-06 06:08:09 +00:00
|
|
|
}
|
|
|
|
|
2007-06-07 21:53:09 +00:00
|
|
|
static byte* fixedWrite(int xid, Page *p, recordid rid) {
|
|
|
|
assertlocked(p->rwlatch);
|
|
|
|
checkRid(p, rid);
|
|
|
|
assert(rid.slot < *recordcount_ptr(p));
|
|
|
|
return fixed_record_ptr(p, rid.slot);
|
|
|
|
}
|
2004-10-06 06:08:09 +00:00
|
|
|
|
2007-06-07 21:53:09 +00:00
|
|
|
static int fixedGetType(int xid, Page *p, recordid rid) {
|
|
|
|
assertlocked(p->rwlatch);
|
|
|
|
// checkRid(p, rid);
|
|
|
|
if(rid.slot < *recordcount_ptr(p)) {
|
|
|
|
int type = *recordsize_ptr(p);
|
|
|
|
if(type > 0) {
|
|
|
|
type = NORMAL_SLOT;
|
|
|
|
}
|
|
|
|
return type;
|
2004-10-06 06:08:09 +00:00
|
|
|
} else {
|
2007-06-07 21:53:09 +00:00
|
|
|
return INVALID_SLOT;
|
2004-10-06 06:08:09 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-07 21:53:09 +00:00
|
|
|
static void fixedSetType(int xid, Page *p, recordid rid, int type) {
|
|
|
|
assertlocked(p->rwlatch);
|
|
|
|
checkRid(p,rid);
|
|
|
|
assert(rid.slot < *recordcount_ptr(p));
|
2007-10-03 01:53:51 +00:00
|
|
|
assert(stasis_record_type_to_size(type) == stasis_record_type_to_size(*recordsize_ptr(p)));
|
2007-06-07 21:53:09 +00:00
|
|
|
*recordsize_ptr(p) = rid.size;
|
|
|
|
}
|
|
|
|
static int fixedGetLength(int xid, Page *p, recordid rid) {
|
|
|
|
assertlocked(p->rwlatch);
|
2007-10-02 00:18:33 +00:00
|
|
|
assert(*stasis_page_type_ptr(p));
|
2007-08-20 16:04:44 +00:00
|
|
|
return rid.slot > *recordcount_ptr(p) ?
|
2007-10-03 01:53:51 +00:00
|
|
|
INVALID_SLOT : stasis_record_type_to_size(*recordsize_ptr(p));
|
2007-06-07 21:53:09 +00:00
|
|
|
}
|
2007-08-20 21:58:20 +00:00
|
|
|
|
2007-07-18 20:09:14 +00:00
|
|
|
static int notSupported(int xid, Page * p) { return 0; }
|
2007-06-07 21:53:09 +00:00
|
|
|
|
|
|
|
static int fixedFreespace(int xid, Page * p) {
|
|
|
|
assertlocked(p->rwlatch);
|
2007-10-02 00:18:33 +00:00
|
|
|
if(stasis_fixed_records_per_page(*recordsize_ptr(p)) > *recordcount_ptr(p)) {
|
2007-06-07 21:53:09 +00:00
|
|
|
// Return the size of a slot; that's the biggest record we can take.
|
2007-10-03 01:53:51 +00:00
|
|
|
return stasis_record_type_to_size(*recordsize_ptr(p));
|
2004-10-19 04:45:42 +00:00
|
|
|
} else {
|
2007-06-07 21:53:09 +00:00
|
|
|
// Page full; return zero.
|
|
|
|
return 0;
|
2004-10-19 04:45:42 +00:00
|
|
|
}
|
2004-10-06 06:08:09 +00:00
|
|
|
}
|
2007-06-07 21:53:09 +00:00
|
|
|
static void fixedCompact(Page * p) {
|
|
|
|
// no-op
|
|
|
|
}
|
|
|
|
static recordid fixedPreAlloc(int xid, Page *p, int size) {
|
|
|
|
assertlocked(p->rwlatch);
|
2007-10-02 00:18:33 +00:00
|
|
|
if(stasis_fixed_records_per_page(*recordsize_ptr(p)) > *recordcount_ptr(p)) {
|
2007-06-07 21:53:09 +00:00
|
|
|
recordid rid;
|
|
|
|
rid.page = p->id;
|
|
|
|
rid.slot = *recordcount_ptr(p);
|
|
|
|
rid.size = *recordsize_ptr(p);
|
|
|
|
return rid;
|
|
|
|
} else {
|
|
|
|
return NULLRID;
|
2004-10-06 06:08:09 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-07 21:53:09 +00:00
|
|
|
static void fixedPostAlloc(int xid, Page *p, recordid rid) {
|
|
|
|
assertlocked(p->rwlatch);
|
|
|
|
assert(*recordcount_ptr(p) == rid.slot);
|
|
|
|
assert(*recordsize_ptr(p) == rid.size);
|
|
|
|
(*recordcount_ptr(p))++;
|
2004-10-06 06:08:09 +00:00
|
|
|
}
|
2007-06-07 21:53:09 +00:00
|
|
|
static void fixedFree(int xid, Page *p, recordid rid) {
|
|
|
|
assertlocked(p->rwlatch);
|
|
|
|
if(*recordsize_ptr(p) == rid.slot+1) {
|
|
|
|
(*recordsize_ptr(p))--;
|
|
|
|
} else {
|
|
|
|
// leak space; there's no way to track it with this page format.
|
2004-10-06 06:08:09 +00:00
|
|
|
}
|
|
|
|
}
|
2007-07-18 20:09:14 +00:00
|
|
|
|
|
|
|
// XXX dereferenceRID
|
|
|
|
|
|
|
|
void fixedLoaded(Page *p) {
|
2007-10-02 00:18:33 +00:00
|
|
|
p->LSN = *stasis_page_lsn_ptr(p);
|
2007-07-18 20:09:14 +00:00
|
|
|
}
|
|
|
|
void fixedFlushed(Page *p) {
|
2007-10-02 00:18:33 +00:00
|
|
|
*stasis_page_lsn_ptr(p) = p->LSN;
|
2007-06-07 21:53:09 +00:00
|
|
|
}
|
2007-08-20 21:58:20 +00:00
|
|
|
void fixedCleanup(Page *p) { }
|
2007-06-07 21:53:09 +00:00
|
|
|
page_impl fixedImpl() {
|
|
|
|
static page_impl pi = {
|
|
|
|
FIXED_PAGE,
|
|
|
|
fixedRead,
|
|
|
|
fixedWrite,
|
2007-07-18 20:09:14 +00:00
|
|
|
0,// readDone
|
|
|
|
0,// writeDone
|
2007-06-07 21:53:09 +00:00
|
|
|
fixedGetType,
|
|
|
|
fixedSetType,
|
|
|
|
fixedGetLength,
|
2007-07-18 20:09:14 +00:00
|
|
|
fixedFirst,
|
|
|
|
fixedNext,
|
|
|
|
notSupported, // notSupported,
|
2007-10-02 00:18:33 +00:00
|
|
|
stasis_block_first_default_impl,
|
|
|
|
stasis_block_next_default_impl,
|
|
|
|
stasis_block_done_default_impl,
|
2007-06-07 21:53:09 +00:00
|
|
|
fixedFreespace,
|
|
|
|
fixedCompact,
|
|
|
|
fixedPreAlloc,
|
|
|
|
fixedPostAlloc,
|
|
|
|
fixedFree,
|
|
|
|
0, // XXX dereference
|
2007-07-18 20:09:14 +00:00
|
|
|
fixedLoaded, // loaded
|
|
|
|
fixedFlushed, // flushed
|
2007-08-20 21:58:20 +00:00
|
|
|
fixedCleanup
|
2007-06-07 21:53:09 +00:00
|
|
|
};
|
|
|
|
return pi;
|
|
|
|
}
|
2004-10-06 06:08:09 +00:00
|
|
|
|
2007-08-14 01:17:31 +00:00
|
|
|
/**
|
|
|
|
@todo arrayListImpl belongs in arrayList.c
|
|
|
|
*/
|
|
|
|
page_impl arrayListImpl() {
|
2007-06-07 21:53:09 +00:00
|
|
|
page_impl pi = fixedImpl();
|
|
|
|
pi.page_type = ARRAY_LIST_PAGE;
|
|
|
|
return pi;
|
2004-10-06 06:08:09 +00:00
|
|
|
}
|
2007-06-07 21:53:09 +00:00
|
|
|
|
|
|
|
void fixedPageInit() { }
|
|
|
|
void fixedPageDeinit() { }
|