


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Assignment 1 1
/* Start new transaction */ int start() Returns: -1, if there is an active transaction tId < -1 (a new Transaction Identifier) otherwise
/* If possible, read block at diskBlockAddr on behalf of transaction tId from disk into main memory and save a pointer to it in memBlock */ int read(int diskBlockAddr, int tId, int *memBlock) Returns: 0 if successful, -1 otherwise
/* Tell BlockDB that transaction tId has updated a block at diskBlockAddr */ int write(int diskBlockAddr, int tId) Returns: 0 if there is no cached entry for diskBlockAddr 1 otherwise
/* Try to commit transaction tId */ int commit(int tId) Returns: 0 if successful, -1 otherwise
/* Abort transaction tId */ int abort(int tId) Returns: 0
Assignment 1 2
/* Read the value of block at diskBlockAddr from disk and return it in main memory at address memAddr */ int diskRead(int diskBlockAddr, int memAddr)
/* Store the content of the main memory beginning at address memAddr into block diskBlockAddr on disk */ int diskWrite(int diskblockAddr, int memAddr)
Returns: For each operation, read or write, the disk drive either performs the intended operation and returns 0 or it has no effect and returns -1.
lastTrans = 1;
int start() { if (lastTrans < 0) { return -1 } else { lastTrans = -(++lastTrans); return lastTrans } }
int read(int diskBlockAddr, int tId, int memBlock) { / find the cache element e containing the block whose disk address is diskBlockAddr / if (there is such a cache element e) { / the disk block at diskBlockAddr is in cache / Cache(e).tId = tId; memBlock = &Cache(e).newBlock; / &Cache(e).newBlock is the address of Cache(e).newBlock / return 0 } else { / pick a cache entry e, where Cache(e).tId = 0. If there is no such entry, then return -1 */ status = diskRead(diskBlockAddr, &Cache(e).oldBlock); if (status != 0) { return -1 }; Cache(e).newBlock = Cache(e).oldBlock;
Assignment 1 4
for (all cache entries e) { Cache(e).tId = 0 } lastTrans = -lastTrans;
return 0 }