Commit a2e4768f authored by unknown's avatar unknown

aligned ndb versioning with mysql

    changed define SNPRINTF_RETURN_ZERO to SNPRINTF_RETURN_TRUNC
    added define NDB_INIT
    removed getarg, strlcat, strlcpy
    aligned ndb version with mysql version
    cpcd: removed old way of reading config file and replaced with mysql load_defaults
    changed from using getarg to my_getopts
    use mysql my_progname
    moved getarg to test


BitKeeper/deleted/.del-strlcat.c~250851f8f1ac1c2c:
  Delete: ndb/src/common/util/strlcat.c
BitKeeper/deleted/.del-strlcpy.c~43266e312d11c47b:
  Delete: ndb/src/common/util/strlcpy.c
ndb/test/include/getarg.h:
  Rename: ndb/include/util/getarg.h -> ndb/test/include/getarg.h
configure.in:
  aligned ndb versioning with mysql
  changed define SNPRINTF_RETURN_ZERO to SNPRINTF_RETURN_TRUNC
ndb/include/ndb_global.h:
  added define NDB_INIT
  removed strlcpy, strlcat
ndb/src/common/editline/sysunix.c:
  removed usage of strlcat
ndb/src/common/util/Makefile.am:
  removed getarg, strlcat, strlcpy
ndb/src/common/util/basestring_vsnprintf.c:
  changed define from SNPRINTF_RETURN_ZERO to SNPRINTF_RETURN_TRUNC
ndb/src/common/util/socket_io.cpp:
  removed usage of strlcat
ndb/src/common/util/version.c:
  aligned ndb version with mysql version
ndb/src/cw/cpcd/common.cpp:
  removed old way of reading config file and replaced with mysql load_defaults
ndb/src/cw/cpcd/common.hpp:
  removed old way of reading config file and replaced with mysql load_defaults
ndb/src/cw/cpcd/main.cpp:
  changed from usin getarg to my_opts
ndb/src/kernel/blocks/backup/restore/main.cpp:
  changed from usin getarg to my_opts
ndb/src/kernel/error/ErrorReporter.cpp:
  use mysql my_progname
ndb/src/kernel/main.cpp:
  removed const in main declaration
ndb/src/kernel/vm/Configuration.cpp:
  changed from usin getarg to my_opts
ndb/src/kernel/vm/Configuration.hpp:
  removed const in main declaration
ndb/src/mgmclient/main.cpp:
  changed from usin getarg to my_opts
ndb/src/mgmsrv/main.cpp:
  changed from usin getarg to my_opts
ndb/src/ndbapi/Ndb.cpp:
  fixed compiler warnings
ndb/test/run-test/Makefile.am:
  moved getarg to test
ndb/test/src/Makefile.am:
  moved getarg to test
ndb/test/src/getarg.c:
  moved strlcat and strlcpy into getarg.c
ndb/tools/delete_all.cpp:
  changed from usin getarg to my_opts
ndb/tools/desc.cpp:
  changed from usin getarg to my_opts
ndb/tools/drop_index.cpp:
  changed from usin getarg to my_opts
ndb/tools/drop_tab.cpp:
  changed from usin getarg to my_opts
ndb/tools/listTables.cpp:
  changed from usin getarg to my_opts
ndb/tools/select_all.cpp:
  changed from usin getarg to my_opts
ndb/tools/select_count.cpp:
  changed from usin getarg to my_opts
ndb/tools/waiter.cpp:
  changed from usin getarg to my_opts
