📄 mserver5.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 mserver5@a M.L. Kersten, P. Boncz, Niels Nes, Stefan Manegold, Sjoerd Mullender@v 5.0@* The Monet ServerThe program @code{ mserver5} is the MonetDB server. It is started by the databaseadministrator. The console is primarilly meant to further initializethe server, such as starting internet listeners.@+ Manual PageThe server is a multithreaded program. There is one system thread, and foreach service, e.g. a client session or transaction service,there is one worker thread.As a default, the server also starts the internet listener thread,on the port number specified in the parameter file.@- Usage@verbatimusage: mserver5 [options] [script] --dbname=<database_name> --dbfarm=<directory> --dbinit=<stmt> Server prepare statement --user=<dbaname> --password=<passwrd> --config=<config_file> --debug=<number> trace server actions[0] --daemon=yes|no run in background [no] --delay=<number> delay between mguardian tests [300] --set <option>=<value> set environment value --help this list of options@end verbatimThe server options have the following meaning:@table @code@item --dbname <db-name> open the database <db-name>.@item --config <config-file> where to find the environment settings@item --dbinit <stmt> execute the statement first.@end itemize@{@+ Implementation@h#ifndef _MONET_GLOBAL_H_#define _MONET_GLOBAL_H_#include "mal_config.h"#include "monet_options.h"#include "mal.h"#include "mal_session.h"#include "mal_import.h"#include "mal_client.h"#include "mal_function.h"/* #define MONET_GLOBAL_DEBUG */#endif /* _MONET_GLOBAL_H_ */@c#include "mal_config.h"#include "mserver5.h"#include "mal_authorize.h"#include "mal_sabaoth.h"#include <stdio.h>#include <errno.h>#include <string.h> /* strerror */#ifdef _CRTDBG_MAP_ALLOC/* Windows only: our definition of new and delete clashes with the one if _CRTDBG_MAP_ALLOC is defined.*/#undef _CRTDBG_MAP_ALLOC#endif@-The architecture is setup to handle multiple streams of requests.The first thread started represents the server. It reads from standard inputand writes to standard input. This is also a way to recognize the serveractions. To start the server in the background one should use the argument -background.This closes standard input. Direct execution in the background may causethe server to hang in stdio for input from the terminal.@ The server thread started remains in existence until all other threads die.The server is stopped by cntrl-D or receiving the quit command.@@cstatic int malloc_init = 1;/* NEEDED? */#if defined(_MSC_VER) && defined(__cplusplus)#include <eh.h>voidmserver_abort(){ fprintf(stderr, "\n! mserver_abort() was called by terminate(). !\n"); fflush(stderr); MT_global_exit(0);}#endifvoidusage(char *prog){ fprintf(stderr, "Usage: %s [options] [script]\n", prog); fprintf(stderr, " --dbname=<database_name> \n"); fprintf(stderr, " --dbfarm=<database_directory> \n"); fprintf(stderr, " --help for more options \n"); exit(0);}voidusage2(char *prog){ fprintf(stderr, "Usage: %s [options] [script]\n", prog); fprintf(stderr, " --dbname=<database_name> \n"); fprintf(stderr, " --dbfarm=<directory> \n"); fprintf(stderr, " --dbinit=<stmt> Server prepare statement\n"); fprintf(stderr, " --user=<str> Defaults to [monetdb]\n"); fprintf(stderr, " --password=<str> Defaults to [monetdb]\n"); fprintf(stderr, " --config=<config_file> \n"); fprintf(stderr, " --delay=<number> cycle delay [300]\n"); fprintf(stderr, " --debug=<number> trace server actions[0]\n"); fprintf(stderr, " --daemon=yes|no run in background [no]\n"); fprintf(stderr, " --set <option>=<value> set environment value\n"); fprintf(stderr, " --help this list of options \n"); exit(0);}@-A welcoming message is displayed to inform the user about recentchanges. @cvoidmonet_hello(opt *set, int setlen){#ifdef STATIC char *linkinfo = "statically";#else char *linkinfo = "dynamically";#endif char *msg = mo_find_option(set, setlen, "monet_welcome"); if (msg && strcmp(msg, "yes") == 0) { printf("# MonetDB Server v%s\n", GDKgetenv("gdk_version")); printf("# Copyright (c) 1993-2007 CWI, all rights reserved\n"); printf("# Compiled for %s/" SZFMT "bit with " SZFMT "bit OIDs %s linked\n", HOST, (size_t) (sizeof(ptr) * 8), (size_t) (sizeof(oid) * 8), linkinfo);#ifdef MONET_GLOBAL_DEBUG printf("# config:%s\n", GDKgetenv("config")); printf("# dbfarm:%s\n", GDKgetenv("gdk_dbfarm"));#endif printf("# dbname:%s\n", GDKgetenv("gdk_dbname")); printf("# Visit http://monetdb.cwi.nl/ for further information\n"); }}strabsolute_path(str s){ if (!MT_path_absolute(s)) { str ret = (str) GDKmalloc(strlen(s) + strlen(monet_cwd) + 2); sprintf(ret, "%s%c%s", monet_cwd, DIR_SEP, s); return ret; } return GDKstrdup(s);}@-The options obtained during initialization should be maintained asa global structure for other components to extract information.@c#define BSIZE 8192intmonet_init(opt *set, int setlen){ char *p; opt *n = (opt *) malloc(setlen * sizeof(opt)); int i, j, nlen = 0; char *dbname = mo_find_option(set, setlen, "gdk_dbname"); char *dbfarm = mo_find_option(set, setlen, "gdk_dbfarm"); char *alloc_map = mo_find_option(set, setlen, "gdk_alloc_map"); if (n == NULL || dbname == NULL || dbfarm == NULL || alloc_map == NULL) { fprintf(stderr, "Error, no database name or directory\n"); if (n) free(n); return 0; } dbfarm = mo_substitute(set, setlen, dbfarm); if ((p = mo_find_option(set, setlen, "gdk_debug"))) GDKdebug = strtol(p, NULL, 10); /* determine Monet's kernel settings */ if (!GDKinit(dbname, dbfarm, strcasecmp(alloc_map, "yes") == 0) ) { free(dbfarm); free(n); return 0; } free(dbfarm);@-Find duplicate entries in the property list and movethem to the front. Actually, this should be done inmonet_options.mx.in@c for (i = 0; i < setlen; i++) { int done = 0; for (j = 0; j < nlen; j++) { if (strcmp(n[j].name, set[i].name) == 0) { if (n[j].kind < set[i].kind) { n[j] = set[i]; } done = 1; break; } } if (!done) { n[nlen] = set[i]; nlen++; } } for (i = 0; i < nlen; i++) { char *value; value = mo_substitute(n, nlen, n[i].value); GDKsetenv(n[i].name, value); free(value); } free(n); if ((p = GDKgetenv("gdk_mem_bigsize"))) { /* when allocating >6% of all RAM; do so using vmalloc() iso malloc() */ lng max_mem_bigsize = GDK_mem_maxsize/16; /* sanity check to avoid memory fragmentation */ GDK_mem_bigsize = (size_t) MIN(max_mem_bigsize, strtol(p, NULL, 10)); } if ((p = GDKgetenv("gdk_vm_minsize"))){ /* when allocating HUGE regions, switch from vmalloc() to mmap() on a real file */ /* for 32-bits systems HUGE = RAM/8, for 64-bits systems HUGE = RAM/2 */ lng max_vm_minsize = ((lng)GDK_mem_maxsize*sizeof(void*)*sizeof(void*))/128; /* sanity check to avoid running out of swap space */ GDK_vm_minsize = (size_t) MIN(max_vm_minsize, strtol(p, NULL, 10)); } if (GDKgetenv_isyes("gdk_embedded") || GDKgetenv_isyes("embedded")) { GDKembedded = 1; } if (GDKgetenv_isyes("monet_daemon") || GDKgetenv_isyes("daemon")) { monet_daemon = 1;#ifdef HAVE_SETSID setsid();#endif } monet_hello(set, setlen);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -