-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathreorg_tab.cpp
More file actions
115 lines (88 loc) · 3.2 KB
/
Copy pathreorg_tab.cpp
File metadata and controls
115 lines (88 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* Copyright (C) 2008 MySQL AB, 2009 Sun Microsystems, Inc.
All rights reserved. Use is subject to license terms.
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; version 2 of the License.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
#include <ndb_global.h>
#include <NdbOut.hpp>
#include <NdbApi.hpp>
#include <NDBT.hpp>
#include <getarg.h>
int main(int argc, const char** argv){
ndb_init();
int _help = 0;
int _p = 0;
const char * db = "TEST_DB";
const char* _connectstr = NULL;
struct getargs args[] = {
{ "database", 'd', arg_string, &db, "database", 0 },
{ "connstr", 'c', arg_string, &_connectstr, "Connect string", "cs" },
{ "partitions", 'p', arg_integer, &_p, "New no of partitions", 0},
{ "usage", '?', arg_flag, &_help, "Print help", "" }
};
int num_args = sizeof(args) / sizeof(args[0]);
int optind = 0;
char desc[] =
"tabname\n" \
"This program will alter no of partitions of table in Ndb.\n";
if(getarg(args, num_args, argc, argv, &optind) || _help){
arg_printusage(args, num_args, argv[0], desc);
return NDBT_ProgramExit(NDBT_WRONGARGS);
}
if(argv[optind] == NULL)
{
arg_printusage(args, num_args, argv[0], desc);
return NDBT_ProgramExit(NDBT_WRONGARGS);
}
// Connect to Ndb
Ndb_cluster_connection con(_connectstr);
if(con.connect(12, 5, 1) != 0)
{
return NDBT_ProgramExit(NDBT_FAILED);
}
Ndb MyNdb(&con, db );
if(MyNdb.init() != 0){
ERR(MyNdb.getNdbError());
return NDBT_ProgramExit(NDBT_FAILED);
}
while(MyNdb.waitUntilReady() != 0)
ndbout << "Waiting for ndb to become ready..." << endl;
NdbDictionary::Dictionary* MyDic = MyNdb.getDictionary();
for (int i = optind; i<argc; i++)
{
printf("altering %s/%s...", db, argv[i]);
const NdbDictionary::Table* oldTable = MyDic->getTable(argv[i]);
if (oldTable == 0)
{
ndbout << "Failed to retrieve table " << argv[i]
<< ": " << MyDic->getNdbError() << endl;
return NDBT_ProgramExit(NDBT_FAILED);
}
NdbDictionary::Table newTable = *oldTable;
newTable.setFragmentCount(_p);
if (MyDic->beginSchemaTrans() != 0)
goto err;
if (MyDic->prepareHashMap(*oldTable, newTable) != 0)
goto err;
if (MyDic->alterTable(*oldTable, newTable) != 0)
goto err;
if (MyDic->endSchemaTrans())
goto err;
ndbout_c("done");
}
return NDBT_ProgramExit(NDBT_OK);
err:
NdbError err = MyDic->getNdbError();
if (MyDic->hasSchemaTrans())
MyDic->endSchemaTrans(NdbDictionary::Dictionary::SchemaTransAbort);
ndbout << "Failed! "
<< err << endl;
return NDBT_ProgramExit(NDBT_FAILED);
}