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

📄 bbp.mx

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 MX
📖 第 1 页 / 共 2 页
字号:
@' The contents of this file are subject to the MonetDB Public License@' Version 1.1 (the "License"); you may not use this file except in@' compliance with the License. You may obtain a copy of the License at@' http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html@'@' Software distributed under the License is distributed on an "AS IS"@' basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the@' License for the specific language governing rights and limitations@' under the License.@'@' The Original Code is the MonetDB Database System.@'@' The Initial Developer of the Original Code is CWI.@' Portions created by CWI are Copyright (C) 1997-2007 CWI.@' All Rights Reserved.@f bbp@v 2.0@a M.L.Kersten, P. Boncz@+ BAT Buffer PoolThe BBP module implements a box interface over the BAT buffer pool.It is primarilly meant to ease inspection of the BAT collection managedby the server.The two predominant approaches to use bbp is to access the BBPwith either @emph{bind} or @emph{take}. The former merely maps the BAT nameto the object in the bat buffer pool.  A more controlled scheme is to @emph{ deposit}, @emph{take}, @emph{release}and @emph{ discard} elements.Any BAT B created can be brought under this scheme with the name N.The association N->B is only maintained in the box administrationand not reflected in the BAT descriptor.In particular, taking a  BATobject out of the box leads to a private copy to isolate the user from concurrent updates on the underlying store.Upon releasing it, the updates are merged with the master copy [todo].The remainder of this module contains operations that relyon the MAL runtime setting, but logically belong to the kernel/batmodule.@malmodule bbp;command open():void		address CMDbbpopencomment "Locate the bbp box and open it.";command close():void		address CMDbbpclosecomment "Close the bbp box.";command destroy():void		address CMDbbpdestroycomment "Destroy the box";pattern take(name:str) :bat[:any_1,:any_2] address CMDbbptakecomment "Load a particular bat";pattern deposit(name:str,v:bat[:any_1,:any_2]) :void 			address CMDbbpdepositcomment "Enter a new bat into the bbp box.";pattern deposit(name:str,loc:str) :bat[:any_1,:any_2]address CMDbbpbindDefinitioncomment "Relate a logical name to a physical BAT in the buffer pool.";pattern commit():void 	address CMDbbpReleaseAllcomment "Commit updates for this client";pattern releaseAll():void 	address CMDbbpReleaseAllcomment "Commit updates for this client";pattern release(name:str,val:bat[:any_1,:any_2]) :void 			address CMDbbpreleasecomment "Commit updates and release this BAT.";pattern release(b:bat[:any_1,:any_2]):voidaddress CMDbbpreleaseBATcomment "Remove the BAT from further consideration";pattern destroy(b:bat[:any_1,:any_2]):voidaddress CMDbbpdestroyBAT1comment "BAT removal at session end";pattern destroy(b:bat[:any_1,:any_2],immediate:bit)address CMDbbpdestroyBATcomment "Schedule a BAT for removal at session end or immediately";pattern toString(name:str):str 	address CMDbbptoStrcomment "Get the string representation of an element in the box";pattern discard(name:str):void address CMDbbpdiscardcomment "Remove the BAT from the box";pattern iterator(nme:str):lng 	address CMDbbpiteratorcomment "Locates the next element in the box";pattern prelude():void address CMDbbppreludecomment "Initialize the bbp box";pattern bind(name:str):bat[:any_1,:any_2]address CMDbbpbindcomment "Locate the BAT using its logical name";command find(name:str):bat[:any_1,:any_2]address CMDbbpfind3comment "Locate the BAT using its logical name in the BAT buffer pool");command find(head:str,tail:str):bat[:any_1,:any_2]address CMDbbpfind2comment "Locate the BAT using the head and tail names in the BAT buffer pool");command find(idx:BAT):bat[:any_1,:any_2] address CMDbbpbindindexcomment "Locate the BAT using its BBP index in the BAT buffer pool";pattern getObjects():bat[:int,:str] address CMDbbpGetObjects	comment "View of the box content.";                                                                                @{@- Singleton Set managementSingleton sets are ideally not represented by BATs, but theynevertheless emerge as the result of an operation.They can be packed/unpacked easily.@- BAT declarationsA pattern block may be required to make the proper translation tothe BAT library. In particular when the type information is neededto steer the process. This means the code can not belong to thekernel module, because MAL context knowledge is forbidden there.The signatures are, however, moved into the proper place.@- Algebraic operatorsThere are also a few algebraic operators that have to be defined here/They rely on knowledge of the runtime environment@mal@+ BAT buffer poolThe following list of operations permits inspection of thebuffer pool@}@malcommand getHeadType() :bat[:int,:str]		address CMDbbpHeadTypecomment "Map a BAT into its head type";command getTailType() :bat[:int,:str]		address CMDbbpTailTypecomment "Map a BAT into its tail type";command getNames() :bat[:int,:str] 	address CMDbbpNamescomment "Map BAT into its bbp name";command getRNames() :bat[:int,:str] 	address CMDbbpRNamescomment "Map a BAT into its bbp physical name";command getName( b:bat[:any_1,:any_2]):straddress CMDbbpNamecomment "Map a BAT into its internal name";command getCount() :bat[:int,:lng] 	address CMDbbpCountcomment "Create a BAT with the cardinalities of all known BATs";command getRefCount() :bat[:int,:int] 	address CMDbbpRefCountcomment "Create a BAT with the (hard) reference counts";command getLRefCount() :bat[:int,:int] 	address CMDbbpLRefCountcomment "Create a BAT with the logical reference counts";command getLocation() :bat[:int,:str] 	address CMDbbpLocationcomment "Create a BAT with their disk locations";command getHeat() :bat[:int,:int] 	address CMDbbpHeatcomment "Create a BAT with the heat values";command getDirty() :bat[:int,:str] 	address CMDbbpDirtycomment "Create a BAT with the dirty/ diffs/clean status";command getStatus() :bat[:int,:str] 	address CMDbbpStatuscomment "Create a BAT with the disk/load status";command getKind():bat[:int,:str] address CMDbbpKindcomment "Create a BAT with the persistency status";command getRefCount(b:bat[:any_1,:any_2]) :intaddress CMDgetBATrefcntcomment "Utility for debugging MAL interpreter";command getLRefCount(b:bat[:any_1,:any_2]) :intaddress CMDgetBATlrefcntcomment "Utility for debugging MAL interpreter";@-@{@include prelude.mx@+ Implementation sectionIn most cases we pass a BAT identifier, which should be unifiedwith a BAT descriptor. Upon failure we can simply abort the function.@c#include "mal_config.h"#include "mal_box.h"#include "mal_client.h"#include "mal_interpreter.h"#include "bat5.h"#include "algebra.h"#ifdef WIN32#ifndef LIBBBP#define bbp_export extern __declspec(dllimport)#else#define bbp_export extern __declspec(dllexport)#endif#else#define bbp_export extern#endifbbp_export str CMDbbpprelude(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);bbp_export str CMDbbpopen(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);bbp_export str CMDbbpclose(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);bbp_export str CMDbbpdestroy(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);bbp_export str CMDbbpdeposit(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);bbp_export str CMDbbpbindDefinition(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);bbp_export str CMDbbpbind(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);bbp_export str CMDbbpfind2(int *ret, str *hnme, str *tnme);bbp_export str CMDbbpfind3(int *ret, str *nme);bbp_export str CMDbbpbindindex(int *ret, int *bid);bbp_export str CMDbbptake(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);bbp_export str CMDbbprelease(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);bbp_export str CMDbbpreleaseBAT(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);bbp_export str CMDbbpdestroyBAT(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);bbp_export str CMDbbpdestroyBAT1(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);bbp_export str CMDbbpReleaseAll(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);bbp_export str CMDbbpdiscard(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);bbp_export str CMDbbptoStr(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);bbp_export str CMDbbpiterator(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);bbp_export str CMDbbpGetObjects(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);bbp_export str CMDbbpNames(int *ret);bbp_export str CMDbbpName(str *ret, int *bid);bbp_export str CMDbbpRNames(int *ret);bbp_export str CMDbbpCount(int *ret);bbp_export str CMDbbpLocation(int *ret);bbp_export str CMDbbpHeat(int *ret);bbp_export str CMDbbpDirty(int *ret);bbp_export str CMDbbpStatus(int *ret);bbp_export str CMDbbpKind(int *ret);bbp_export str CMDbbpRefCount(int *ret);bbp_export str CMDbbpLRefCount(int *ret);bbp_export str CMDgetBATrefcnt(int *res, int *bid);bbp_export str CMDgetBATlrefcnt(int *res, int *bid);bbp_export str CMDbatunpack(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);bbp_export str CMDbatpack(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);@-Access to a box calls for resolving the first parameterto a named box. The bbp box is automatically opened.@c#define OpenBox(X) \	box= findBox("bbp");\	if(box == 0 )\		box= openBox("bbp");\	if( box ==0) \		throw(MAL, "bbp." X,"box is not open");strCMDbbpprelude(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	(void) mb;	(void) stk;	(void) pci;		/* fool compiler */	if (openBox("bbp"))		return MAL_SUCCEED;	throw(MAL, "bbp.prelude", "failed to open box");}@- Operator implementation@cstrCMDbbpopen(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	(void) mb;	(void) stk;	(void) pci;		/* fool compiler */	if (openBox("bbp") != 0)		return MAL_SUCCEED;	throw(MAL, "bbp.open", "failed to open box");}strCMDbbpclose(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	(void) mb;	(void) stk;	(void) pci;		/* fool compiler */	if (closeBox("bbp", TRUE) == 0)		return MAL_SUCCEED;	throw(MAL, "bbp.close", "failed to close 'bbp' box");}strCMDbbpdestroy(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	Box box;	(void) mb;	(void) stk;	(void) pci;		/* fool compiler */	OpenBox("destroy");	if (MCgetClient() != mal_clients)		throw(MAL, "bbp.destroy", "not allowed to destroy 'bbp' box");	destroyBox("bbp");	return MAL_SUCCEED;}@-Beware that once you deposit a BAT into a box, it shouldincrement the reference count to assure it is notgarbage collected. Moreover, it should be done so only once.@cstrCMDbbpdeposit(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	str name;	ValPtr v;	Box box;	int flg;	(void) mb;		/* fool compiler */	OpenBox("deposit");	name = (str) getArgValue(stk, pci, 1);	if (isIdentifier(name) < 0 )		throw(MAL, "bbp.deposit", "identifier expected");	v = &stk->stk[getArg(pci, 2)];	flg = findVariable(box->sym, name) >= 0;	if (depositBox(box, name, v))		throw(MAL, "bbp.deposit", "failed to deposit into box");	if (!flg)		BBPincref(v->val.bval, TRUE);	return MAL_SUCCEED;}strCMDbbpbindDefinition(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	str name, loc;	Box box;	(void) mb;		/* fool compiler */	OpenBox("bind");	name = (str) getArgValue(stk, pci, 1);	loc = (str) getArgValue(stk, pci, 2);	if (isIdentifier(name) < 0)		throw(MAL, "bbp.bind", "identifier expected");	if (bindBAT(box, name, loc))		throw(MAL, "bbp.bind", "failed to bind name ");	return MAL_SUCCEED;}strCMDbbpbind(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	str name;	Box box;	ValPtr lhs, rhs;	int i = -1;	BAT *b;	(void) mb;		/* fool compiler */	lhs = &stk->stk[getArg(pci, 0)];	name = (str) getArgValue(stk, pci, 1);	if (isIdentifier(name) < 0)		throw(MAL, "bbp.bind", "identifier expected");	box = findBox("bbp");	if (box && (i = findVariable(box->sym, name)) >= 0) {		rhs = &box->val->stk[i];		VALcopy(lhs, rhs);		if (lhs->vtype == TYPE_bat) {			BAT *b;			b = (BAT *) BBPgetdesc(lhs->val.bval);			if (b == NULL)				throw(MAL, "bbp.bind", "can not access descriptor");			BBPincref(b->batCacheid, TRUE);		}		return MAL_SUCCEED;	}	i = BBPindex(name);	if (i == 0)		throw(MAL, "bbp.bind", "failed to locate object in box");	/* make sure you load the descriptors and heaps */	b = (BAT *) BATdescriptor(i);	if (b == 0)		/* Simple ignore the binding if you can;t find the bat */		throw(MAL, "bbp.bind", "failed to find object in box");	/* make sure we are not dealing with an about to be deleted bat */	if( BBP_refs(b->batCacheid) == 1 &&		BBP_lrefs(b->batCacheid) == 0){		BBPunfix(i);		throw(MAL, "bbp.bind", "failed to find object in box");	}	BBPincref(b->batCacheid, TRUE);	BBPunfix(i);	lhs->vtype = TYPE_bat;	lhs->val.bval = i;	return MAL_SUCCEED;}strCMDbbpfind3(int *ret, str *nme){	int i;	/* find a specific BAT in the buffer pool */	BBPlock("CMDbbpfind3");	for (i = 1; i < BBPsize; i++)	if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) {		if( strcmp(BBP_logical(i),*nme)==0 ){			BBPkeepref(i);			*ret = i;			BBPunlock("CMDbbpfind3");			return MAL_SUCCEED;		}	}	BBPunlock("CMDbbpfind3");	throw(MAL, "bbp.find","BAT not found");}strCMDbbpfind2(int *ret, str *hnme, str *tnme){	int i;	/* find a specific BAT in the buffer pool */	BBPlock("CMDbbpfind2");	for (i = 1; i < BBPsize; i++)	if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) {		BAT *b = (BAT *) BATdescriptor(i);		if( b == 0 ) 			continue;		if( strcmp(b->hident,*hnme)==0 &&			strcmp(b->tident,*tnme)==0 ){			BBPkeepref(i);			*ret = i;			BBPunlock("CMDbbpfind2");			return MAL_SUCCEED;		}		BBPreleaseref(i);	}	BBPunlock("CMDbbpfind2");	throw(MAL, "bbp.find","BAT not found");}strCMDbbpbindindex(int *ret, int *bid){	BAT *b;	if ( *bid  == bat_nil)		throw(MAL, "bbp.bind", "can not access descriptor");	b = (BAT *) BATdescriptor(*bid);	if (b == 0)		throw(MAL, "bbp.bind", "can not access descriptor");	*ret = b->batCacheid;	BBPkeepref(*ret);	return MAL_SUCCEED;}@-Moving BATs in/out of the box also involveschecking the type already known for possible misfits.Therefore, we need access to the runtime context.If the bat is not known in the box, we go to the bbp pooland make an attempt to load it directly.@cstrCMDbbptake(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	str name;	Box box;	ValPtr v;	(void) mb;		/* fool compiler */	OpenBox("take");	name = (str) getArgValue(stk, pci, 1);	if (isIdentifier(name)< 0)		throw(MAL, "bbp.take", "identifier expected");	if (strstr(name, "M5system_auth") == name)		throw(MAL, "bbp.take", "access denied");	v = &stk->stk[getArg(pci, 0)];	if (takeBox(box, name, v, (int) getArgType(mb, pci, 0))) {		int bid = BBPindex(name);		if (bid > 0 && (v->vtype == TYPE_any || v->vtype == TYPE_bat)) {			/* adjust the types as well */			v->vtype = TYPE_bat;			v->val.ival = bid;			BBPincref(bid, TRUE);		} else			throw(MAL, "bbp.take", "failed to take object from box");	}	/* make a private copy for this client session */	/* use the cheapest copy method */	/* printf("bbp.take not yet fully implemented\n"); */	return MAL_SUCCEED;}strCMDbbprelease(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	str name;	Box box;	(void) mb;		/* fool compiler */	OpenBox("release");	name = (str) getArgValue(stk, pci, 1);	releaseBox(box, name);	/* merge the updates of this BAT with the master copy */	/* printf("bbp.release not yet fully implemented\n"); */	return MAL_SUCCEED;}@-A BAT can be released to make room for others.We decrease the reference count with one, but should notimmediately release it, because there may be aliases.@cstrCMDbbpreleaseBAT(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	int *bid;	Box box;	OpenBox("release");	bid = (int *) getArgValue(stk, pci, 1);	BBPdecref(*bid, TRUE);	releaseBAT(mb, stk, *bid);	*bid = 0;	return MAL_SUCCEED;}@-A BAT designated as garbage can be removed, provided wedo not keep additional references in the stack frameBe careful here not to remove persistent BATs.Note that we clear the dirty bit to ensure thatthe BAT is not written back to store before being freed.@cstrCMDbbpgarbage(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	int *bid;	Box box;	BAT *b;	(void) mb;	OpenBox("release");	bid = (int *) getArgValue(stk, pci, 1);	if ((b = BATdescriptor(*bid)) == NULL) {		throw(MAL, "bbp.garbage", "Cannot access descriptor");	}	b->batDirty= FALSE;

⌨️ 快捷键说明

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