parent d46c7366
......@@ -4,6 +4,7 @@ dnl Process this file with autoconf to produce a configure script.
AC_INIT(sql/mysqld.cc)
AC_CANONICAL_SYSTEM
# The Docs Makefile.am parses this line!
# remember to also change ndb version below and update version.c in ndb
AM_INIT_AUTOMAKE(mysql, 4.1.8)
AM_CONFIG_HEADER(config.h)
......@@ -13,9 +14,9 @@ DOT_FRM_VERSION=6
SHARED_LIB_VERSION=14:0:0
# ndb version
NDB_VERSION_MAJOR=3
NDB_VERSION_MINOR=5
NDB_VERSION_BUILD=4
NDB_VERSION_MAJOR=4
NDB_VERSION_MINOR=1
NDB_VERSION_BUILD=8
NDB_VERSION_STATUS=""
# Set all version vars based on $VERSION. How do we do this more elegant ?
......@@ -1142,8 +1143,8 @@ dnl Is this the right match for DEC OSF on alpha?
fi
echo "Adding defines for OSF1"
# gethostbyname_r is deprecated and doesn't work ok on OSF1
CFLAGS="$CFLAGS -DUNDEF_HAVE_GETHOSTBYNAME_R -DSNPRINTF_RETURN_ZERO"
CXXFLAGS="$CXXFLAGS -DUNDEF_HAVE_GETHOSTBYNAME_R -DSNPRINTF_RETURN_ZERO"
CFLAGS="$CFLAGS -DUNDEF_HAVE_GETHOSTBYNAME_R -DSNPRINTF_RETURN_TRUNC"
CXXFLAGS="$CXXFLAGS -DUNDEF_HAVE_GETHOSTBYNAME_R -DSNPRINTF_RETURN_TRUNC"
# fix to handle include of <stdint.h> correctly on OSF1 with cxx compiler
CXXFLAGS="$CXXFLAGS -I/usr/include/cxx -I/usr/include/cxx_cname -I/usr/include -I/usr/include.dtk"
;;
......
......@@ -82,19 +82,12 @@ extern "C" {
/* call in main() - does not return on error */
extern int ndb_init(void);
extern void ndb_end(int);
#define NDB_INIT(prog_name) {my_progname=(prog_name); ndb_init();}
#ifndef HAVE_STRDUP
extern char * strdup(const char *s);
#endif
#ifndef HAVE_STRLCPY
extern size_t strlcpy (char *dst, const char *src, size_t dst_sz);
#endif
#ifndef HAVE_STRLCAT
extern size_t strlcat (char *dst, const char *src, size_t dst_sz);
#endif
#ifndef HAVE_STRCASECMP
extern int strcasecmp(const char *s1, const char *s2);
extern int strncasecmp(const char *s1, const char *s2, size_t n);
......
/* Copyright (C) 2003 MySQL AB
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 _NDB_OPTS_H
#define _NDB_OPTS_H
#include <my_sys.h>
#include <my_getopt.h>
#include <mysql_version.h>
#include <ndb_version.h>
#ifndef DBUG_OFF
#define NDB_STD_OPTS(prog_name) \
{ "debug", '#', "Output debug log. Often this is 'd:t:o,filename'.", \
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0 }, \
{ "usage", '?', "Display this help and exit.", \
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }, \
{ "help", '?', "Display this help and exit.", \
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }, \
{ "version", 'V', "Output version information and exit.", 0, 0, 0, \
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }, \
{ "connect-string", 'c', \
"Set connect string for connecting to ndb_mgmd. " \
"<constr>=\"host=<hostname:port>[;nodeid=<id>]\". " \
"Overides specifying entries in NDB_CONNECTSTRING and config file", \
(gptr*) &opt_connect_str, (gptr*) &opt_connect_str, 0, \
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }
#else
#define NDB_STD_OPTS(prog_name) \
{ "usage", '?', "Display this help and exit.", \
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }, \
{ "help", '?', "Display this help and exit.", \
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }, \
{ "version", 'V', "Output version information and exit.", 0, 0, 0, \
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }, \
{ "connect-string", 'c', \
"Set connect string for connecting to ndb_mgmd. " \
"<constr>=\"host=<hostname:port>[;nodeid=<id>]\". " \
"Overides specifying entries in NDB_CONNECTSTRING and config file", \
(gptr*) &opt_connect_str, (gptr*) &opt_connect_str, 0, \
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }
#endif
#endif /*_NDB_OPTS_H */
......@@ -138,6 +138,11 @@ rl_add_slash(char *path, char *p, size_t p_len)
{
struct stat Sb;
if (stat(path, &Sb) >= 0)
(void)strlcat(p, S_ISDIR(Sb.st_mode) ? "/" : " ", p_len);
if (stat(path, &Sb) >= 0) {
int len= strlen(p);
if (len+1 < p_len) {
p[len]= S_ISDIR(Sb.st_mode) ? '/' : ' ';
p[len+1]= 0;
}
}
}
......@@ -7,8 +7,8 @@ libgeneral_la_SOURCES = \
SocketServer.cpp SocketClient.cpp SocketAuthenticator.cpp\
OutputStream.cpp NdbOut.cpp BaseString.cpp Base64.cpp \
NdbSqlUtil.cpp new.cpp \
uucode.c random.c getarg.c version.c \
strdup.c strlcat.c strlcpy.c \
uucode.c random.c version.c \
strdup.c \
ConfigValues.cpp ndb_init.c basestring_vsnprintf.c
include $(top_srcdir)/ndb/config/common.mk.am
......
......@@ -34,20 +34,19 @@ basestring_snprintf(char *str, size_t size, const char *format, ...)
#ifdef HAVE_SNPRINTF
#define BASESTRING_VSNPRINTF_FUNC(a,b,c,d) vsnprintf(a,b,c,d)
#else
#define SNPRINTF_RETURN_ZERO
#define SNPRINTF_RETURN_TRUNC
#define BASESTRING_VSNPRINTF_FUNC(a,b,c,d) my_vsnprintf(a,b,c,d)
extern int my_vsnprintf(char *str, size_t size, const char *format, va_list ap);
#endif
#ifdef SNPRINTF_RETURN_ZERO
#ifdef SNPRINTF_RETURN_TRUNC
static char basestring_vsnprintf_buf[16*1024];
#endif
int
basestring_vsnprintf(char *str, size_t size, const char *format, va_list ap)
{
int ret= BASESTRING_VSNPRINTF_FUNC(str, size, format, ap);
#ifdef SNPRINTF_RETURN_ZERO
if (ret == 0 && format != 0 && format[0] != '\0') {
#ifdef SNPRINTF_RETURN_TRUNC
if (ret == size-1) {
ret= BASESTRING_VSNPRINTF_FUNC(basestring_vsnprintf_buf,
sizeof(basestring_vsnprintf_buf),
format, ap);
......
......@@ -172,22 +172,21 @@ vprint_socket(NDB_SOCKET_TYPE socket, int timeout_millis,
const char * fmt, va_list ap){
char buf[1000];
char *buf2 = buf;
size_t size = sizeof(buf);
size_t size;
if (fmt != 0) {
if (fmt != 0 && fmt[0] != 0) {
size = BaseString::vsnprintf(buf, sizeof(buf), fmt, ap);
/* Check if the output was truncated */
if(size >= sizeof(buf)) {
buf2 = (char *)malloc(size+1);
if(size > sizeof(buf)) {
buf2 = (char *)malloc(size);
if(buf2 == NULL)
return -1;
BaseString::vsnprintf(buf2, size, fmt, ap);
} else
size = sizeof(buf);
}
} else
buf[0] = 0;
return 0;
int ret = write_socket(socket, timeout_millis, buf2, strlen(buf2));
int ret = write_socket(socket, timeout_millis, buf2, size);
if(buf2 != buf)
free(buf2);
return ret;
......@@ -199,23 +198,23 @@ vprintln_socket(NDB_SOCKET_TYPE socket, int timeout_millis,
const char * fmt, va_list ap){
char buf[1000];
char *buf2 = buf;
size_t size = sizeof(buf);
size_t size;
if (fmt != 0) {
size = BaseString::vsnprintf(buf, sizeof(buf), fmt, ap);
if (fmt != 0 && fmt[0] != 0) {
size = BaseString::vsnprintf(buf, sizeof(buf), fmt, ap)+1;// extra byte for '/n'
/* Check if the output was truncated */
if(size >= sizeof(buf)-1) {
buf2 = (char *)malloc(size+2);
if(size > sizeof(buf)) {
buf2 = (char *)malloc(size);
if(buf2 == NULL)
return -1;
BaseString::vsnprintf(buf2, size+1, fmt, ap);
} else
size = sizeof(buf);
} else
buf[0] = 0;
strlcat(buf2, "\n", size+2);
BaseString::vsnprintf(buf2, size, fmt, ap);
}
} else {
size = 1;
}
buf2[size-1]='\n';
int ret = write_socket(socket, timeout_millis, buf2, strlen(buf2));
int ret = write_socket(socket, timeout_millis, buf2, size);
if(buf2 != buf)
free(buf2);
return ret;
......
/*
* Copyright (c) 1995 - 1999 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <ndb_global.h>
/* RCSID("$KTH: strlcat.c,v 1.1 2000/08/16 01:23:47 lha Exp $"); */
#ifndef HAVE_STRLCAT
size_t
strlcat (char *dst, const char *src, size_t dst_sz)
{
size_t len = strlen(dst);
return len + strlcpy (dst + len, src, dst_sz - len);
}
#endif
/*
* Copyright (c) 1995 - 1999 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <ndb_global.h>
/* RCSID("$KTH: strlcpy.c,v 1.1 2000/08/16 01:23:48 lha Exp $"); */
#ifndef HAVE_STRLCPY
size_t
strlcpy (char *dst, const char *src, size_t dst_sz)
{
size_t n;
char *p;
for (p = dst, n = 0;
n + 1 < dst_sz && *src != '\0';
++p, ++src, ++n)
*p = *src;
*p = '\0';
if (*src == '\0')
return n;
else
return n + strlen (src);
}
#endif
......@@ -70,6 +70,7 @@ struct NdbUpGradeCompatible {
#ifndef TEST_VERSION
struct NdbUpGradeCompatible ndbCompatibleTable_full[] = {
{ MAKE_VERSION(3,5,2), MAKE_VERSION(3,5,1), UG_Exact },
{ MAKE_VERSION(4,1,8), MAKE_VERSION(3,5,4), UG_Exact }, /* Aligned version with MySQL */
{ 0, 0, UG_Null }
};
......
......@@ -96,66 +96,3 @@ insert_file(const char * filename, class Properties& p){
if(f) fclose(f);
return res;
}
int
parse_config_file(struct getargs args[], int num_arg, const Properties& p){
Properties::Iterator it(&p);
for(const char * name = it.first(); name != 0; name = it.next()){
bool found = false;
for(int i = 0; i<num_arg; i++){
if(strcmp(name, args[i].long_name) != 0)
continue;
found = true;
const char * tmp;
p.get(name, &tmp);
int t = 1;
switch(args[i].type){
case arg_integer:{
int val = atoi(tmp);
if(args[i].value){
*((int*)args[i].value) = val;
}
}
break;
case arg_string:
if(args[i].value){
*((const char**)args[i].value) = tmp;
}
break;
case arg_negative_flag:
t = 0;
case arg_flag:
if(args[i].value){
if(!strcasecmp(tmp, "y") ||
!strcasecmp(tmp, "on") ||
!strcasecmp(tmp, "true") ||
!strcasecmp(tmp, "1")){
*((int*)args[i].value) = t;
}
if(!strcasecmp(tmp, "n") ||
!strcasecmp(tmp, "off") ||
!strcasecmp(tmp, "false") ||
!strcasecmp(tmp, "0")){
*((int*)args[i].value) = t;
}
}
t = 1;
break;
case arg_strings:
case arg_double:
case arg_collect:
case arg_counter:
break;
}
}
if(!found) {
printf("Unknown parameter: %s\n", name);
return 1;
}
}
return 0;
}
......@@ -19,7 +19,9 @@
#include <ndb_global.h>
#include <logger/Logger.hpp>
#if 0
#include <getarg.h>
#endif
extern int debug;
......@@ -30,6 +32,5 @@ int insert(const char * pair, class Properties & p);
int insert_file(const char * filename, class Properties&);
int insert_file(FILE *, class Properties&, bool break_on_empty = false);
int parse_config_file(struct getargs args[], int num_arg, const Properties& p);
#endif /* ! __CPCD_COMMON_HPP_INCLUDED__ */
......@@ -15,13 +15,13 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <ndb_global.h> /* Needed for mkdir(2) */
#include <ndb_opts.h>
#include "CPCD.hpp"
#include "APIService.hpp"
#include <NdbMain.h>
#include <NdbSleep.h>
#include <BaseString.hpp>
#include <getarg.h>
#include <logger/Logger.hpp>
#include <logger/FileLogHandler.hpp>
#include <logger/SysLogHandler.hpp>
......@@ -29,28 +29,44 @@
#include "common.hpp"
static const char *work_dir = CPCD_DEFAULT_WORK_DIR;
static int port = CPCD_DEFAULT_TCP_PORT;
static int use_syslog = 0;
static int port;
static int use_syslog;
static const char *logfile = NULL;
static const char *config_file = CPCD_DEFAULT_CONFIG_FILE;
static const char *user = 0;
static struct getargs args[] = {
{ "work-dir", 'w', arg_string, &work_dir,
"Work directory", "directory" },
{ "port", 'p', arg_integer, &port,
"TCP port to listen on", "port" },
{ "syslog", 'S', arg_flag, &use_syslog,
"Log events to syslog", NULL},
{ "logfile", 'L', arg_string, &logfile,
"File to log events to", "file"},
{ "debug", 'D', arg_flag, &debug,
"Enable debug mode", NULL},
{ "config", 'c', arg_string, &config_file, "Config file", NULL },
{ "user", 'u', arg_string, &user, "Run as user", NULL }
static struct my_option my_long_options[] =
{
{ "work-dir", 'w', "Work directory",
(gptr*) &work_dir, (gptr*) &work_dir, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ "port", 'p', "TCP port to listen on",
(gptr*) &port, (gptr*) &port, 0,
GET_INT, REQUIRED_ARG, CPCD_DEFAULT_TCP_PORT, 0, 0, 0, 0, 0 },
{ "syslog", 'S', "Log events to syslog",
(gptr*) &use_syslog, (gptr*) &use_syslog, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "logfile", 'L', "File to log events to",
(gptr*) &logfile, (gptr*) &logfile, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ "debug", 'D', "Enable debug mode",
(gptr*) &debug, (gptr*) &debug, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "config", 'c', "Config file",
(gptr*) &config_file, (gptr*) &config_file, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ "user", 'u', "Run as user",
(gptr*) &user, (gptr*) &user, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
static const int num_args = sizeof(args) / sizeof(args[0]);
static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
return 0;
}
static CPCD * g_cpcd = 0;
#if 0
......@@ -59,23 +75,16 @@ extern "C" static void sig_child(int signo, siginfo_t*, void*);
const char *progname = "ndb_cpcd";
NDB_MAIN(ndb_cpcd){
int optind = 0;
if(getarg(args, num_args, argc, argv, &optind)) {
arg_printusage(args, num_args, progname, "");
exit(1);
}
Properties p;
insert_file(config_file, p);
if(parse_config_file(args, num_args, p)){
ndbout_c("Invalid config file: %s", config_file);
exit(1);
}
int main(int argc, char** argv){
int save_argc= argc;
char** save_argv= argv;
const char *load_default_groups[]= { "ndb_cpcd",0 };
MY_INIT(argv[0]);
if(getarg(args, num_args, argc, argv, &optind)) {
arg_printusage(args, num_args, progname, "");
load_defaults("ndb_cpcd",load_default_groups,&argc,&argv);
if (handle_options(&argc, &argv, my_long_options, get_one_option)) {
my_print_help(my_long_options);
my_print_variables(my_long_options);
exit(1);
}
......
......@@ -14,7 +14,8 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <getarg.h>
#include <ndb_global.h>
#include <ndb_opts.h>
#include <Vector.hpp>
#include <ndb_limits.h>
#include <NdbTCP.h>
......@@ -35,80 +36,107 @@ static Vector<class BackupConsumer *> g_consumers;
static const char* ga_backupPath = "." DIR_SEPARATOR;
static const char* ga_connect_NDB = NULL;
static const char* opt_connect_str= NULL;
/**
* print and restore flags
*/
static bool ga_restore = false;
static bool ga_print = false;
static int _print = 0;
static int _print_meta = 0;
static int _print_data = 0;
static int _print_log = 0;
static int _restore_data = 0;
static int _restore_meta = 0;
static struct my_option my_long_options[] =
{
NDB_STD_OPTS("ndb_restore"),
{ "connect", 'c', "same as --connect-string",
(gptr*) &opt_connect_str, (gptr*) &opt_connect_str, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ "nodeid", 'n', "Backup files from node with id",
(gptr*) &ga_nodeId, (gptr*) &ga_nodeId, 0,
GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ "backupid", 'b', "Backup id",
(gptr*) &ga_backupId, (gptr*) &ga_backupId, 0,
GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ "restore_data", 'r',
"Restore table data/logs into NDB Cluster using NDBAPI",
(gptr*) &_restore_data, (gptr*) &_restore_data, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "restore_meta", 'm',
"Restore meta data into NDB Cluster using NDBAPI",
(gptr*) &_restore_meta, (gptr*) &_restore_meta, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "parallelism", 'p',
"No of parallel transactions during restore of data."
"(parallelism can be 1 to 1024)",
(gptr*) &ga_nParallelism, (gptr*) &ga_nParallelism, 0,
GET_INT, REQUIRED_ARG, 128, 0, 0, 0, 0, 0 },
{ "print", 256, "Print data and log to stdout",
(gptr*) &_print, (gptr*) &_print, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "print_data", 257, "Print data to stdout",
(gptr*) &_print_data, (gptr*) &_print_data, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "print_meta", 258, "Print meta data to stdout",
(gptr*) &_print_meta, (gptr*) &_print_meta, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "print_log", 259, "Print log to stdout",
(gptr*) &_print_log, (gptr*) &_print_log, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "dont_ignore_systab_0", 'f',
"Experimental. Do not ignore system table during restore.",
(gptr*) &ga_dont_ignore_systab_0, (gptr*) &ga_dont_ignore_systab_0, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
static void short_usage_sub(void)
{
printf("Usage: %s [OPTIONS] [<path to backup files>]\n", my_progname);
}
static void print_version()
{
printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
}
static void usage()
{
short_usage_sub();
print_version();
my_print_help(my_long_options);
my_print_variables(my_long_options);
}
static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
switch (optid) {
case '#':
DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_restore.trace");
break;
case 'V':
print_version();
exit(0);
case '?':
usage();
exit(0);
}
return 0;
}
bool
readArguments(const int argc, const char** argv)
readArguments(int *pargc, char*** pargv)
{
int _print = 0;
int _print_meta = 0;
int _print_data = 0;
int _print_log = 0;
int _restore_data = 0;
int _restore_meta = 0;
struct getargs args[] =
{
{ "connect", 'c', arg_string, &ga_connect_NDB,
"NDB Cluster connection", "\"nodeid=<api id>;host=<hostname:port>\""},
{ "nodeid", 'n', arg_integer, &ga_nodeId,
"Backup files from node", "db node id"},
{ "backupid", 'b',arg_integer, &ga_backupId, "Backup id", "backup id"},
{ "print", '\0', arg_flag, &_print,
"Print data and log to stdout", "print data and log"},
{ "print_data", '\0', arg_flag, &_print_data,
"Print data to stdout", "print data"},
{ "print_meta", '\0', arg_flag, &_print_meta,
"Print meta data to stdout", "print meta data"},
{ "print_log", '\0', arg_flag, &_print_log,
"Print log to stdout", "print log"},
{ "restore_data", 'r', arg_flag, &_restore_data,
"Restore table data/logs into NDB Cluster using NDBAPI",
"Restore table data/log"},
{ "restore_meta", 'm', arg_flag, &_restore_meta,
"Restore meta data into NDB Cluster using NDBAPI", "Restore meta data"},
{ "parallelism", 'p', arg_integer, &ga_nParallelism,
"No of parallel transactions during restore of data."
"(parallelism can be 1 to 1024)",
"Parallelism"},
#ifdef USE_MYSQL
{ "use_mysql", '\0', arg_flag, &use_mysql,
"Restore meta data via mysql. Systab will be ignored. Data is restored "
"using NDBAPI.", "use mysql"},
{ "user", '\0', arg_string, &ga_user, "MySQL user", "Default: root"},
{ "password", '\0', arg_string, &ga_password, "MySQL user's password",
"Default: \"\" "},
{ "host", '\0', arg_string, &ga_host, "Hostname of MySQL server",
"Default: localhost"},
{ "socket", '\0', arg_string, &ga_socket, "Path to MySQL server socket file",
"Default: /tmp/mysql.sock"},
{ "port", '\0', arg_integer, &ga_port, "Port number of MySQL server",
"Default: 3306"},
#endif
{ "dont_ignore_systab_0", 'f', arg_flag, &ga_dont_ignore_systab_0,
"Experimental. Do not ignore system table during restore.",
"dont_ignore_systab_0"}
};
int num_args = sizeof(args) / sizeof(args[0]);
int optind = 0;
if (getarg(args, num_args, argc, argv, &optind) ||
const char *load_default_groups[]= { "ndb_tools","ndb_restore",0 };
load_defaults("my",load_default_groups,pargc,pargv);
if (handle_options(pargc, pargv, my_long_options, get_one_option) ||
ga_nodeId == 0 ||
ga_backupId == 0 ||
ga_nParallelism < 1 ||
ga_nParallelism >1024)
{
arg_printusage(args, num_args, argv[0], "<path to backup files>\n");
return false;
ga_nParallelism >1024) {
exit(1);
}
BackupPrinter* printer = new BackupPrinter();
......@@ -122,10 +150,6 @@ readArguments(const int argc, const char** argv)
return false;
}
/**
* Got segmentation fault when using the printer's attributes directly
* in getargs... Do not have the time to found out why... this is faster...
*/
if (_print)
{
ga_print = true;
......@@ -169,15 +193,14 @@ readArguments(const int argc, const char** argv)
g_consumers.push_back(c);
}
// Set backup file path
if (argv[optind] != NULL)
if (*pargv[0] != NULL)
{
ga_backupPath = argv[optind];
ga_backupPath = *pargv[0];
}
return true;
}
void
clearConsumers()
{
......@@ -204,19 +227,16 @@ free_data_callback()
}
int
main(int argc, const char** argv)
main(int argc, char** argv)
{
ndb_init();
if (!readArguments(argc, argv))
NDB_INIT(argv[0]);
if (!readArguments(&argc, &argv))
{
return -1;
}
if (ga_connect_NDB != NULL)
{
// Use connection string
Ndb::setConnectString(ga_connect_NDB);
}
Ndb::setConnectString(opt_connect_str);
/**
* we must always load meta data, even if we will only print it to stdout
......
......@@ -137,7 +137,7 @@ ErrorReporter::formatMessage(ErrorCategory type,
faultID,
(problemData == NULL) ? "" : problemData,
objRef,
programName,
my_progname,
processId,
theNameOfTheTraceFile ? theNameOfTheTraceFile : "<no tracefile>");
......
......@@ -53,11 +53,9 @@ extern "C" void handler_error(int signum); // for process signal handling
void systemInfo(const Configuration & conf,
const LogLevel & ll);
const char programName[] = "NDB Kernel";
NDB_MAIN(ndb_kernel){
ndb_init();
int main(int argc, char** argv)
{
NDB_INIT(argv[0]);
// Print to stdout/console
g_eventLogger.createConsoleHandler();
g_eventLogger.setCategory("NDB");
......
......@@ -15,6 +15,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <ndb_global.h>
#include <ndb_opts.h>
#include <LocalConfig.hpp>
#include "Configuration.hpp"
......@@ -28,8 +29,6 @@
#include <NdbOut.hpp>
#include <WatchDog.hpp>
#include <getarg.h>
#include <mgmapi_configuration.hpp>
#include <mgmapi_config_parameters_debug.h>
#include <kernel_config_parameters.h>
......@@ -47,81 +46,86 @@ extern "C" {
#include <EventLogger.hpp>
extern EventLogger g_eventLogger;
static const char* opt_connect_str= 0;
static int _daemon, _no_daemon, _initial, _no_start;
/**
* Arguments to NDB process
*/
static struct my_option my_long_options[] =
{
NDB_STD_OPTS("ndbd"),
{ "initial", 256,
"Perform initial start of ndbd, including cleaning the file system. "
"Consult documentation before using this",
(gptr*) &_initial, (gptr*) &_initial, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "nostart", 'n',
"Don't start ndbd immediately. Ndbd will await command from ndb_mgmd",
(gptr*) &_no_start, (gptr*) &_no_start, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "daemon", 'd', "Start ndbd as daemon (default)",
(gptr*) &_daemon, (gptr*) &_daemon, 0,
GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0 },
{ "nodaemon", 257,
"Do not start ndbd as daemon, provided for testing purposes",
(gptr*) &_no_daemon, (gptr*) &_no_daemon, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
static void short_usage_sub(void)
{
printf("Usage: %s [OPTIONS]\n", my_progname);
}
static void print_version()
{
printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
}
static void usage()
{
short_usage_sub();
print_version();
my_print_help(my_long_options);
my_print_variables(my_long_options);
}
static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
switch (optid) {
case '#':
DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndbd.trace");
break;
case 'V':
print_version();
exit(0);
case '?':
usage();
exit(0);
}
return 0;
}
bool
Configuration::init(int argc, const char** argv){
Configuration::init(int argc, char** argv)
{
const char *load_default_groups[]= { "ndbd",0 };
load_defaults("my",load_default_groups,&argc,&argv);
/**
* Default values for arguments
*/
int _no_start = 0;
int _initial = 0;
const char* _connect_str = NULL;
int _daemon = 1;
int _no_daemon = 0;
int _help = 0;
int _print_version = 0;
#ifndef DBUG_OFF
const char *debug_option= 0;
#endif
/**
* Arguments to NDB process
*/
struct getargs args[] = {
{ "version", 'v', arg_flag, &_print_version, "Print ndbd version", "" },
{ "nostart", 'n', arg_flag, &_no_start,
"Don't start ndbd immediately. Ndbd will await command from ndb_mgmd", "" },
{ "daemon", 'd', arg_flag, &_daemon, "Start ndbd as daemon (default)", "" },
{ "nodaemon", 0, arg_flag, &_no_daemon, "Do not start ndbd as daemon, provided for testing purposes", "" },
#ifndef DBUG_OFF
{ "debug", 0, arg_string, &debug_option,
"Specify debug options e.g. d:t:i:o,out.trace", "options" },
#endif
{ "initial", 0, arg_flag, &_initial,
"Perform initial start of ndbd, including cleaning the file system. Consult documentation before using this", "" },
int ho_error;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
{ "connect-string", 'c', arg_string, &_connect_str,
"Set connect string for connecting to ndb_mgmd. <constr>=\"host=<hostname:port>[;nodeid=<id>]\". Overides specifying entries in NDB_CONNECTSTRING and config file",
"<constr>" },
{ "usage", '?', arg_flag, &_help, "Print help", "" }
};
int num_args = sizeof(args) / sizeof(args[0]);
int optind = 0;
char desc[] =
"The MySQL Cluster kernel";
if(getarg(args, num_args, argc, argv, &optind) || _help) {
arg_printusage(args, num_args, argv[0], desc);
for (int i = 0; i < argc; i++) {
if (strcmp("-i",argv[i]) == 0) {
printf("flag depricated %s, use %s\n", "-i", "--initial");
}
}
return false;
}
if (_no_daemon) {
_daemon= 0;
}
// check for depricated flag '-i'
#ifndef DBUG_OFF
if (debug_option)
DBUG_PUSH(debug_option);
#endif
DBUG_PRINT("info", ("no_start=%d", _no_start));
DBUG_PRINT("info", ("initial=%d", _initial));
DBUG_PRINT("info", ("daemon=%d", _daemon));
DBUG_PRINT("info", ("connect_str=%s", _connect_str));
DBUG_PRINT("info", ("connect_str=%s", opt_connect_str));
ndbSetOwnVersion();
if (_print_version) {
ndbPrintVersion();
return false;
}
// Check the start flag
if (_no_start)
globalData.theRestartFlag = initial_state;
......@@ -133,8 +137,8 @@ Configuration::init(int argc, const char** argv){
_initialStart = true;
// Check connectstring
if (_connect_str)
_connectString = strdup(_connect_str);
if (opt_connect_str)
_connectString = strdup(opt_connect_str);
// Check daemon flag
if (_daemon)
......
......@@ -31,7 +31,7 @@ public:
/**
* Returns false if arguments are invalid
*/
bool init(int argc, const char** argv);
bool init(int argc, char** argv);
void fetch_configuration(LocalConfig &local_config);
void setupConfiguration();
......
......@@ -15,11 +15,12 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <ndb_global.h>
#include <ndb_opts.h>
#include <NdbMain.h>
#include <NdbHost.h>
#include <util/getarg.h>
#include <mgmapi.h>
#include <ndb_version.h>
#include <LocalConfig.hpp>
#include "CommandInterpreter.hpp"
......@@ -43,28 +44,62 @@ handler(int sig){
}
}
int main(int argc, const char** argv){
ndb_init();
int optind = 0;
static unsigned _try_reconnect;
static char *opt_connect_str= 0;
static struct my_option my_long_options[] =
{
NDB_STD_OPTS("ndb_mgm"),
{ "try-reconnect", 't',
"Specify number of retries for connecting to ndb_mgmd, default infinite",
(gptr*) &_try_reconnect, (gptr*) &_try_reconnect, 0,
GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
static void short_usage_sub(void)
{
printf("Usage: %s [OPTIONS] [hostname [port]]\n", my_progname);
}
static void print_version()
{
printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
}
static void usage()
{
short_usage_sub();
print_version();
my_print_help(my_long_options);
my_print_variables(my_long_options);
}
static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
switch (optid) {
case '#':
DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_mgm.trace");
break;
case 'V':
print_version();
exit(0);
case '?':
usage();
exit(0);
}
return 0;
}
int main(int argc, char** argv){
NDB_INIT(argv[0]);
const char *_host = 0;
int _port = 0;
int _help = 0;
int _try_reconnect = 0;
struct getargs args[] = {
{ "try-reconnect", 't', arg_integer, &_try_reconnect, "Specify number of retries for connecting to ndb_mgmd, default infinite", "#" },
{ "usage", '?', arg_flag, &_help, "Print help", "" },
};
int num_args = sizeof(args) / sizeof(args[0]); /* Number of arguments */
if(getarg(args, num_args, argc, argv, &optind) || _help) {
arg_printusage(args, num_args, progname, "[host [port]]");
exit(1);
}
const char *load_default_groups[]= { "ndb_mgm",0 };
argv += optind;
argc -= optind;
load_defaults("my",load_default_groups,&argc,&argv);
int ho_error;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
LocalConfig cfg;
......@@ -74,7 +109,7 @@ int main(int argc, const char** argv){
_port = atoi(argv[1]);
}
} else {
if(cfg.init(0, 0) && cfg.ids.size() > 0 && cfg.ids[0].type == MgmId_TCP){
if(cfg.init(opt_connect_str, 0) && cfg.ids.size() > 0 && cfg.ids[0].type == MgmId_TCP){
_host = cfg.ids[0].name.c_str();
_port = cfg.ids[0].port;
} else {
......
......@@ -15,6 +15,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <ndb_global.h>
#include <ndb_opts.h>
#include "MgmtSrvr.hpp"
#include "EventLogger.hpp"
......@@ -33,7 +34,6 @@
#include <ndb_version.h>
#include <ConfigRetriever.hpp>
#include <mgmapi_config_parameters.h>
#include <getarg.h>
#include <NdbAutoPtr.hpp>
......@@ -97,41 +97,70 @@ bool g_StopServer;
extern EventLogger g_EventLogger;
extern int global_mgmt_server_check;
int _print_version = 0;
#ifndef DBUG_OFF
const char *debug_option= 0;
#endif
struct getargs args[] = {
{ "version", 'v', arg_flag, &_print_version,
"Print ndb_mgmd version",""},
{ "config-file", 'c', arg_string, &glob.config_filename,
"Specify cluster configuration file (default config.ini if available)",
"filename"},
#ifndef DBUG_OFF
{ "debug", 0, arg_string, &debug_option,
"Specify debug options e.g. d:t:i:o,out.trace", "options"},
#endif
{ "daemon", 'd', arg_flag, &glob.daemon,
"Run ndb_mgmd in daemon mode (default)",""},
{ NULL, 'l', arg_string, &glob.local_config_filename,
"Specify configuration file connect string (default Ndb.cfg if available)",
"filename"},
{ "interactive", 0, arg_flag, &glob.interactive,
"Run interactive. Not supported but provided for testing purposes", ""},
{ "no-nodeid-checks", 0, arg_flag, &g_no_nodeid_checks,
"Do not provide any node id checks", ""},
{ "nodaemon", 0, arg_flag, &glob.non_interactive,
"Don't run as daemon, but don't read from stdin", "non-interactive"}
static char *opt_connect_str= 0;
static struct my_option my_long_options[] =
{
NDB_STD_OPTS("ndb_mgmd"),
{ "config-file", 'c', "Specify cluster configuration file",
(gptr*) &glob.config_filename, (gptr*) &glob.config_filename, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ "daemon", 'd', "Run ndb_mgmd in daemon mode (default)",
(gptr*) &glob.daemon, (gptr*) &glob.daemon, 0,
GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0 },
{ "l", 'l', "Specify configuration file connect string (default Ndb.cfg if available)",
(gptr*) &glob.local_config_filename, (gptr*) &glob.local_config_filename, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ "interactive", 256, "Run interactive. Not supported but provided for testing purposes",
(gptr*) &glob.interactive, (gptr*) &glob.interactive, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "no-nodeid-checks", 257, "Do not provide any node id checks",
(gptr*) &g_no_nodeid_checks, (gptr*) &g_no_nodeid_checks, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "nodaemon", 258, "Don't run as daemon, but don't read from stdin",
(gptr*) &glob.non_interactive, (gptr*) &glob.non_interactive, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
int num_args = sizeof(args) / sizeof(args[0]);
static void short_usage_sub(void)
{
printf("Usage: %s [OPTIONS]\n", my_progname);
}
static void print_version()
{
printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
}
static void usage()
{
short_usage_sub();
print_version();
my_print_help(my_long_options);
my_print_variables(my_long_options);
}
static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
switch (optid) {
case '#':
DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_mgmd.trace");
break;
case 'V':
print_version();
exit(0);
case '?':
usage();
exit(0);
}
return 0;
}
/*
* MAIN
*/
NDB_MAIN(mgmsrv){
ndb_init();
int main(int argc, char** argv)
{
NDB_INIT(argv[0]);
/**
* OSE specific. Enable shared ownership of file system resources.
......@@ -143,31 +172,20 @@ NDB_MAIN(mgmsrv){
#endif
global_mgmt_server_check = 1;
glob.config_filename= "config.ini";
int optind = 0;
if(getarg(args, num_args, argc, argv, &optind)) {
arg_printusage(args, num_args, progname, "");
exit(1);
}
const char *load_default_groups[]= { "ndb_mgmd",0 };
load_defaults("my",load_default_groups,&argc,&argv);
int ho_error;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
if (glob.interactive ||
glob.non_interactive) {
glob.daemon= 0;
}
#ifndef DBUG_OFF
if (debug_option)
DBUG_PUSH(debug_option);
#endif
if (_print_version) {
ndbPrintVersion();
exit(0);
}
if(glob.config_filename == NULL) {
glob.config_filename= "config.ini";
}
glob.socketServer = new SocketServer();
MgmApiService * mapi = new MgmApiService();
......
......@@ -1386,6 +1386,7 @@ Ndb::printState(const char* fmt, ...)
va_end(ap);
NdbMutex_Lock(ndb_print_state_mutex);
bool dups = false;
unsigned i;
ndbout << buf << " ndb=" << hex << this << dec;
#ifndef NDB_WIN32
ndbout << " thread=" << (int)pthread_self();
......@@ -1406,21 +1407,21 @@ Ndb::printState(const char* fmt, ...)
ndbout << "!! DUPS !!" << endl;
dups = true;
}
for (unsigned i = 0; i < theNoOfPreparedTransactions; i++)
for (i = 0; i < theNoOfPreparedTransactions; i++)
thePreparedTransactionsArray[i]->printState();
ndbout << "sent: " << theNoOfSentTransactions<< endl;
if (checkdups(theSentTransactionsArray, theNoOfSentTransactions)) {
ndbout << "!! DUPS !!" << endl;
dups = true;
}
for (unsigned i = 0; i < theNoOfSentTransactions; i++)
for (i = 0; i < theNoOfSentTransactions; i++)
theSentTransactionsArray[i]->printState();
ndbout << "completed: " << theNoOfCompletedTransactions<< endl;
if (checkdups(theCompletedTransactionsArray, theNoOfCompletedTransactions)) {
ndbout << "!! DUPS !!" << endl;
dups = true;
}
for (unsigned i = 0; i < theNoOfCompletedTransactions; i++)
for (i = 0; i < theNoOfCompletedTransactions; i++)
theCompletedTransactionsArray[i]->printState();
NdbMutex_Unlock(ndb_print_state_mutex);
}
......
......@@ -11,7 +11,7 @@ test_SCRIPTS=atrt-analyze-result.sh atrt-gather-result.sh atrt-setup.sh \
atrt-clear-result.sh make-config.sh make-index.sh make-html-reports.sh
atrt_SOURCES = main.cpp
INCLUDES_LOC = -I$(top_srcdir)/ndb/src/mgmclient
INCLUDES_LOC = -I$(top_srcdir)/ndb/test/include -I$(top_srcdir)/ndb/src/mgmclient
LDADD_LOC = $(top_builddir)/ndb/src/mgmclient/CpcClient.o \
$(top_builddir)/ndb/src/libndbclient.la \
$(top_builddir)/dbug/libdbug.a \
......
......@@ -9,7 +9,7 @@ libNDBT_a_SOURCES = \
HugoAsynchTransactions.cpp UtilTransactions.cpp \
NdbRestarter.cpp NdbRestarts.cpp NDBT_Output.cpp \
NdbBackup.cpp NdbConfig.cpp NdbGrep.cpp NDBT_Table.cpp \
NdbSchemaCon.cpp NdbSchemaOp.cpp
NdbSchemaCon.cpp NdbSchemaOp.cpp getarg.c
INCLUDES_LOC = -I$(top_srcdir)/ndb/src/common/mgmcommon -I$(top_srcdir)/ndb/include/mgmcommon -I$(top_srcdir)/ndb/include/kernel -I$(top_srcdir)/ndb/src/mgmapi
......
......@@ -36,15 +36,33 @@
#include "getarg.h"
#define ISFLAG(X) ((X).type == arg_flag || (X).type == arg_negative_flag)
#ifndef HAVE_STRLCPY
extern size_t strlcpy (char *dst, const char *src, size_t dst_sz);
#endif /* !HAVE_STRLCPY */
static size_t
strlcpy (char *dst, const char *src, size_t dst_sz)
{
size_t n;
char *p;
for (p = dst, n = 0;
n + 1 < dst_sz && *src != '\0';
++p, ++src, ++n)
*p = *src;
*p = '\0';
if (*src == '\0')
return n;
else
return n + strlen (src);
}
#endif
#ifndef HAVE_STRLCAT
extern size_t strlcat (char *dst, const char *src, size_t dst_sz);
#endif /* !HAVE_STRLCAT */
static size_t
strlcat (char *dst, const char *src, size_t dst_sz)
{
size_t len = strlen(dst);
return len + strlcpy (dst + len, src, dst_sz - len);
}
#endif
#define ISFLAG(X) ((X).type == arg_flag || (X).type == arg_negative_flag)
#ifndef max
#define max(a, b) (a) > (b) ? (a) : (b)
......
......@@ -15,41 +15,65 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <ndb_global.h>
#include <ndb_opts.h>
#include <NdbOut.hpp>
#include <NdbApi.hpp>
#include <NdbSleep.h>
#include <NDBT.hpp>
#include <getarg.h>
static int clear_table(Ndb* pNdb, const NdbDictionary::Table* pTab, int parallelism=240);
int main(int argc, const char** argv){
ndb_init();
const char* _tabname = NULL;
const char* _dbname = "TEST_DB";
int _help = 0;
struct getargs args[] = {
{ "usage", '?', arg_flag, &_help, "Print help", "" },
{ "database", 'd', arg_string, &_dbname, "dbname",
"Name of database table is in"}
};
int num_args = sizeof(args) / sizeof(args[0]);
int optind = 0;
static const char* opt_connect_str= 0;
static const char* _dbname = "TEST_DB";
static struct my_option my_long_options[] =
{
NDB_STD_OPTS("ndb_desc"),
{ "database", 'd', "Name of database table is in",
(gptr*) &_dbname, (gptr*) &_dbname, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
static void print_version()
{
printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
}
static void usage()
{
char desc[] =
"tabname\n"\
"This program will delete all records in the specified table using scan delete.\n";
if(getarg(args, num_args, argc, argv, &optind) ||
argv[optind] == NULL || _help) {
arg_printusage(args, num_args, argv[0], desc);
return NDBT_ProgramExit(NDBT_WRONGARGS);
print_version();
my_print_help(my_long_options);
my_print_variables(my_long_options);
}
static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
switch (optid) {
case '#':
DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_delete_all.trace");
break;
case 'V':
print_version();
exit(0);
case '?':
usage();
exit(0);
}
_tabname = argv[optind];
return 0;
}
int main(int argc, char** argv){
NDB_INIT(argv[0]);
const char *load_default_groups[]= { "ndb_tools",0 };
load_defaults("my",load_default_groups,&argc,&argv);
int ho_error;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
return NDBT_ProgramExit(NDBT_WRONGARGS);
Ndb::setConnectString(opt_connect_str);
// Connect to Ndb
Ndb MyNdb(_dbname);
......@@ -64,13 +88,12 @@ int main(int argc, const char** argv){
// Check if table exists in db
int res = NDBT_OK;
for(int i = optind; i<argc; i++){
for(int i = 0; i<argc; i++){
const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, argv[i]);
if(pTab == NULL){
ndbout << " Table " << _tabname << " does not exist!" << endl;
ndbout << " Table " << argv[i] << " does not exist!" << endl;
return NDBT_ProgramExit(NDBT_WRONGARGS);
}
ndbout << "Deleting all from " << argv[i] << "...";
if(clear_table(&MyNdb, pTab) == NDBT_FAILED){
res = NDBT_FAILED;
......
......@@ -14,40 +14,66 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <getarg.h>
#include <ndb_global.h>
#include <ndb_opts.h>
#include <NDBT.hpp>
#include <NdbApi.hpp>
int main(int argc, const char** argv){
ndb_init();
const char* _tabname = NULL;
const char* _dbname = "TEST_DB";
int _unqualified = 0;
int _help = 0;
struct getargs args[] = {
{ "unqualified", 'u', arg_flag, &_unqualified, "unqualified",
"Use unqualified table names"},
{ "database", 'd', arg_string, &_dbname, "dbname",
"Name of database table is in"},
{ "usage", '?', arg_flag, &_help, "Print help", "" }
};
int num_args = sizeof(args) / sizeof(args[0]);
int optind = 0;
static const char* opt_connect_str= 0;
static const char* _dbname = "TEST_DB";
static int _unqualified = 0;
static struct my_option my_long_options[] =
{
NDB_STD_OPTS("ndb_desc"),
{ "database", 'd', "Name of database table is in",
(gptr*) &_dbname, (gptr*) &_dbname, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ "unqualified", 'u', "Use unqualified table names",
(gptr*) &_unqualified, (gptr*) &_unqualified, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
static void print_version()
{
printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
}
static void usage()
{
char desc[] =
"tabname\n"\
"This program list all properties of table(s) in NDB Cluster.\n"\
" ex: desc T1 T2 T4\n";
if(getarg(args, num_args, argc, argv, &optind) ||
argv[optind] == NULL ||_help) {
arg_printusage(args, num_args, argv[0], desc);
return NDBT_ProgramExit(NDBT_WRONGARGS);
" ex: desc T1 T2 T4\n";
print_version();
my_print_help(my_long_options);
my_print_variables(my_long_options);
}
static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
switch (optid) {
case '#':
DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_desc.trace");
break;
case 'V':
print_version();
exit(0);
case '?':
usage();
exit(0);
}
_tabname = argv[optind];
return 0;
}
int main(int argc, char** argv){
NDB_INIT(argv[0]);
const char *load_default_groups[]= { "ndb_tools",0 };
load_defaults("my",load_default_groups,&argc,&argv);
int ho_error;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
return NDBT_ProgramExit(NDBT_WRONGARGS);
Ndb::setConnectString(opt_connect_str);
Ndb* pMyNdb;
pMyNdb = new Ndb(_dbname);
......@@ -60,7 +86,7 @@ int main(int argc, const char** argv){
ndbout << endl;
NdbDictionary::Dictionary * dict = pMyNdb->getDictionary();
for (int i = optind; i < argc; i++) {
for (int i = 0; i < argc; i++) {
NDBT_Table* pTab = (NDBT_Table*)dict->getTable(argv[i]);
if (pTab != 0){
ndbout << (* pTab) << endl;
......
......@@ -15,38 +15,66 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <ndb_global.h>
#include <ndb_opts.h>
#include <NdbOut.hpp>
#include <NdbApi.hpp>
#include <NDBT.hpp>
#include <getarg.h>
int main(int argc, const char** argv){
ndb_init();
const char* _tabname = NULL;
const char* _dbname = "TEST_DB";
int _help = 0;
struct getargs args[] = {
{ "database", 'd', arg_string, &_dbname, "dbname",
"Name of database table is in"},
{ "usage", '?', arg_flag, &_help, "Print help", "" }
};
int num_args = sizeof(args) / sizeof(args[0]);
int optind = 0;
static const char* opt_connect_str= 0;
static const char* _dbname = "TEST_DB";
static struct my_option my_long_options[] =
{
NDB_STD_OPTS("ndb_desc"),
{ "database", 'd', "Name of database table is in",
(gptr*) &_dbname, (gptr*) &_dbname, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
static void print_version()
{
printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
}
static void usage()
{
char desc[] =
"<indexname>+\n"\
"This program will drop index(es) in Ndb\n";
print_version();
my_print_help(my_long_options);
my_print_variables(my_long_options);
}
static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
switch (optid) {
case '#':
DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_drop_index.trace");
break;
case 'V':
print_version();
exit(0);
case '?':
usage();
exit(0);
}
return 0;
}
if(getarg(args, num_args, argc, argv, &optind) ||
argv[optind] == NULL || _help){
arg_printusage(args, num_args, argv[0], desc);
int main(int argc, char** argv){
NDB_INIT(argv[0]);
const char *load_default_groups[]= { "ndb_tools",0 };
load_defaults("my",load_default_groups,&argc,&argv);
int ho_error;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
return NDBT_ProgramExit(NDBT_WRONGARGS);
if (argc < 1) {
usage();
return NDBT_ProgramExit(NDBT_WRONGARGS);
}
_tabname = argv[optind];
Ndb::setConnectString(opt_connect_str);
// Connect to Ndb
Ndb MyNdb(_dbname);
if(MyNdb.init() != 0){
......@@ -58,7 +86,7 @@ int main(int argc, const char** argv){
ndbout << "Waiting for ndb to become ready..." << endl;
int res = 0;
for(int i = optind; i<argc; i++){
for(int i = 0; i<argc; i++){
ndbout << "Dropping index " << argv[i] << "...";
int tmp;
if((tmp = MyNdb.getDictionary()->dropIndex(argv[i], 0)) != 0){
......
......@@ -15,43 +15,67 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <ndb_global.h>
#include <ndb_opts.h>
#include <NdbOut.hpp>
#include <NdbApi.hpp>
#include <NDBT.hpp>
#include <getarg.h>
int main(int argc, const char** argv){
ndb_init();
const char* _tabname = NULL;
const char* _dbname = "TEST_DB";
const char* _connectstr = NULL;
int _help = 0;
struct getargs args[] = {
{ "database", 'd', arg_string, &_dbname, "dbname",
"Name of database table is in"},
{ "connstr", 'c', arg_string, &_connectstr, "connect string",
"How to connect to NDB"},
{ "usage", '?', arg_flag, &_help, "Print help", "" }
};
int num_args = sizeof(args) / sizeof(args[0]);
int optind = 0;
static const char* opt_connect_str= 0;
static const char* _dbname = "TEST_DB";
static struct my_option my_long_options[] =
{
NDB_STD_OPTS("ndb_desc"),
{ "database", 'd', "Name of database table is in",
(gptr*) &_dbname, (gptr*) &_dbname, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
static void print_version()
{
printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
ndbPrintVersion();
}
static void usage()
{
char desc[] =
"tabname\n"\
"This program will drop one table in Ndb\n";
print_version();
my_print_help(my_long_options);
my_print_variables(my_long_options);
}
static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
switch (optid) {
case '#':
DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_drop_table.trace");
break;
case 'V':
print_version();
exit(0);
case '?':
usage();
exit(0);
}
return 0;
}
if(getarg(args, num_args, argc, argv, &optind) ||
argv[optind] == NULL || _help){
arg_printusage(args, num_args, argv[0], desc);
int main(int argc, char** argv){
NDB_INIT(argv[0]);
const char *load_default_groups[]= { "ndb_tools",0 };
load_defaults("my",load_default_groups,&argc,&argv);
int ho_error;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
return NDBT_ProgramExit(NDBT_WRONGARGS);
if (argc < 1) {
usage();
return NDBT_ProgramExit(NDBT_WRONGARGS);
}
_tabname = argv[optind];
if (_connectstr)
Ndb::setConnectString(_connectstr);
Ndb::setConnectString(opt_connect_str);
Ndb MyNdb(_dbname);
if(MyNdb.init() != 0){
ERR(MyNdb.getNdbError());
......@@ -62,7 +86,7 @@ int main(int argc, const char** argv){
ndbout << "Waiting for ndb to become ready..." << endl;
int res = 0;
for(int i = optind; i<argc; i++){
for(int i = 0; i<argc; i++){
ndbout << "Dropping table " << argv[i] << "...";
int tmp;
if((tmp = MyNdb.getDictionary()->dropTable(argv[i])) != 0){
......
......@@ -22,7 +22,7 @@
*/
#include <ndb_global.h>
#include <getarg.h>
#include <ndb_opts.h>
#include <NdbApi.hpp>
#include <NDBT.hpp>
......@@ -161,39 +161,34 @@ list(const char * tabname,
}
}
#ifndef DBUG_OFF
const char *debug_option= 0;
#endif
int main(int argc, const char** argv){
ndb_init();
int _loops = 1;
const char* _tabname = NULL;
const char* _dbname = "TEST_DB";
int _type = 0;
int _help = 0;
const char* _connect_str = NULL;
struct getargs args[] = {
{ "loops", 'l', arg_integer, &_loops, "loops",
"Number of times to run(default = 1)" },
{ "unqualified", 'u', arg_flag, &_unqualified, "unqualified",
"Use unqualified table names"},
{ "database", 'd', arg_string, &_dbname, "dbname",
"Name of database table is in"},
{ "type", 't', arg_integer, &_type, "type",
"Type of objects to show, see NdbDictionary.hpp for numbers(default = 0)" },
{ "connect-string", 'c', arg_string, &_connect_str,
"Set connect string for connecting to ndb_mgmd. <constr>=\"host=<hostname:port>[;nodeid=<id>]\". Overides specifying entries in NDB_CONNECTSTRING and config file",
"<constr>" },
#ifndef DBUG_OFF
{ "debug", 0, arg_string, &debug_option,
"Specify debug options e.g. d:t:i:o,out.trace", "options" },
#endif
{ "usage", '?', arg_flag, &_help, "Print help", "" }
};
int num_args = sizeof(args) / sizeof(args[0]);
int optind = 0;
static const char* opt_connect_str= 0;
static const char* _dbname = "TEST_DB";
static int _loops;
static int _type;
static struct my_option my_long_options[] =
{
NDB_STD_OPTS("ndb_desc"),
{ "database", 'd', "Name of database table is in",
(gptr*) &_dbname, (gptr*) &_dbname, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ "loops", 'l', "loops",
(gptr*) &_loops, (gptr*) &_loops, 0,
GET_INT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0 },
{ "type", 't', "type",
(gptr*) &_type, (gptr*) &_type, 0,
GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ "unqualified", 'u', "Use unqualified table names",
(gptr*) &_unqualified, (gptr*) &_unqualified, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
static void print_version()
{
printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
ndbPrintVersion();
}
static void usage()
{
char desc[] =
"tabname\n"\
"This program list all system objects in NDB Cluster.\n"\
......@@ -201,19 +196,42 @@ int main(int argc, const char** argv){
" ex: list_tables -t 2 would show all UserTables\n"\
"To show all indexes for a table write table name as final argument\n"\
" ex: list_tables T1\n";
if(getarg(args, num_args, argc, argv, &optind) || _help) {
arg_printusage(args, num_args, argv[0], desc);
print_version();
my_print_help(my_long_options);
my_print_variables(my_long_options);
}
static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
switch (optid) {
case '#':
DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_show_tables.trace");
break;
case 'V':
print_version();
exit(0);
case '?':
usage();
exit(0);
}
return 0;
}
int main(int argc, char** argv){
NDB_INIT(argv[0]);
const char* _tabname;
const char *load_default_groups[]= { "ndb_tools",0 };
load_defaults("my",load_default_groups,&argc,&argv);
int ho_error;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
return NDBT_ProgramExit(NDBT_WRONGARGS);
if ((_tabname = argv[0]) == 0) {
usage();
return NDBT_ProgramExit(NDBT_WRONGARGS);
}
_tabname = argv[optind];
#ifndef DBUG_OFF
if (debug_option)
DBUG_PUSH(debug_option);
#endif
ndb_cluster_connection = new Ndb_cluster_connection(_connect_str);
ndb_cluster_connection = new Ndb_cluster_connection(opt_connect_str);
ndb = new Ndb(ndb_cluster_connection, _dbname);
if (ndb->init() != 0)
fatal("init");
......
......@@ -16,6 +16,7 @@
#include <ndb_global.h>
#include <ndb_opts.h>
#include <NdbOut.hpp>
......@@ -23,13 +24,8 @@
#include <NdbMain.h>
#include <NDBT.hpp>
#include <NdbSleep.h>
#include <getarg.h>
#include <NdbScanFilter.hpp>
#ifndef DBUG_OFF
const char *debug_option= 0;
#endif
int scanReadRecords(Ndb*,
const NdbDictionary::Table*,
const NdbDictionary::Index*,
......@@ -40,39 +36,44 @@ int scanReadRecords(Ndb*,
char delim,
bool orderby);
int main(int argc, const char** argv){
ndb_init();
int _parallelism = 240;
const char* _delimiter = "\t";
int _header = true;
int _useHexFormat = false;
const char* _tabname = NULL;
const char* _dbname = "TEST_DB";
int _help = 0;
int _lock = 0;
int _order = 0;
struct getargs args[] = {
{ "database", 'd', arg_string, &_dbname, "dbname",
"Name of database table is in"},
{ "parallelism", 'p', arg_integer, &_parallelism, "parallelism",
"parallelism" },
{ "header", 'h', arg_flag, &_header, "Print header", "header" },
{ "useHexFormat", 'x', arg_flag, &_useHexFormat,
"Output numbers in hexadecimal format", "useHexFormat" },
{ "delimiter", 'd', arg_string, &_delimiter, "Column delimiter",
"delimiter" },
#ifndef DBUG_OFF
{ "debug", 0, arg_string, &debug_option,
"Specify debug options e.g. d:t:i:o,out.trace", "options" },
#endif
{ "usage", '?', arg_flag, &_help, "Print help", "" },
{ "lock", 'l', arg_integer, &_lock,
"Read(0), Read-hold(1), Exclusive(2)", "lock"},
{ "order", 'o', arg_flag, &_order, "Sort resultset according to index", ""}
};
int num_args = sizeof(args) / sizeof(args[0]);
int optind = 0;
static const char* opt_connect_str= 0;
static const char* _dbname = "TEST_DB";
static const char* _delimiter = "\t";
static int _unqualified, _header, _parallelism, _useHexFormat, _lock,
_order;
static struct my_option my_long_options[] =
{
NDB_STD_OPTS("ndb_desc"),
{ "database", 'd', "Name of database table is in",
(gptr*) &_dbname, (gptr*) &_dbname, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ "parallelism", 'p', "parallelism",
(gptr*) &_parallelism, (gptr*) &_parallelism, 0,
GET_INT, REQUIRED_ARG, 240, 0, 0, 0, 0, 0 },
{ "lock", 'l', "Read(0), Read-hold(1), Exclusive(2)",
(gptr*) &_lock, (gptr*) &_lock, 0,
GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ "order", 'o', "Sort resultset according to index",
(gptr*) &_order, (gptr*) &_order, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "header", 'h', "Print header",
(gptr*) &_header, (gptr*) &_header, 0,
GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0 },
{ "useHexFormat", 'x', "Output numbers in hexadecimal format",
(gptr*) &_useHexFormat, (gptr*) &_useHexFormat, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "delimiter", 'D', "Column delimiter",
(gptr*) &_delimiter, (gptr*) &_delimiter, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
static void print_version()
{
printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
}
static void usage()
{
char desc[] =
"tabname\n"\
"This program reads all records from one table in NDB Cluster\n"\
......@@ -80,19 +81,42 @@ int main(int argc, const char** argv){
"(It only print error messages if it encounters a permanent error.)\n"\
"It can also be used to dump the content of a table to file \n"\
" ex: select_all --no-header --delimiter=';' T4 > T4.data\n";
if(getarg(args, num_args, argc, argv, &optind) ||
argv[optind] == NULL || _help) {
arg_printusage(args, num_args, argv[0], desc);
return NDBT_ProgramExit(NDBT_WRONGARGS);
print_version();
my_print_help(my_long_options);
my_print_variables(my_long_options);
}
static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
switch (optid) {
case '#':
DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_select_all.trace");
break;
case 'V':
print_version();
exit(0);
case '?':
usage();
exit(0);
}
_tabname = argv[optind];
return 0;
}
#ifndef DBUG_OFF
if (debug_option)
DBUG_PUSH(debug_option);
#endif
int main(int argc, char** argv){
NDB_INIT(argv[0]);
const char *load_default_groups[]= { "ndb_tools",0 };
load_defaults("my",load_default_groups,&argc,&argv);
const char* _tabname;
int ho_error;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
return NDBT_ProgramExit(NDBT_WRONGARGS);
if ((_tabname = argv[0]) == 0) {
usage();
return NDBT_ProgramExit(NDBT_WRONGARGS);
}
Ndb::setConnectString(opt_connect_str);
// Connect to Ndb
Ndb MyNdb(_dbname);
......@@ -108,8 +132,8 @@ int main(int argc, const char** argv){
// Check if table exists in db
const NdbDictionary::Table* pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
const NdbDictionary::Index * pIdx = 0;
if(optind+1 < argc){
pIdx = MyNdb.getDictionary()->getIndex(argv[optind+1], _tabname);
if(argc > 1){
pIdx = MyNdb.getDictionary()->getIndex(argv[0], _tabname);
}
if(pTab == NULL){
......
......@@ -16,6 +16,7 @@
#include <ndb_global.h>
#include <ndb_opts.h>
#include <NdbOut.hpp>
......@@ -23,7 +24,6 @@
#include <NdbMain.h>
#include <NDBT.hpp>
#include <NdbSleep.h>
#include <getarg.h>
#include <UtilTransactions.hpp>
static int
......@@ -32,34 +32,68 @@ select_count(Ndb* pNdb, const NdbDictionary::Table* pTab,
int* count_rows,
UtilTransactions::ScanLock lock);
int main(int argc, const char** argv){
ndb_init();
const char* _dbname = "TEST_DB";
int _parallelism = 240;
int _help = 0;
int _lock = 0;
struct getargs args[] = {
{ "database", 'd', arg_string, &_dbname, "dbname",
"Name of database table is in"},
{ "parallelism", 's', arg_integer, &_parallelism, "parallelism", "parallelism" },
{ "usage", '?', arg_flag, &_help, "Print help", "" },
{ "lock", 'l', arg_integer, &_lock,
"Read(0), Read-hold(1), Exclusive(2)", "lock"}
};
int num_args = sizeof(args) / sizeof(args[0]);
int optind = 0;
static const char* opt_connect_str= 0;
static const char* _dbname = "TEST_DB";
static int _parallelism = 240;
static int _lock = 0;
static struct my_option my_long_options[] =
{
NDB_STD_OPTS("ndb_desc"),
{ "database", 'd', "Name of database table is in",
(gptr*) &_dbname, (gptr*) &_dbname, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ "parallelism", 'p', "parallelism",
(gptr*) &_parallelism, (gptr*) &_parallelism, 0,
GET_INT, REQUIRED_ARG, 240, 0, 0, 0, 0, 0 },
{ "lock", 'l', "Read(0), Read-hold(1), Exclusive(2)",
(gptr*) &_lock, (gptr*) &_lock, 0,
GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
static void print_version()
{
printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
}
static void usage()
{
char desc[] =
"tabname1 ... tabnameN\n"\
"This program will count the number of records in tables\n";
if(getarg(args, num_args, argc, argv, &optind) ||
argv[optind] == NULL || _help) {
arg_printusage(args, num_args, argv[0], desc);
print_version();
my_print_help(my_long_options);
my_print_variables(my_long_options);
}
static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
switch (optid) {
case '#':
DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_select_count.trace");
break;
case 'V':
print_version();
exit(0);
case '?':
usage();
exit(0);
}
return 0;
}
int main(int argc, char** argv){
NDB_INIT(argv[0]);
const char *load_default_groups[]= { "ndb_tools",0 };
load_defaults("my",load_default_groups,&argc,&argv);
int ho_error;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
return NDBT_ProgramExit(NDBT_WRONGARGS);
if (argc < 1) {
usage();
return NDBT_ProgramExit(NDBT_WRONGARGS);
}
Ndb::setConnectString(opt_connect_str);
// Connect to Ndb
Ndb MyNdb(_dbname);
......@@ -72,7 +106,7 @@ int main(int argc, const char** argv){
while(MyNdb.waitUntilReady() != 0)
ndbout << "Waiting for ndb to become ready..." << endl;
for(int i = optind; i<argc; i++){
for(int i = 0; i<argc; i++){
// Check if table exists in db
const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, argv[i]);
if(pTab == NULL){
......
......@@ -16,11 +16,12 @@
#include <ndb_global.h>
#include <ndb_opts.h>
#include <mgmapi.h>
#include <NdbMain.h>
#include <NdbOut.hpp>
#include <NdbSleep.h>
#include <getarg.h>
#include <kernel/ndb_limits.h>
#include "../include/mgmcommon/LocalConfig.hpp"
......@@ -29,34 +30,60 @@
int
waitClusterStatus(const char* _addr, ndb_mgm_node_status _status, unsigned int _timeout);
int main(int argc, const char** argv){
ndb_init();
static const char* opt_connect_str= 0;
static int _no_contact = 0;
static int _timeout = 120;
static struct my_option my_long_options[] =
{
NDB_STD_OPTS("ndb_desc"),
{ "no-contact", 'n', "Wait for cluster no contact",
(gptr*) &_no_contact, (gptr*) &_no_contact, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "timeout", 't', "Timeout to wait",
(gptr*) &_timeout, (gptr*) &_timeout, 0,
GET_INT, REQUIRED_ARG, 120, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
static void print_version()
{
printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
ndbPrintVersion();
}
static void usage()
{
print_version();
my_print_help(my_long_options);
my_print_variables(my_long_options);
}
static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
switch (optid) {
case '#':
DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_drop_table.trace");
break;
case 'V':
print_version();
exit(0);
case '?':
usage();
exit(0);
}
return 0;
}
int main(int argc, char** argv){
NDB_INIT(argv[0]);
const char *load_default_groups[]= { "ndb_tools",0 };
load_defaults("my",load_default_groups,&argc,&argv);
const char* _hostName = NULL;
int _no_contact = 0;
int _help = 0;
int _timeout = 120;
struct getargs args[] = {
{ "timeout", 0, arg_integer, &_timeout, "Timeout to wait", "#" },
{ "no-contact", 0, arg_flag, &_no_contact, "Wait for cluster no contact", "" },
{ "usage", '?', arg_flag, &_help, "Print help", "" }
};
int num_args = sizeof(args) / sizeof(args[0]);
int optind = 0;
char desc[] =
"hostname:port\n"\
"This program will connect to the mgmsrv of a NDB cluster.\n"\
"It will then wait for all nodes to be started\n";
if(getarg(args, num_args, argc, argv, &optind) || _help) {
arg_printusage(args, num_args, argv[0], desc);
int ho_error;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
return NDBT_ProgramExit(NDBT_WRONGARGS);
}
char buf[255];
_hostName = argv[optind];
_hostName = argv[0];
if (_hostName == NULL){
LocalConfig lcfg;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment