2004-07-06 01:22:18 +00:00
|
|
|
#include <config.h>
|
|
|
|
#include <lladd/common.h>
|
|
|
|
|
2004-06-24 21:10:31 +00:00
|
|
|
#include <lladd/operations/alloc.h>
|
2004-07-06 01:22:18 +00:00
|
|
|
|
|
|
|
#include <lladd/transactional.h>
|
2004-06-24 21:10:31 +00:00
|
|
|
#include <lladd/bufferManager.h>
|
2004-06-30 01:09:57 +00:00
|
|
|
#include "../blobManager.h"
|
2004-07-23 20:21:44 +00:00
|
|
|
#include "../page.h"
|
2004-06-24 21:10:31 +00:00
|
|
|
/**
|
2004-07-20 03:40:57 +00:00
|
|
|
@file
|
|
|
|
|
2004-06-24 21:10:31 +00:00
|
|
|
Implementation of Talloc() as an operation
|
|
|
|
|
|
|
|
This is a bit strange compared to other operations, as it happens
|
|
|
|
in two phases. The buffer manager reserves space for a record
|
|
|
|
before the log entry is allocated. Then, the recordid of this
|
|
|
|
space is written to the log. Finally, alloc tells bufferManager
|
|
|
|
that it will use the space.
|
|
|
|
|
|
|
|
@todo Currently, if the system crashes during an alloc, (before the
|
|
|
|
log is flushed, but after bufferManager returns a rid), then the
|
|
|
|
space alloced during the crash is leaked. This doesn't seem to be
|
2004-06-28 22:48:02 +00:00
|
|
|
too big of a deal, but it should be fixed someday. A more serious
|
|
|
|
problem results from crashes during blob allocation.
|
2004-07-20 03:40:57 +00:00
|
|
|
|
|
|
|
@ingroup OPERATIONS
|
|
|
|
|
|
|
|
$Id$
|
2004-06-24 21:10:31 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2004-07-23 20:21:44 +00:00
|
|
|
static int operate(int xid, Page * p, lsn_t lsn, recordid rid, const void * dat) {
|
2004-06-30 01:09:57 +00:00
|
|
|
if(rid.size >= BLOB_THRESHOLD_SIZE) {
|
|
|
|
allocBlob(xid, lsn, rid);
|
|
|
|
} else {
|
2004-07-14 20:49:18 +00:00
|
|
|
/* Page * loadedPage = loadPage(rid.page); */
|
|
|
|
/* pageSlotRalloc(loadedPage, lsn, rid); */
|
|
|
|
|
2004-06-30 01:09:57 +00:00
|
|
|
/** Has no effect during normal operation. */
|
2004-07-23 20:21:44 +00:00
|
|
|
pageSlotRalloc(p, lsn, rid);
|
2004-06-30 01:09:57 +00:00
|
|
|
}
|
|
|
|
|
2004-06-24 21:10:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-06-30 01:09:57 +00:00
|
|
|
/** @todo Currently, we just leak store space on dealloc. */
|
2004-07-23 20:21:44 +00:00
|
|
|
static int deoperate(int xid, Page * p, lsn_t lsn, recordid rid, const void * dat) {
|
2004-07-14 20:49:18 +00:00
|
|
|
/* Page * loadedPage = loadPage(rid.page); */
|
2004-06-30 01:09:57 +00:00
|
|
|
/** Has no effect during normal operation, other than updating the LSN. */
|
2004-07-14 20:49:18 +00:00
|
|
|
/* pageSlotRalloc(loadedPage, lsn, rid); */
|
2004-07-23 20:21:44 +00:00
|
|
|
pageSlotRalloc(p, lsn, rid);
|
2004-06-24 21:10:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Operation getAlloc() {
|
|
|
|
Operation o = {
|
|
|
|
OPERATION_ALLOC, /* ID */
|
|
|
|
0,
|
|
|
|
OPERATION_DEALLOC,
|
|
|
|
&operate
|
|
|
|
};
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2004-06-28 21:10:10 +00:00
|
|
|
|
2004-07-06 01:22:18 +00:00
|
|
|
recordid Talloc(int xid, long size) {
|
2004-06-24 21:10:31 +00:00
|
|
|
recordid rid;
|
|
|
|
|
2004-06-30 01:09:57 +00:00
|
|
|
if(size >= BLOB_THRESHOLD_SIZE) {
|
|
|
|
rid = preAllocBlob(xid, size);
|
|
|
|
} else {
|
|
|
|
|
2004-07-04 00:46:49 +00:00
|
|
|
rid = ralloc(xid, size);
|
2004-06-30 01:09:57 +00:00
|
|
|
|
|
|
|
}
|
2004-06-24 21:10:31 +00:00
|
|
|
|
|
|
|
Tupdate(xid,rid, NULL, OPERATION_ALLOC);
|
|
|
|
|
|
|
|
return rid;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Operation getDealloc() {
|
|
|
|
Operation o = {
|
|
|
|
OPERATION_DEALLOC,
|
|
|
|
0,
|
|
|
|
OPERATION_ALLOC,
|
|
|
|
&deoperate
|
|
|
|
};
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Tdealloc(int xid, recordid rid) {
|
|
|
|
Tupdate(xid, rid, NULL, OPERATION_DEALLOC);
|
|
|
|
}
|