gdk_tm.c

来自「这个是内存数据库中的一个管理工具」· C语言 代码 · 共 165 行

C
165
字号
#line 36 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_tm.mx"#include "monetdb_config.h"#include "gdk.h"#include "gdk_tm.h"#line 60 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_tm.mx"/* in the commit prelude, the delta status in the memory image of all bats is commited */static int prelude(int cnt, bat* subcommit) {	int i = 0;	while(++i < cnt) {		bat bid = subcommit?subcommit[i]:i;		if (BBP_status(bid) & BBPPERSISTENT) {			BAT *b = BBP_cache(bid);			if (b == NULL && (BBP_status(bid) & BBPSWAPPED)) {				b = BBPquickdesc(bid, TRUE);				if (b == NULL) return -1;			}			if (b) {				BATcommit(b);			}		}	}	return 0;}/* in the commit epilogue, the BBP-status of the bats is changed to reflect their presence in the succeeded checkpoint.  * Also bats from the previous checkpoint that were deleted now are physically destroyed. */static int epilogue(int cnt, bat* subcommit) {	int i = 0;	while(++i < cnt) {		bat bid = subcommit?subcommit[i]:i;		if (BBP_status(bid) & BBPPERSISTENT) {			BBP_status_on(bid, BBPEXISTING, subcommit?"TMsubcommit":"TMcommit");		} else if ((BBP_status(bid) & (BBPDELETED | BBPTMP)) && BBP_refs(bid) <= 0 && BBP_lrefs(bid) <= 0) {			BAT *b = BBPquickdesc(bid, TRUE);			/* the unloaded ones are deleted without loading delete disk images */			BATdelete(b);				if (BBP_cache(bid)) {				/* those that quickdesc decides to load => free memory */				BATfree(b);			}			BBPclear(bid);	/* clear with locking */		}		BBP_status_off(bid, BBPDELETED | BBPSWAPPED | BBPNEW, subcommit?"TMsubcommit":"TMcommit");	}	return 0;}#line 109 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_tm.mx"intTMcommit(void) {	int ret = -1;	/* commit with the BBP globally locked */	BBPlock("TMcommit");	if (prelude(BBPsize, NULL) == 0 && BBPsync(BBPsize, NULL) == 0) {		ret = epilogue(BBPsize, NULL);	}	BBPunlock("TMcommit");	return ret;}#line 143 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_tm.mx"intTMsubcommit(BAT* b) {	int xx, ret = -1, cnt = 1; /* BBP artifact: slot 0 in the array will be ignored */	bat *subcommit = (bat*) alloca((BATcount(b)+1)*sizeof(bat));	BUN p, q;	/* collect the list and save the new bats outside any locking */	BATloopFast(b, p, q, xx) {		bat bid = BBPindex((str) BUNtail(b,p));		if (bid < 0) bid = -bid;		if (bid) subcommit[cnt++] = bid;	}	/* sort the list on BAT id */ 	GDKqsort(subcommit+1, NULL, cnt-1, sizeof(bat), TYPE_bat, 0);	if (prelude(cnt, subcommit) == 0) { /* save the new bats outside the lock */		/* lock just prevents BBPtrims, and other global (sub-)commits */		gdk_set_lock(GDKtrimLock, "TMsubcommit"); 		if (BBPsync(cnt, subcommit) == 0) { /* write BBP.dir (++) */			ret = epilogue(cnt, subcommit);		}		gdk_unset_lock(GDKtrimLock, "TMsubcommit");	}	return ret;}#line 176 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_tm.mx"intTMabort(void){	int i;	BBPlock("TMabort");	for (i = 1; i < BBPsize; i++) {		if (BBP_status(i) & BBPNEW) {			BAT *b = BBPquickdesc(i, FALSE);			if (b) {				if (b->batPersistence == PERSISTENT)					BBPdecref(i, TRUE);				b->batPersistence = TRANSIENT;				b->batDirtydesc = 1;			}		}	}	for (i = 1; i < BBPsize; i++) {		if (BBP_status(i) & (BBPPERSISTENT | BBPDELETED | BBPSWAPPED)) {			BAT *b = BBPquickdesc(i, TRUE);			if (b == NULL)				continue;			BBPfix(i);			if (BATdirty(b) || DELTAdirty(b)) {				/* BUN move-backes need a real BAT! */				/* Stefan: 				 * Actually, in case DELTAdirty(b), i.e., a				 * BAT with differences that is				 * saved/swapped-out but not yet committed,				 * we (AFAIK) don't have to load the BAT and				 * apply the undo, but rather could simply				 * discard the delta and revive the backup;				 * however, I don't know how to do this				 * (yet), hence we stick with this solution				 * for the time being --- it should be				 * correct though it might not be the most				 * efficient way...				 */				b = BBPdescriptor(i);				BATundo(b);			}			if (BBP_status(i) & BBPDELETED) {				BBP_status_on(i, BBPEXISTING, "TMabort");				if (b->batPersistence != PERSISTENT)					BBPincref(i, TRUE);				b->batPersistence = PERSISTENT;				b->batDirtydesc = 1;			}			BBPunfix(i);		}		BBP_status_off(i, BBPDELETED | BBPSWAPPED | BBPNEW, "TMabort");	}	BBPunlock("TMabort");	return 0;}#line 235 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_tm.mx"

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?