2006-06-21 00:45:18 +00:00
|
|
|
#include <string.h>
|
2007-06-11 21:36:57 +00:00
|
|
|
#include <stasis/transactional.h>
|
2006-06-21 00:45:18 +00:00
|
|
|
#include "page/raw.h"
|
|
|
|
#include <assert.h>
|
2004-07-27 21:30:54 +00:00
|
|
|
|
2004-07-26 20:37:04 +00:00
|
|
|
|
2006-06-21 00:45:18 +00:00
|
|
|
void allocBlob(int xid, recordid rid) {
|
|
|
|
assert(rid.size>0);
|
|
|
|
int pageCount = (rid.size / USABLE_SIZE_OF_PAGE) + ((rid.size % USABLE_SIZE_OF_PAGE) ? 1 : 0);
|
|
|
|
long startPage = TpageAllocMany(xid, pageCount);
|
|
|
|
blob_record_t rec;
|
|
|
|
rec.offset = startPage;
|
|
|
|
rec.size = rid.size;
|
|
|
|
recordid rid2 = rid;
|
|
|
|
rid2.size = BLOB_SLOT;
|
|
|
|
Tset(xid, rid2, &rec);
|
|
|
|
// printf("Page start = %d, count = %d, rid.size=%d\n", rec.offset, pageCount, rid.size);
|
|
|
|
// printf("rid = {%d %d %d}\n", rid.page, rid.slot, rid.size);
|
2004-06-28 21:10:10 +00:00
|
|
|
}
|
|
|
|
|
2006-06-21 00:45:18 +00:00
|
|
|
void readBlob(int xid, Page * p2, recordid rid, byte * buf) {
|
|
|
|
int chunk;
|
|
|
|
recordid rawRid = rid;
|
|
|
|
rawRid.size = BLOB_SLOT;
|
|
|
|
byte * pbuf = alloca(PAGE_SIZE);
|
2004-06-28 21:10:10 +00:00
|
|
|
blob_record_t rec;
|
2007-10-02 00:18:33 +00:00
|
|
|
stasis_record_read(xid, p2, rawRid, (byte*)&rec);
|
2007-07-18 20:09:14 +00:00
|
|
|
|
|
|
|
for(chunk = 0; (chunk+1) * USABLE_SIZE_OF_PAGE < rid.size; chunk++) {
|
2006-06-21 00:45:18 +00:00
|
|
|
TpageGet(xid, rec.offset+chunk, pbuf);
|
|
|
|
memcpy(buf + (chunk * USABLE_SIZE_OF_PAGE), pbuf, USABLE_SIZE_OF_PAGE);
|
2004-06-26 02:05:24 +00:00
|
|
|
}
|
2004-06-28 21:10:10 +00:00
|
|
|
|
2006-06-21 00:45:18 +00:00
|
|
|
TpageGet(xid, rec.offset+chunk, pbuf);
|
|
|
|
memcpy(buf + (chunk * USABLE_SIZE_OF_PAGE), pbuf, rid.size % USABLE_SIZE_OF_PAGE);
|
|
|
|
// printf("Chunk = %d\n", chunk);
|
2004-06-28 21:10:10 +00:00
|
|
|
|
2004-07-27 21:30:54 +00:00
|
|
|
}
|
2004-08-21 00:03:30 +00:00
|
|
|
|
2006-06-21 00:45:18 +00:00
|
|
|
void writeBlob(int xid, Page * p2, lsn_t lsn, recordid rid, const byte * buf) {
|
|
|
|
int chunk;
|
|
|
|
recordid rawRid = rid;
|
|
|
|
rawRid.size = BLOB_SLOT;
|
|
|
|
byte * pbuf = alloca(PAGE_SIZE);
|
2004-07-27 21:30:54 +00:00
|
|
|
blob_record_t rec;
|
2007-10-02 00:18:33 +00:00
|
|
|
stasis_record_read(xid, p2, rawRid, (byte*)&rec);
|
2007-07-18 20:09:14 +00:00
|
|
|
Page tmp;
|
|
|
|
tmp.memAddr=pbuf;
|
2004-07-27 21:30:54 +00:00
|
|
|
|
2007-07-18 20:09:14 +00:00
|
|
|
assert(rec.offset);
|
|
|
|
for(chunk = 0; (chunk+1) * USABLE_SIZE_OF_PAGE < rid.size; chunk++) {
|
2006-06-21 00:45:18 +00:00
|
|
|
TpageGet(xid, rec.offset+chunk, pbuf);
|
2007-07-18 20:09:14 +00:00
|
|
|
|
2007-10-02 00:18:33 +00:00
|
|
|
*stasis_page_type_ptr(&tmp) = BLOB_PAGE;
|
2006-06-21 00:45:18 +00:00
|
|
|
memcpy(pbuf, buf + (chunk * USABLE_SIZE_OF_PAGE), USABLE_SIZE_OF_PAGE);
|
|
|
|
TpageSet(xid, rec.offset+chunk, pbuf);
|
|
|
|
}
|
|
|
|
TpageGet(xid, rec.offset+chunk, pbuf);
|
|
|
|
memcpy(pbuf, buf + (chunk * USABLE_SIZE_OF_PAGE), rid.size % USABLE_SIZE_OF_PAGE);
|
|
|
|
TpageSet(xid, rec.offset+chunk, pbuf);
|
|
|
|
// printf("Write Chunk = %d (%d)\n", chunk, rec.offset+chunk);
|
2007-07-18 20:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int notSupported(int xid, Page * p) { return 0; }
|
|
|
|
|
2007-08-20 21:58:20 +00:00
|
|
|
static void blobLoaded(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
|
|
|
}
|
2007-08-20 21:58:20 +00:00
|
|
|
static void blobFlushed(Page *p) {
|
2007-10-02 00:18:33 +00:00
|
|
|
*stasis_page_lsn_ptr(p) = p->LSN;
|
2007-07-18 20:09:14 +00:00
|
|
|
}
|
2007-08-20 21:58:20 +00:00
|
|
|
static void blobCleanup(Page *p) { }
|
2004-06-26 02:05:24 +00:00
|
|
|
|
2007-07-18 20:09:14 +00:00
|
|
|
static page_impl pi = {
|
|
|
|
BLOB_PAGE,
|
|
|
|
0, //read,
|
|
|
|
0, //write,
|
|
|
|
0, //readDone
|
|
|
|
0, //writeDone
|
|
|
|
0, //getType,
|
|
|
|
0, //setType,
|
|
|
|
0, //getLength,
|
|
|
|
0, //recordFirst,
|
|
|
|
0, //recordNext,
|
|
|
|
notSupported, // is block supported
|
|
|
|
0, //pageGenericBlockFirst,
|
|
|
|
0, //pageGenericBlockNext,
|
|
|
|
0, //pageGenericBlockDone,
|
|
|
|
0, //freespace,
|
|
|
|
0, //compact,
|
|
|
|
0, //preRalloc,
|
|
|
|
0, //postRalloc,
|
|
|
|
0, //Free,
|
|
|
|
0, //XXX page_impl_dereference_identity,
|
|
|
|
blobLoaded,
|
|
|
|
blobFlushed,
|
2007-08-20 21:58:20 +00:00
|
|
|
blobCleanup
|
2007-07-18 20:09:14 +00:00
|
|
|
};
|
|
|
|
page_impl blobImpl() {
|
|
|
|
return pi;
|
2004-06-26 02:05:24 +00:00
|
|
|
}
|