📄 gdk.mx
字号:
@' 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 gdk@t The Goblin Database Kernel@v Version 3.05@a Martin L. Kersten & Peter Boncz@* The Inner CoreThe innermost library of the MonetDB database system is formed bythe library called GDK, an abbreviation of Goblin Database Kernel.Its development was originally rooted in the design of a pureactive-object-oriented programming language, before developmentwas shifted towards a re-usable database kernel engine.GDK is a C library that provides ACID properties on a DSM model@tex[@cite{Copeland85}]@end tex, using main-memorydatabase algorithms@tex[@cite{Garcia-Molina92}]@end tex built on virtual-memoryOS primitives and multi-threaded parallelism.Its implementation has undergone various changes over its decadeof development, many of which were driven by external needs toobtain a robust and fast database system.The coding scheme explored in GDK has also laid a foundation tocommunicate over time experiences and to provide (hopefully)helpful advice near to the place where the code-reader needs it.Of course, over such a long time the documentation diverges fromreality. Especially in areas where the environment of this packageis being described.Consider such deviations as historic landmarks, e.g. crystallizationof brave ideas and mistakes rectified at a later stage.@+ Short OutlineThe facilities provided in this implementation are:@itemize@itemGDK or Goblin Database Kernel routines for session management@item BAT routines that define the primitive operations on thedatabase tables (BATs).@item BBP routines to manage the BAT Buffer Pool (BBP).@item ATOM routines to manipulate primitive types, define new typesusing an ADT interface.@item HEAP routines for manipulating heaps: linear spaces of memorythat are GDK's vehicle of mass storage (on which BATs are built).@item DELTA routines to access inserted/deleted elements within atransaction.@item HASH routines for manipulating GDK's built-in linear-chainedhash tables, for accelerating lookup searches on BATs.@item TM routines that provide basic transaction management primitives.@item TRG routines that provided active database support. [DEPRECATED]@item ALIGN routines that implement BAT alignment management.@end itemizeThe Binary Association Table (BAT) is the lowest level of storageconsidered in the Goblin runtime system@tex[@cite{Goblin}]@end tex. A BAT is aself-descriptive main-memory structure that represents the @strong{binaryrelationship} between two atomic types.@The association can be defined over:@table @code@item void: virtual-OIDs: a densely ascending column of OIDs (takes zero-storage).@item bit: Booleans, implemented as one byte values.@item chr:A single character (8 bits @strong{integer}s).DEPRECATED for storing text (Unicode not supported).@item bte: Tiny (1-byte) integers (8-bit @strong{integer}s).@item sht: Short integers (16-bit @strong{integer}s).@item int: This is the C @strong{int} type (32-bit).@item oid: Unique @strong{long int} values uses as object identifier. Highest bit cleared always. Thus, oids-s are 31-bit numbers on 32-bit systems, and 63-bit numbers on 64-bit systems.@item wrd: Machine-word sized integers (32-bit on 32-bit systems, 64-bit on 64-bit systems).@item ptr:Memory pointer values. DEPRECATED. Can only be stored in transient BATs.@item flt: The IEEE @strong{float} type.@item dbl: The IEEE @strong{double} type.@item lng: Longs: the C @strong{long long} type (64-bit integers).@item str: UTF-8 strings (Unicode). A zero-terminated byte sequence.@item bat: Bat descriptor. This allows for recursive adminstered tables, butseverely complicates transaction management. Therefore, theyCAN ONLY BE STORED IN TRANSIENT BATs.[on the list to become depreciated,@end tableThis model can be used as a back-end model underlying other -higherlevel- models, in order to achieve @strong{better performance} and@strong{data independence} in one go. The relational model andthe object-oriented model can be mapped on BATs by verticallysplitting every table (or class) for each attribute. Each such acolumn is then stored in a BAT with type @strong{bat[oid,attribute]}, wherethe unique object identifiers link tuples in the different BATs.Relationship attributes in the object-oriented model hence aremapped to @strong{bat[oid,oid]} tables, being equivalent to the concept of@emph{join indexes}@tex[@cite{Valduriez87}]@end tex.The set of built-in types can be extended with user-defined typesthrough an ADT interface. They are linked with the kernel to obtainan enhanced library, or they are dynamically loaded upon request.Types can be derived from other types. They represent something differentthan that from which they are derived, but their internal storage managementis equal. This feature facilitates the work of extension programmers, byenabling reuse of implementation code, but is also used to keep the GDK codeportable from 32-bits to 64-bits machines: the @strong{oid} and @strong{ptr} typesare derived from @strong{int} on 32-bits machines, but is derived from @strong{lng}on 64 bits machines. This requires changes in only two lines of code each.To accelerate lookup and search in BATs, GDK supports one built-insearch accelerator: hash tables. We choose an implementation efficient for main-memory: bucket chained hash @tex[@cite{LehCar86,Analyti92}]@end tex. Alternatively, when the table is sorted, it will resort to merge-scanoperations or binary lookups.@BATs are built on the concept of heaps, which are large pieces of mainmemory. They can also consist of virtual memory, in case the workingset exceeds main-memory. In this case, GDK supports operations thatcluster the heaps of a BAT, in order to improve performance of itsmain-memory.@- RationaleThe rationale for choosing a BAT as the building block for bothrelational and object-oriented system is based on the followingobservations:@itemize@item -Given the fact that CPU speed and main-memory increase incurrent workstation hardware for the last years has been exceedingIO access speed increase, traditional disk-page oriented algorithmsdo no longer take best advantage of hardware, in most database operations.Instead of having a disk-block oriented kernel with a large memorycache, we choose to build a main-memory kernel, that only under large datavolumes slowly degrades to IO-bound performance, comparable totraditional systems@tex[@cite{boncz95,boncz96}]@end tex.@item -Traditional (disk-based) relational systems move too much dataaround to save on (main-memory) join operations.The fully decomposed store (DSM@tex[@cite{Copeland85})]@end texassures that only those attributes of a relation that are needed,will have to be accessed.@item -The data management issues for a binary association is mucheasier to deal with than traditional @emph{struct}-based approachesencountered in relational systems.@item -Object-oriented systems often maintain a double cache, one with thedisk-based representation and a C pointer-based main-memory structure.This causes expensive conversions and replicated storage management.\\GDK does not do such `pointer swizzling'. It used virtual-memory (@strong{mmap()}) and buffer management advice (@strong{madvise()}) OS primitives tocache only once. Tables take the same form in memory as on disk,making the use of this technique transparent@tex[@cite{oo7}]@end tex.@end itemizeA RDBMS or OODBMS based on BATs strongly depends on our abilityto efficiently support tuples and to handle small joins, respectively.The remainder of this document describes the Goblin Database kernelimplementation at greater detail. It is organized as follows:@table @code@item @strong{GDK Interface}:It describes the global interface with which GDK sessions can bestarted and ended, and environment variables used.@item @strong{Binary Association Tables}:As already mentioned, these are the primary data structure of GDK.This chapter describes the kernel operations for creation, destructionand basic manipulation of BATs and BUNs (i.e. tuples: Binary UNits).@item @strong{BAT Buffer Pool:}All BATs are registered in the BAT Buffer Pool. This directory is usedto guide swapping in and out of BATs. Here we find routines that guidethis swapping process.@item @strong{GDK Extensibility:}Atoms can be defined using a unified ADT interface.There is also an interface to extend the GDK library withdynamically linked object code.@item @strong{GDK Utilities:}Memory allocation and error handling primitives are provided. Layersbuilt on top of GDK should use them, for proper system monitoring.Thread management is also included here.@item @strong{Transaction Management:}For the time being, we just provide BAT-grained concurrency and globaltransactions. Work is needed here.@item @strong{BAT Alignment:}Due to the mapping of multi-ary datamodels onto the BAT model,we expect many correspondences among BATs, e.g. @emph{bat(oid,attr1),..bat(oid,attrN)} vertical decompositions. Frequent activities will beto jump from one attribute to the other (`bunhopping'). If the headcolumns are equal lists in two BATs, merge or even array lookupscan be used instead of hash lookups. The alignment interface makesthese relations explicitly manageable.In GDK, complex data models are mapped with DSM on binary tables.Usually, one decomposes @emph{N}-ary relations into @emph{N} BATs withan @strong{oid} in the head column, and the attribute in the tail column.There may well be groups of tables that have the same sets of @strong{oid}s, equally ordered. The alignment interface is intended to makethis explicit. Implementations can use this interface to detect thissituation, and use cheaper algorithms (like merge-join, or even arraylookup) instead.@item @strong{BAT Iterators:}Iterators are C macros that generally encapsulate a complex for-loop.They would be the equivalent of cursors in the SQL model. The macrointerface (instead of a function call interface) is chosen to achievespeed when iterating main-memory tables.@item @strong{Common BAT Operations:}These are much used operations on BATs, such as aggregate functionsand relational operators. They are implemented in terms of BAT- andBUN-manipulation GDK primitives.@end table@@+ Interface FilesIn this section we summarize the user interface to the GDK library.It consist of a header file (gdk.h) and an object library (gdklib.a),which implements the required functionality. The header file must beincluded in any program that uses the library. The library must belinked with such a program.@- Database ContextThe MonetDB environment settings are collected in a configurationfile. Amongst others it contains the location of the databasedirectory.First, the databasedirectory is closed for other servers running at the same time.Second, performance enhancements may take effect, such as lockingthe code into memory (if the OS permits) and preloading thedata dictionary.An error at this stage normally lead to an abort.@{@h#ifndef _GDK_H_#define _GDK_H_#include <monet_utils.h>/* standard includes upon which all configure tests depend */#include <stdio.h>#ifdef HAVE_SYS_TYPES_H# include <sys/types.h>#endif#ifdef HAVE_SYS_STAT_H# include <sys/stat.h>#endif#ifdef STDC_HEADERS# include <stdlib.h># include <stddef.h>#else# ifdef HAVE_STDLIB_H# include <stdlib.h># endif#endif#ifdef HAVE_STRING_H# if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)# include <memory.h># endif# include <string.h>#endif#ifdef HAVE_STRINGS_H# include <strings.h>#endif#ifdef HAVE_INTTYPES_H# include <inttypes.h>#else# ifdef HAVE_STDINT_H# include <stdint.h># endif#endif#ifdef HAVE_UNISTD_H# include <unistd.h>#endif#include <ctype.h> /* isspace etc. */#ifdef HAVE_SYS_FILE_H# include <sys/file.h>#endif#ifdef HAVE_SYS_PARAM_H# include <sys/param.h> /* MAXPATHLEN */#endif#ifdef HAVE_DIRENT_H# include <dirent.h># define NAMLEN(dirent) strlen((dirent)->d_name)#else# define dirent direct# define NAMLEN(dirent) (dirent)->d_namlen# ifdef HAVE_SYS_NDIR_H# include <sys/ndir.h>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -