Made pageWriteLSN static.
This commit is contained in:
parent
d564b9ded6
commit
282d284035
5 changed files with 53 additions and 262 deletions
|
@ -99,7 +99,7 @@ extern int errno;
|
||||||
#define lsn_t long
|
#define lsn_t long
|
||||||
|
|
||||||
#define DEBUGGING
|
#define DEBUGGING
|
||||||
#define PROFILE_LATCHES
|
/*#define PROFILE_LATCHES*/
|
||||||
|
|
||||||
#ifdef DEBUGGING
|
#ifdef DEBUGGING
|
||||||
/** @todo Files that use DEBUG have to pull in stdio.h, which is a pain! */
|
/** @todo Files that use DEBUG have to pull in stdio.h, which is a pain! */
|
||||||
|
|
153
lladd/page.h
153
lladd/page.h
|
@ -91,107 +91,7 @@ void pageInit();
|
||||||
* as a parameter a Page. The Page struct contains the new LSN and the page
|
* as a parameter a Page. The Page struct contains the new LSN and the page
|
||||||
* number to which the new LSN must be written to.
|
* number to which the new LSN must be written to.
|
||||||
*/
|
*/
|
||||||
void pageWriteLSN(Page page);
|
/*void pageWriteLSN(Page page);*/
|
||||||
|
|
||||||
/**
|
|
||||||
* assumes that the page is already loaded in memory. It takes
|
|
||||||
* as a parameter a Page and returns the LSN that is currently written on that
|
|
||||||
* page in memory.
|
|
||||||
*/
|
|
||||||
lsn_t/*---
|
|
||||||
This software is copyrighted by the Regents of the University of
|
|
||||||
California, and other parties. The following terms apply to all files
|
|
||||||
associated with the software unless explicitly disclaimed in
|
|
||||||
individual files.
|
|
||||||
|
|
||||||
The authors hereby grant permission to use, copy, modify, distribute,
|
|
||||||
and license this software and its documentation for any purpose,
|
|
||||||
provided that existing copyright notices are retained in all copies
|
|
||||||
and that this notice is included verbatim in any distributions. No
|
|
||||||
written agreement, license, or royalty fee is required for any of the
|
|
||||||
authorized uses. Modifications to this software may be copyrighted by
|
|
||||||
their authors and need not follow the licensing terms described here,
|
|
||||||
provided that the new terms are clearly indicated on the first page of
|
|
||||||
each file where they apply.
|
|
||||||
|
|
||||||
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
|
|
||||||
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
||||||
ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
|
|
||||||
DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
|
|
||||||
POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
|
|
||||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
|
||||||
NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND
|
|
||||||
THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
|
|
||||||
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
||||||
|
|
||||||
GOVERNMENT USE: If you are acquiring this software on behalf of the
|
|
||||||
U.S. government, the Government shall have only "Restricted Rights" in
|
|
||||||
the software and related documentation as defined in the Federal
|
|
||||||
Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you are
|
|
||||||
acquiring the software on behalf of the Department of Defense, the
|
|
||||||
software shall be classified as "Commercial Computer Software" and the
|
|
||||||
Government shall have only "Restricted Rights" as defined in Clause
|
|
||||||
252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
|
|
||||||
authors grant the U.S. Government and others acting in its behalf
|
|
||||||
permission to use and distribute the software in accordance with the
|
|
||||||
terms specified in this license.
|
|
||||||
---*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file
|
|
||||||
*
|
|
||||||
* interface for dealing with slotted pages
|
|
||||||
*
|
|
||||||
* @ingroup LLADD_CORE
|
|
||||||
* $Id$
|
|
||||||
*
|
|
||||||
* @todo update docs in this file.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#ifndef __PAGE_H__
|
|
||||||
#define __PAGE_H__
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
BEGIN_C_DECLS
|
|
||||||
|
|
||||||
/**
|
|
||||||
* represents how to look up a record on a page
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
int page;
|
|
||||||
int slot;
|
|
||||||
long size;
|
|
||||||
} recordid;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct Page_s {
|
|
||||||
int id;
|
|
||||||
long LSN;
|
|
||||||
byte *memAddr;
|
|
||||||
int dirty;
|
|
||||||
struct Page_s *next;
|
|
||||||
/** for replacement policy */
|
|
||||||
struct Page_s *prev;
|
|
||||||
/** this too */
|
|
||||||
int queue;
|
|
||||||
} Page;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* initializes all the important variables needed in all the
|
|
||||||
* functions dealing with pages.
|
|
||||||
*/
|
|
||||||
void pageInit();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* assumes that the page is already loaded in memory. It takes
|
|
||||||
* as a parameter a Page. The Page struct contains the new LSN and the page
|
|
||||||
* number to which the new LSN must be written to.
|
|
||||||
*/
|
|
||||||
void pageWriteLSN(Page page);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* assumes that the page is already loaded in memory. It takes
|
* assumes that the page is already loaded in memory. It takes
|
||||||
|
@ -224,56 +124,7 @@ int freespace(Page page);
|
||||||
*/
|
*/
|
||||||
recordid pageRalloc(Page page, int size);
|
recordid pageRalloc(Page page, int size);
|
||||||
|
|
||||||
void pageWriteRecord(int xid, Page page, recordid rid, const byte *data);
|
void pageWriteRecord(int xid, Page page, recordid rid, lsn_t lsn, const byte *data);
|
||||||
|
|
||||||
void pageReadRecord(int xid, Page page, recordid rid, byte *buff);
|
|
||||||
|
|
||||||
void pageCommit(int xid);
|
|
||||||
|
|
||||||
void pageAbort(int xid);
|
|
||||||
|
|
||||||
void pageRealloc(Page *p, int id);
|
|
||||||
|
|
||||||
Page* pageAlloc(int id);
|
|
||||||
|
|
||||||
recordid pageSlotRalloc(Page page, lsn_t lsn, recordid rid);
|
|
||||||
|
|
||||||
int pageTest();
|
|
||||||
|
|
||||||
int getSlotType(Page p, int slot, int type);
|
|
||||||
void setSlotType(Page p, int slot, int type);
|
|
||||||
|
|
||||||
|
|
||||||
END_C_DECLS
|
|
||||||
|
|
||||||
#endif
|
|
||||||
pageReadLSN(Page page);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* assumes that the page is already loaded in memory. It takes as a
|
|
||||||
* parameter a Page, and returns an estimate of the amount of free space on this
|
|
||||||
* page. This is either exact, or an underestimate.
|
|
||||||
*/
|
|
||||||
int freespace(Page page);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* assumes that the page is already loaded in memory. It takes as
|
|
||||||
* parameters a Page and the size in bytes of the new record. pageRalloc()
|
|
||||||
* returns a recordid representing the newly allocated record.
|
|
||||||
*
|
|
||||||
* NOTE: might want to pad records to be multiple of words in length, or, simply
|
|
||||||
* make sure all records start word aligned, but not necessarily having
|
|
||||||
* a length that is a multiple of words. (Since Tread(), Twrite() ultimately
|
|
||||||
* call memcpy(), this shouldn't be an issue)
|
|
||||||
*
|
|
||||||
* NOTE: pageRalloc() assumes that the caller already made sure that sufficient
|
|
||||||
* amount of freespace exists in this page. (@see freespace())
|
|
||||||
*
|
|
||||||
* @todo Makes no attempt to reuse old recordid's.
|
|
||||||
*/
|
|
||||||
recordid pageRalloc(Page page, int size);
|
|
||||||
|
|
||||||
void pageWriteRecord(int xid, Page page, recordid rid, const byte *data);
|
|
||||||
|
|
||||||
void pageReadRecord(int xid, Page page, recordid rid, byte *buff);
|
void pageReadRecord(int xid, Page page, recordid rid, byte *buff);
|
||||||
|
|
||||||
|
|
9
reconf-1.8
Executable file
9
reconf-1.8
Executable file
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/sh
|
||||||
|
rm -f config.cache
|
||||||
|
rm -f acconfig.h
|
||||||
|
aclocal-1.8 -I m4
|
||||||
|
autoconf
|
||||||
|
autoheader
|
||||||
|
libtoolize --automake
|
||||||
|
automake-1.8 -a
|
||||||
|
exit
|
|
@ -145,74 +145,10 @@ static void closePageFile() {
|
||||||
stable = NULL;
|
stable = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* void pageMap(Page *ret) {
|
|
||||||
pageRead(ret);
|
|
||||||
}
|
|
||||||
int flushPage(Page ret) {
|
|
||||||
pageWrite(&ret);
|
|
||||||
return 0;
|
|
||||||
} */
|
|
||||||
|
|
||||||
/*
|
|
||||||
void pageMap(Page *ret) {
|
|
||||||
|
|
||||||
int fileSize;
|
|
||||||
/ * this was lseek(stable, SEEK_SET, pageid*PAGE_SIZE), but changed to
|
|
||||||
lseek(stable, pageid*PAGE_SIZE, SEEK_SET) by jkit (Wed Mar 24 12:59:18 PST 2004)* /
|
|
||||||
fileSize = lseek(stable, 0, SEEK_END);
|
|
||||||
|
|
||||||
if ((ret->id)*PAGE_SIZE >= fileSize) {
|
|
||||||
lseek(stable, (1 + ret->id)*PAGE_SIZE -1 , SEEK_SET);
|
|
||||||
write(stable, "", 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if((ret->memAddr = mmap((void *) 0, PAGE_SIZE, (PROT_READ | PROT_WRITE), MAP_SHARED, stable, (ret->id)*PAGE_SIZE)) == (void*)-1) {
|
|
||||||
printf("ERROR: %i on %s line %d", errno, __FILE__, __LINE__);
|
|
||||||
exit(errno);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int flushPage(Page page) {
|
|
||||||
|
|
||||||
if( munmap(page.memAddr, PAGE_SIZE) )
|
|
||||||
return MEM_WRITE_ERROR;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
int bufInit() {
|
int bufInit() {
|
||||||
|
|
||||||
stable = NULL;
|
stable = NULL;
|
||||||
|
|
||||||
/* Create STORE_FILE, if necessary, then open it read/write
|
|
||||||
|
|
||||||
If we're creating it, then put one all-zero record at the beginning of it.
|
|
||||||
(Need to have at least one record in the PAGE file?)
|
|
||||||
|
|
||||||
It used to be that there was one file per page, and LSN needed to be set to -1.
|
|
||||||
|
|
||||||
Now, zero means uninitialized, so this could probably be replaced
|
|
||||||
with a call to open(... O_CREAT|O_RW) or something like that...
|
|
||||||
*/
|
|
||||||
/* if( (stable = open(STORE_FILE, O_RDWR, 0)) == -1 ) { / * file may not exist * /
|
|
||||||
void *zero = mmap(0, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); / * zero = /dev/zero * /
|
|
||||||
if( (stable = creat(STORE_FILE, 0666)) == -1 ) { / * cannot even create it * /
|
|
||||||
printf("ERROR: %i on %s line %d", errno, __FILE__, __LINE__);
|
|
||||||
exit(errno);
|
|
||||||
}
|
|
||||||
/ * kick off a fresh page * /
|
|
||||||
if( write(stable, zero, PAGE_SIZE) != PAGE_SIZE ) { / * write zeros out * /
|
|
||||||
printf("ERROR: %i on %s line %d", errno, __FILE__, __LINE__);
|
|
||||||
exit(errno);
|
|
||||||
}
|
|
||||||
if( close(stable) || ((stable = open(STORE_FILE, O_RDWR, 0)) == -1) ) { / * need to reopen with read perms * /
|
|
||||||
printf("ERROR: %i on %s line %d", errno, __FILE__, __LINE__);
|
|
||||||
exit(errno);
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
|
|
||||||
openPageFile();
|
openPageFile();
|
||||||
pageCacheInit();
|
pageCacheInit();
|
||||||
openBlobStore();
|
openBlobStore();
|
||||||
|
@ -225,10 +161,6 @@ void bufDeinit() {
|
||||||
closeBlobStore();
|
closeBlobStore();
|
||||||
pageCacheDeinit();
|
pageCacheDeinit();
|
||||||
closePageFile();
|
closePageFile();
|
||||||
/* if( close(stable) ) {
|
|
||||||
printf("ERROR: %i on %s line %d", errno, __FILE__, __LINE__);
|
|
||||||
exit(errno);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -258,33 +190,24 @@ recordid ralloc(int xid, /*lsn_t lsn,*/ long size) {
|
||||||
recordid ret;
|
recordid ret;
|
||||||
Page p;
|
Page p;
|
||||||
|
|
||||||
DEBUG("Rallocing blob of size %ld\n", (long int)size);
|
DEBUG("Rallocing record of size %ld\n", (long int)size);
|
||||||
|
|
||||||
assert(size < BLOB_THRESHOLD_SIZE || size == BLOB_SLOT);
|
assert(size < BLOB_THRESHOLD_SIZE || size == BLOB_SLOT);
|
||||||
|
|
||||||
/* if (size >= BLOB_THRESHOLD_SIZE) {
|
|
||||||
|
|
||||||
ret = allocBlob(xid, lsn, size);
|
|
||||||
|
|
||||||
} else { */
|
|
||||||
|
|
||||||
while(freespace(p = loadPage(lastFreepage)) < size ) { lastFreepage++; }
|
while(freespace(p = loadPage(lastFreepage)) < size ) { lastFreepage++; }
|
||||||
|
|
||||||
ret = pageRalloc(p, size);
|
ret = pageRalloc(p, size);
|
||||||
|
|
||||||
/* } */
|
|
||||||
DEBUG("alloced rid = {%d, %d, %ld}\n", ret.page, ret.slot, ret.size);
|
DEBUG("alloced rid = {%d, %d, %ld}\n", ret.page, ret.slot, ret.size);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
long readLSN(int pageid) {
|
long readLSN(int pageid) {
|
||||||
|
|
||||||
return pageReadLSN(loadPage(pageid));
|
return pageReadLSN(loadPage(pageid));
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
static void writeLSN(lsn_t LSN, int pageid) {
|
|
||||||
Page *p = loadPagePtr(pageid);
|
|
||||||
p->LSN = LSN;
|
|
||||||
pageWriteLSN(*p);
|
|
||||||
}*/
|
|
||||||
void writeRecord(int xid, lsn_t lsn, recordid rid, const void *dat) {
|
void writeRecord(int xid, lsn_t lsn, recordid rid, const void *dat) {
|
||||||
|
|
||||||
Page *p;
|
Page *p;
|
||||||
|
@ -300,18 +223,23 @@ void writeRecord(int xid, lsn_t lsn, recordid rid, const void *dat) {
|
||||||
/** @todo This assert should be here, but the tests are broken, so it causes bogus failures. */
|
/** @todo This assert should be here, but the tests are broken, so it causes bogus failures. */
|
||||||
/*assert(pageReadLSN(*p) <= lsn);*/
|
/*assert(pageReadLSN(*p) <= lsn);*/
|
||||||
|
|
||||||
pageWriteRecord(xid, *p, rid, dat);
|
/** @todo Should pageWriteRecord take an LSN (so it can do the locking?) */
|
||||||
/* writeLSN(lsn, rid.page); */
|
/* pageWriteRecord(xid, *p, rid, dat);
|
||||||
p->LSN = lsn;
|
p->LSN = lsn;
|
||||||
pageWriteLSN(*p);
|
pageWriteLSN(*p); */
|
||||||
|
pageWriteRecord(xid, *p, rid, lsn, dat);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void readRecord(int xid, recordid rid, void *buf) {
|
void readRecord(int xid, recordid rid, void *buf) {
|
||||||
if(rid.size > BLOB_THRESHOLD_SIZE) {
|
if(rid.size > BLOB_THRESHOLD_SIZE) {
|
||||||
DEBUG("Reading blob. xid = %d rid = { %d %d %ld } buf = %x\n", xid, rid.page, rid.slot, rid.size, (unsigned int)buf);
|
DEBUG("Reading blob. xid = %d rid = { %d %d %ld } buf = %x\n",
|
||||||
|
xid, rid.page, rid.slot, rid.size, (unsigned int)buf);
|
||||||
readBlob(xid, rid, buf);
|
readBlob(xid, rid, buf);
|
||||||
} else {
|
} else {
|
||||||
DEBUG("Reading record xid = %d rid = { %d %d %ld } buf = %x\n", xid, rid.page, rid.slot, rid.size, (unsigned int)buf);
|
DEBUG("Reading record xid = %d rid = { %d %d %ld } buf = %x\n",
|
||||||
|
xid, rid.page, rid.slot, rid.size, (unsigned int)buf);
|
||||||
pageReadRecord(xid, loadPage(rid.page), rid, buf);
|
pageReadRecord(xid, loadPage(rid.page), rid, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,7 +224,7 @@ lsn_t pageReadLSN(Page page) {
|
||||||
* as a parameter a Page. The Page struct contains the new LSN and the page
|
* as a parameter a Page. The Page struct contains the new LSN and the page
|
||||||
* number to which the new LSN must be written to.
|
* number to which the new LSN must be written to.
|
||||||
*/
|
*/
|
||||||
void pageWriteLSN(Page page) {
|
static void pageWriteLSN(Page page) {
|
||||||
*(long *)(page.memAddr + START_OF_LSN) = page.LSN;
|
*(long *)(page.memAddr + START_OF_LSN) = page.LSN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -445,7 +445,7 @@ void pageReadRecord(int xid, Page page, recordid rid, byte *buff) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pageWriteRecord(int xid, Page page, recordid rid, const byte *data) {
|
void pageWriteRecord(int xid, Page page, recordid rid, lsn_t lsn, const byte *data) {
|
||||||
|
|
||||||
byte *rec;
|
byte *rec;
|
||||||
|
|
||||||
|
@ -458,6 +458,9 @@ void pageWriteRecord(int xid, Page page, recordid rid, const byte *data) {
|
||||||
exit(MEM_WRITE_ERROR);
|
exit(MEM_WRITE_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
page.LSN = lsn;
|
||||||
|
pageWriteLSN(page);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pageRealloc(Page *p, int id) {
|
void pageRealloc(Page *p, int id) {
|
||||||
|
@ -530,7 +533,7 @@ int pageTest() {
|
||||||
memset(page.memAddr, 0, PAGE_SIZE);
|
memset(page.memAddr, 0, PAGE_SIZE);
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
rid[i] = pageRalloc(page, strlen(str[i]) + 1);
|
rid[i] = pageRalloc(page, strlen(str[i]) + 1);
|
||||||
pageWriteRecord(0, page, rid[i], (byte*)str[i]);
|
pageWriteRecord(0, page, rid[i], 1, (byte*)str[i]);
|
||||||
}
|
}
|
||||||
printPage(page.memAddr);
|
printPage(page.memAddr);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue