⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdk_bat.c

📁 这个是内存数据库中的一个管理工具
💻 C
📖 第 1 页 / 共 5 页
字号:
size_tBATmemsize(BAT *b, int dirty){	BATcheck(b, "BATmemsize");	if (b->batDirty || (b->batPersistence != TRANSIENT && !b->batCopiedtodisk))		dirty = 0;	return ((dirty == 0 || b->batDirtydesc) ? 			sizeof(BATstore) : 0) + 		((dirty == 0 || b->batDirtybuns) ? 			HEAPmemsize(b->batBuns) : 0) + 		(((dirty == 0 || b->batDirtybuns) && b->hhash) ? 			HEAPmemsize(b->hhash->heap) : 0) + 		(((dirty == 0 || b->batDirtybuns) && b->thash) ? 			HEAPmemsize(b->thash->heap) : 0) + 		(((dirty == 0 || b->hheapdirty) && b->hheap) ? 			HEAPmemsize(b->hheap) : 0) + 		(((dirty == 0 || b->theapdirty) && b->theap) ? 			HEAPmemsize(b->theap) : 0);}#line 1907 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"BAT *BATkey(BAT *b, int flag){	bat parent;	BATcheck(b, "BATkey");	parent = VIEWparentcol(b);	if (b->htype == TYPE_void) {		if (b->hseqbase == oid_nil && flag == BOUND2BTRUE) {			GDKerror("BATkey: nil-column cannot be kept unique.\n");		}		if (b->hseqbase != oid_nil && flag == FALSE) {			GDKerror("BATkey: dense column must be unique.\n");		}		if (b->hseqbase == oid_nil || flag == FALSE) {			return b;		}	}	if (flag)		flag |= (1 | b->hkey);	if (b->hkey != flag)		b->batDirtydesc = TRUE;	BATmirror(b)->tkey = b->hkey = flag;	if (!flag)		BATmirror(b)->tdense = b->hdense = 0;	if (flag && parent && ALIGNsynced(b, BBP_cache(parent)))		BATkey(BBP_cache(parent), TRUE);	return b;}BAT *BATset(BAT *b, int flag){	BATcheck(b, "BATset");	if (b->htype == TYPE_void) {		if (b->hseqbase == oid_nil && flag == BOUND2BTRUE)			BATkey(BATmirror(b), flag);	} else if (b->ttype == TYPE_void) {		if (b->tseqbase == oid_nil && flag == BOUND2BTRUE)			BATkey(b, flag);	} else {		if (flag)			flag = TRUE;		if (b->batSet != flag)			b->batDirtydesc = TRUE;		b->batSet = flag;	}	return b;}BAT *BATseqbase(BAT *b, oid o){	BATcheck(b, "BATseqbase");	if (ATOMtype(b->htype) == TYPE_oid) {		BAT *m = BATmirror(b);		if (b->hseqbase != o) {			b->batDirtydesc = TRUE;			/* zap alignment if column is changed by new seqbase */			if (b->htype == TYPE_void)				b->halign = m->talign = 0;		}		m->tseqbase = b->hseqbase = o;		/* adapt keyness */		if (BAThvoid(b)) {			if (o == oid_nil) {				if (b->hkey)					m->tkey = b->hkey = FALSE;			} else {				if (!b->hkey) {					m->tkey = b->hkey = TRUE;					b->H->nokey[0] = b->H->nokey[1] = 0; 				}			}		}	}	return b;}#line 1990 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"#line 2000 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"intBATname(BAT *b, str nme){	BATcheck(b, "BATname");	return BBPrename(b->batCacheid, nme);}strBATrename(BAT *b, str nme){	int ret = BATname(b, nme);	if (ret == 1) {		GDKerror("BATrename: identifier expected: %s\n", nme);	} else if (ret == BBPRENAME_ALREADY) {		GDKerror("BATrename: name is in use: '%s'.\n", nme);	} else if (ret == BBPRENAME_ILLEGAL) {		GDKerror("BATrename: illegal temporary name: '%s'\n", nme);	} else if (ret == BBPRENAME_LONG) {		GDKerror("BATrename: name too long: '%s'\n", nme);	} else if (b == NULL) {		GDKerror("BATrename: BAT argument missing\n");	}	return BBPname(b->batCacheid);}BAT *BATroles(BAT *b, str hnme, str tnme){	BATcheck(b, "BATroles");	if (b->hident && !default_ident(b->hident))		GDKfree(b->hident);	if (hnme)		b->hident = GDKstrdup( hnme );	else		b->hident = BATstring_h;	if (b->tident && !default_ident(b->tident))		GDKfree(b->tident);	if (tnme)		b->tident = GDKstrdup( tnme );	else		b->tident = BATstring_t;	return b;}BAT *BATcol_name(BAT *b, str tnme){	BATcheck(b, "BATcol_name");	if (b->tident && !default_ident(b->tident))		GDKfree(b->tident);	if (tnme)		b->tident = GDKstrdup( tnme );	else		b->tident = BATstring_t;	return b;}#line 2060 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"#line 2087 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"#define ATOMappendpriv(t,h) ((BATatoms[t].atomHeapCheck != HEAP_check || !HEAP_mmappable(h)) && \			     (ATOMstorage(t) != TYPE_str || GDK_ELIMDOUBLES(h)))#line 2091 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"#line 2107 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"intBATmmap(BAT *b, int bns, int hhp, int thp ){	BATcheck(b, "BATmmap");	IODEBUG THRprintf(GDKout, "#BATmmap(%s,%d,%d,%d)\n", BATgetId(b), bns, hhp, thp );	/* Reverse back if required, as this determines which heap is saved in the 	 * "hheap" file and which in the "theap" file.	 */	if (b->batCacheid < 0) {		int swap = hhp;		hhp = thp;		thp = swap;		b = BATmirror(b);	}	b->batMapdirty = TRUE;	b->batMapbuns = bns;	b->batMaphheap = hhp;	b->batMaptheap = thp;	if (b->batBuns) b->batBuns->newstorage = bns;	if (b->hheap) b->hheap->newstorage = hhp;	if (b->theap) b->theap->newstorage = thp;	b->batDirtydesc = 1;	return 0;}#line 2145 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"intBATmadvise(BAT *b, int bns, int hhp, int thp ){	BATcheck(b, "BATmadvise");	#line 2135 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	if (bns >= 0 && (b->batBuns) && (b->batBuns)->base && ((b->batBuns)->storage&STORE_MMAP) &&	    MT_madvise((b->batBuns)->base, (b->batBuns)->free, bns)) {		GDKsyserror("madvise on b->batBuns bns failed.\n");		return -1;	}#line 2149 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	#line 2135 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	if (hhp >= 0 && (b->hheap) && (b->hheap)->base && ((b->hheap)->storage&STORE_MMAP) &&	    MT_madvise((b->hheap)->base, (b->hheap)->free, hhp)) {		GDKsyserror("madvise on b->hheap hhp failed.\n");		return -1;	}#line 2150 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	#line 2135 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	if (thp >= 0 && (b->theap) && (b->theap)->base && ((b->theap)->storage&STORE_MMAP) &&	    MT_madvise((b->theap)->base, (b->theap)->free, thp)) {		GDKsyserror("madvise on b->theap thp failed.\n");		return -1;	}#line 2151 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	return 0;}intBATmmap_pin(BAT *b){	BATcheck(b, "BATmmap_pin");	#line 2141 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	if ( (b->batBuns) && (b->batBuns)->base && ((b->batBuns)->storage&STORE_MMAP)) {		MT_mmap_pin((b->batBuns)->base, (b->batBuns)->maxsize);	}#line 2159 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	#line 2141 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	if ( (b->hheap) && (b->hheap)->base && ((b->hheap)->storage&STORE_MMAP)) {		MT_mmap_pin((b->hheap)->base, (b->hheap)->maxsize);	}#line 2160 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	#line 2141 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	if ( (b->theap) && (b->theap)->base && ((b->theap)->storage&STORE_MMAP)) {		MT_mmap_pin((b->theap)->base, (b->theap)->maxsize);	}#line 2161 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	return 0;}intBATmmap_unpin(BAT *b){	BATcheck(b, "BATmmap_unpin");	#line 2141 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	if ( (b->batBuns) && (b->batBuns)->base && ((b->batBuns)->storage&STORE_MMAP)) {		MT_mmap_unpin((b->batBuns)->base, (b->batBuns)->maxsize);	}#line 2169 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	#line 2141 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	if ( (b->hheap) && (b->hheap)->base && ((b->hheap)->storage&STORE_MMAP)) {		MT_mmap_unpin((b->hheap)->base, (b->hheap)->maxsize);	}#line 2170 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	#line 2141 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	if ( (b->theap) && (b->theap)->base && ((b->theap)->storage&STORE_MMAP)) {		MT_mmap_unpin((b->theap)->base, (b->theap)->maxsize);	}#line 2171 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	return 0;}#line 2176 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"#line 2183 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"static intHEAPcheckmode(Heap *h, int persistent, int unloadable, int writeable){	/* user may have requested illegal or system-wise unwanted mmap modes. correct this */	if (h->size > 0 && h->storage == STORE_MMAP && persistent && writeable) {		/* in a commit, we are sometimes forced to start treating MMAP heaps as PRIV */		if (!unloadable)			h->storage = STORE_PRIV;		return 1;	}	return 0;}intBATcheckmodes(BAT *b, int persistent, int unloadable){	int dirty = 0;	BATcheck(b, "BATcheckmodes");	if (HEAPcheckmode(b->batBuns, persistent, unloadable, b->batRestricted == BAT_WRITE)) {		b->batMapbuns = STORE_PRIV;		dirty = b->batMapdirty = TRUE;	}	if (b->hheap && (HEAPcheckmode(b->hheap, persistent, unloadable, b->batRestricted == BAT_WRITE || (b->batRestricted == BAT_APPEND && ATOMappendpriv(b->htype, b->hheap))))) {		b->batMaphheap = STORE_PRIV;		dirty = TRUE;	}	if (b->theap && (HEAPcheckmode(b->theap, persistent, unloadable, b->batRestricted == BAT_WRITE || (b->batRestricted == BAT_APPEND && ATOMappendpriv(b->ttype, b->theap))))) {		b->batMaptheap = STORE_PRIV;		dirty = TRUE;	}	b->batMapdirty |= dirty;	b->batDirtydesc |= dirty;	return dirty;}#line 2220 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"#line 2307 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"/* transition heap from readonly to writable (or appendable) */static intHEAPsetpriv(Heap *hp, int committed, int *remap, int *reload){	str p;	assert(hp);	if (hp->base == NULL || hp->storage == STORE_MEM || hp->filename == NULL || !committed) {		return hp->storage;	}	/* STORE_PRIV would indicate an illegal heap state */	assert(hp->storage != STORE_PRIV);	p = strstr(hp->filename, ".priv");	if (p) { 		/* state(4), goto state (1) */		*remap = TRUE;		return hp->storage = STORE_PRIV;	}	*remap = TRUE;	/* state(3), goto state (1) */	*reload = TRUE;	return STORE_PRIV;}/* transition heap from writable (or appendable) to readonly */static intHEAPsetmmap(Heap *hp, int committed, int *remap){	assert(hp);	if (hp->base == NULL || hp->storage == STORE_MEM || hp->filename == NULL || !committed ) {		return hp->storage;	}	*remap = TRUE;	if (hp->storage == STORE_MMAP) {		/* state(2), goto state (3) */		long_str src, dst;		str p = strstr(hp->filename, ".priv");		int ret;		assert(p);	/* absence of .priv would indicate an illegal heap state */		GDKfilepath(src, BATDIR, hp->filename, NULL);		*p = 0;		/* cut off .priv */		GDKfilepath(dst, BATDIR, hp->filename, NULL);		/* rename X.priv->X is not crucial for this to work (X.priv is not in the way) */		ret = rename(src, dst);		IODEBUG THRprintf(GDKout, "#BATsetaccess(HEAPsetmmap) rename(%s,%s) = %d\n", src, dst, ret);	} else {		/* state(1), goto state (4) */		hp->storage = STORE_MMAP;	/* direct change! */	}	return STORE_MMAP;}#line 2378 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"static intbatunshare(BAT* b, str fcn) {	#line 2366 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	if (b->batBuns->copied) {		Heap hp;		memset(&hp, 0, sizeof(Heap));		if (HEAPcopy(&hp, b->batBuns) < 0) {			GDKerror("%s: remapped batBuns of %s could not be copied.\n", fcn, BATgetId(b));			return -1;		}		HEAPfree(b->batBuns);		*(b->batBuns) = hp;		b->batBuns->copied = 0;	}#line 2380 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	if (b->hheap) #line 2366 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	if (b->hheap->copied) {		Heap hp;		memset(&hp, 0, sizeof(Heap));		if (HEAPcopy(&hp, b->hheap) < 0) {			GDKerror("%s: remapped hheap of %s could not be copied.\n", fcn, BATgetId(b));			return -1;		}		HEAPfree(b->hheap);		*(b->hheap) = hp;		b->hheap->copied = 0;	}#line 2381 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	if (b->theap) #line 2366 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	if (b->theap->copied) {		Heap hp;		memset(&hp, 0, sizeof(Heap));		if (HEAPcopy(&hp, b->theap) < 0) {			GDKerror("%s: remapped theap of %s could not be copied.\n", fcn, BATgetId(b));			return -1;		}		HEAPfree(b->theap);		*(b->theap) = hp;		b->theap->copied = 0;	}#line 2382 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	b->batLview = 0;	BBPunshare(b->batParentid);	return 0;}BAT *BATsetaccess(BAT *b, int mode){	BATcheck(b, "BATsetaccess");	if (VIEWparent(b) && mode != BAT_READ) {		if (VIEWreset(b) == NULL)			return NULL;	}	if (b->batRestricted != mode) {		int m1 = 0, bak1 = b->batBuns->storage;		int m2 = 0, bak2 = b->hheap ? b->hheap->storage : -1;		int m3 = 0, bak3 = b->theap ? b->theap->storage : -1;		int committed = BBP_status

⌨️ 快捷键说明

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