Added getRecordType()

This commit is contained in:
Sears Russell 2004-11-24 23:25:36 +00:00
parent f0dfa98b8e
commit 80d4af4c9b
3 changed files with 54 additions and 1 deletions

View file

@ -304,6 +304,48 @@ void readRecordUnlocked(int xid, Page * p, recordid rid, void *buf) {
}
assert(rid.page == p->id);
}
/** @TODO getRecordType is a hack. Instead, each record type should
implement code that decides whether a record exists, and returns its size
or -1. Then, getRecordType coudl call that function directly depending on
page type, etc.
A complementary function getRecordSize could return the size value.
*/
int getRecordTypeUnlocked(int xid, Page * p, recordid rid) {
assert(rid.page == p->id);
int page_type = *page_type_ptr(p);
if(page_type == UNINITIALIZED_PAGE) {
return UNINITIALIZED_RECORD;
} else if(rid.size > BLOB_THRESHOLD_SIZE) {
// printf("%d , %d\n", *numslots_ptr(p), *slot_length_ptr(p, rid.slot));
return(*numslots_ptr(p) > rid.slot &&
*slot_length_ptr(p, rid.slot) == BLOB_REC_SIZE) ?
BLOB_RECORD : UNINITIALIZED_RECORD;
} else if(page_type == SLOTTED_PAGE) {
return (*numslots_ptr(p) > rid.slot &&
*slot_length_ptr(p, rid.slot) != INVALID_SLOT) ?
SLOTTED_RECORD : UNINITIALIZED_RECORD;
} else if(page_type == FIXED_PAGE || page_type == ARRAY_LIST_PAGE) {
return (fixedPageCount(p) > rid.slot) ?
FIXED_RECORD : UNINITIALIZED_RECORD;
} else {
abort();
return UNINITIALIZED_RECORD;
}
}
int getRecordType(int xid, Page * p, recordid rid) {
readlock(p->rwlatch, 343);
int ret = getRecordTypeUnlocked(xid, p, rid);
unlock(p->rwlatch);
return ret;
}
void writeRecordUnlocked(int xid, Page * p, lsn_t lsn, recordid rid, const void *dat) {

View file

@ -88,7 +88,7 @@ terms specified in this license.
#include <lladd/transactional.h>
#include <lladd/bufferManager.h>
#include "../../src/lladd/page.h"
BEGIN_C_DECLS
@ -111,6 +111,13 @@ BEGIN_C_DECLS
#define USABLE_SIZE_OF_PAGE (PAGE_SIZE - sizeof(lsn_t) - sizeof(int))
#define UNINITIALIZED_RECORD 0
#define BLOB_RECORD 1
#define SLOTTED_RECORD 2
#define FIXED_RECORD 3
/*#define invalidateSlot(page, n) (*slot_ptr((page), (n)) = INVALID_SLOT)*/
/**
@ -273,6 +280,9 @@ void pageRealloc(Page * p, int id);
*/
/*int pageAlloc() ;*/
int getRecordType(int xid, Page * p, recordid rid);
int getRecordTypeUnlocked(int xid, Page * p, recordid rid);
END_C_DECLS
#endif

View file

@ -8,6 +8,7 @@
#define fixed_record_ptr(page, n) bytes_from_start((page), *recordsize_ptr((page)) * (n))
int recordsPerPage(size_t size);
void fixedPageInitialize(Page * page, size_t size, int count);
/** Return the number of records in a fixed length page */
short fixedPageCount(Page * page);
short fixedPageRecordSize(Page * page);
recordid fixedRawRallocMany(Page * page, int count);