Source for 8.4.2.0 version of extsql.h
/* Copyright (C) 2006, 2007, 2008, 2009, 2010 Software Workshop Incorporated
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifndef EXTSQL_H
#define EXTSQL_H 1
#endif
#define PGSQL 1
#ifdef PGSQL
#define PGSQL_8 1 // only for 8.4 builds and above.
#include
#include
#include
#include
#include
#include
#include
#include
#include "postgres.h"
#include "libpq/pqcomm.h"
#include "miscadmin.h"
#include "catalog/pg_type.h"
#include "tcop/dest.h"
#include "executor/executor.h"
#include "storage/proc.h"
#include "storage/backendid.h"
#include "libpq/libpq-be.h"
#include "libpq/hba.h"
#include "storage/pg_shmem.h" // ZZ shared memory
#include "storage/spin.h"
#include "storage/fd.h"
#include "nodes/pg_list.h"
// need this stuff for PGSQL, mimics where stored in mysql (mysqld.cc)
// by default we are set for MySQL 4.x, PGSQL set for any PGSQL build where
// MySQL stuff will NOT apply
// NOTE variadic macros below, invoke with either '...' or '__VA_ARGS__' compiler dependent!
#define sql_print_information(str, ...) elog(LOG, str, ##__VA_ARGS__)
#define sql_print_warning(str, ...) elog(LOG, str, ##__VA_ARGS__)
#define sql_print_error(str, ...) elog(LOG, str, ##__VA_ARGS__)
#define net_printf(thd, x, str, ...) elog(ERROR, str, ##__VA_ARGS__)
#define DBUG_RETURN(x) return(x)
#define DBUG_ENTER(x)
#define NullS (char *) 0
#define MY_MUTEX_INIT_FAST &my_fast_mutexattr
#define pthread_mutex_trylock(lock) pthread_mutex_lock(lock)
#define my_free(x, y) free(x)
#define my_malloc(a,b) malloc(a)
#define my_open(fileName, mode, flag) open(fileName, mode)
#define my_read(fd, buff, bytes, flags) read(fd, buff, bytes)
#define my_write(fd, buff, bytes, flags) write(fd, buff, bytes)
#define MY_WME 1
#define MY_NABP 1
#define MY_ZEROFILL 1
#define MYF(a) a
#define O_BINARY 0 // ZZ
#define FN_REFLEN 255
typedef char byte;
typedef time_t my_time_t;
typedef time_t MYSQL_TIME;
typedef struct PGPROC THD;
typedef struct show_var_st {
char *name;
ulong *value;
} SHOW_VAR;
extern ulong Com_begin, Com_commit, Com_create_table, Com_delete,
Com_drop_table, Com_insert, Com_rollback, Com_select, Com_update, Connections, Questions;
extern int mysql_show_extsql(THD *thd, const char *stats_class, DestReceiver *dest, List *stats_vars,
uint stats_hourly, const char *wild, char *stats_order_var,
const uint stats_order_dir, const uint stats_order_limit, char *stats_where_var,
const uint stats_where_num, const uint stats_where_char);
#endif // PGSQL
#define STATS_DEBUG(Val) (Val & extsql_debug ? 1 : 0)
#define STATS_MAGIC_NUM 0x12345678
#define STATS_MAX_NAME 20 // max size of a Class name
#define STATS_TMP_BUFF_SIZE 2048
#define STATS_INIT_FAILURE 0 // define the start types
#define STATS_INIT_NORMAL 1
#define STATS_INIT_RESET 2
#define STATS_INIT_RELOAD 3
#define STATS_INIT_CONFIRM 4
#define STATS_THD_INIT_NORM 5
#define STATS_THD_INIT_DB 6
#define STATS_THD_INIT_ALL 7
#define STATS_WRITE_RELOAD 1 // actions taken with reload file
#define STATS_READ_RELOAD 2
#define STATS_SECTION_HDR 23 // characters in reload file section hdrs
#define STATS_SECTION_BYTES 13 // offset to first digit in byte count
#define STATS_MAX_NUM_ALLOC 200 // max independent mem allocs we track
#define MAX_VARS 50 // the most unique Vars we can track
// #define EXTSQL_50 1 -- external define set during build during configure.
// #define EXTSQL_BINARY 1 -- external define set during build during configure.
typedef struct stat_vars {
char *name;
char *addr;
} STAT_VAR, *pSTAT_VAR;
typedef struct stats_class_data { // keep this padded to 4 byte borders
char name[STATS_MAX_NAME]; // class name
ulong *data; // pointer to data area for that class
// 3-d array [instance index][var index][hour index, 0-summary]
ulong *dataEnd; // where does data end - limit check
int maxInstance;
char **instanceIndex; // indexes for named instances
int maxVar;
STAT_VAR **varIndex; // indexes for vars, name & addr
int maxTime;
char *varList; // NOT USED ZZ
int time; // the current time unit we are logging to
char timeUnits; // d - day, h - hour, m - minute
char padd[3];
my_time_t *timeLabels; // absolute time for each time entry in data
int lastTime; // the last clock time we saw for data logged
} STATS_CLASS_DATA, *pSTATS_CLASS_DATA;
// SHARED MEM -- all our global data
typedef struct global_alloc { // in same order as declared in extsql.cc
STATS_CLASS_DATA statData[STATS_MAX_CLASSES];
char *extsql_class_list, *extsql_reload_file;
char *statsAllocArray[STATS_MAX_NUM_ALLOC]; // used to track mem allocs for reset/free
int allocIndex; // our position in the global statsAllocArray
pthread_mutex_t LOCK_stats_load, LOCK_stats_clock;
char *extsql_key, *extsql_users, *extsql_version;
ulong extsql_active, // temp stop extsql activity, can be user re-activated by SET
extsql_disabled, // perm stop extsql activity, severe/license error, only cleared by server restart
extsql_reload_in_progress, // temp stop extsql activity during startType reset/reload
extsql_debug, queries, connects, extsql_counter;
char *varAddrTrackArray[MAX_VARS]; // tracks addr of vars of interest, speeds up increment search.
int varAddrCount; // how many do we have being tracked
int lastMin; // top of minute processing
} GLOBAL, *pGLOBAL;
extern pGLOBAL Shared;
// FOLLOWING only used at startup, then referenced from Shared.
extern ulong extsql_active, extsql_counter, extsql_debug, queries, connects;
extern char *extsql_class_list, *extsql_key, *extsql_users, *extsql_reload_file;
// FUNCTION PROTOTYPES
int extsql_init_globals();
int extsql_check(THD*, int);
#ifdef PGSQL
int extsql_output_prep_2_col(char *col1, char *col2,DestReceiver *dest,
TupOutputState **tstate, TupleDesc tupdesc);
int extsql_output_2_col(char *col1Str, int col1Int, char *col2Str, int col2Int,
DestReceiver *dest, TupOutputState *tstate);
void extsql_output_complete(THD *, TupOutputState *);
int extsql_usage(THD*, DestReceiver*);
int extsql_enable(THD*, DestReceiver*, uint);
int extsql_reset(THD* thd, DestReceiver*, const char* conf);
int extsql_file_io(THD* thd, DestReceiver*, uint io_mode, uint confirm, char* reload_file);
#else
static int extsql_output_prep_2_col(char *col1, char *col2, Protocol *protocol,
List- field_list, char *fill2);
static int extsql_output_2_col(char *col1Str, int col1Int, char *col2Str,
int col2Int, Protocol *protocol, char *fill1);
void extsql_output_complete(THD* thd, char *tstate);
int extsql_usage(THD*);
int extsql_enable(THD*, uint);
int extsql_reset(THD* thd, const char* conf);
int extsql_file_io(THD* thd, uint io_mode, uint confirm, char* reload_file);
#endif
extern void extsql_inc(ulong *V, ulong C);
extern int extsql_init(char *, int, char *);
extern void extsql_prep(int *, const char *, char *);
int extsql_thread_init(THD *thd, int initType);
int extsql_read_section_bytes(char*, File, char**, char*, int);
int extsql_reload(int action, char *loadFileName);
|