/
mcsadmin.cpp
8994 lines (7972 loc) · 274 KB
/
mcsadmin.cpp
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2016 MariaDB Corporation
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. */
/******************************************************************************************
* $Id: mcsadmin.cpp 3110 2013-06-20 18:09:12Z dhill $
*
******************************************************************************************/
#include <clocale>
#include <netdb.h>
extern int h_errno;
#include "mcsadmin.h"
#include "boost/filesystem/operations.hpp"
#include "boost/filesystem/path.hpp"
#include "boost/scoped_ptr.hpp"
#include "boost/tokenizer.hpp"
#include "sessionmanager.h"
#include "dbrm.h"
#include "messagequeue.h"
#include "we_messages.h"
#include "../../writeengine/redistribute/we_redistributedef.h"
#include "we_config.h" // for findObjectFile
#include "we_fileop.h" // for findObjectFile
namespace fs = boost::filesystem;
using namespace alarmmanager;
using namespace std;
using namespace oam;
using namespace config;
using namespace messageqcpp;
using namespace redistribute;
using namespace execplan;
#include "installdir.h"
// Variables shared in both main and functions
Config* fConfig = 0;
string Section;
int CmdID = 0;
string CmdList[cmdNum];
int CmdListID[cmdNum];
string cmdName;
const string SECTION_NAME = "Cmd";
int serverInstallType;
string systemName;
string parentOAMModule;
string localModule;
bool rootUser = true;
string HOME = "/root";
string SingleServerInstall;
bool repeatStop;
static void checkPromptThread();
bool connectToDBRoot1PM(Oam& oam, boost::scoped_ptr<MessageQueueClient>& msgQueueClient);
bool SendToWES(Oam& oam, ByteStream bs);
bool waitForActive()
{
Oam oam;
SystemStatus systemstatus;
SystemProcessStatus systemprocessstatus;
bool bfirst = true;
for (int i = 0 ; i < 1200 ; i ++)
{
sleep (3);
try
{
oam.getSystemStatus(systemstatus);
if (systemstatus.SystemOpState == ACTIVE)
{
return true;
}
if (systemstatus.SystemOpState == FAILED)
{
return false;
}
if (systemstatus.SystemOpState == MAN_OFFLINE)
{
return false;
}
cout << "." << flush;
// Check DMLProc for a switch to BUSY_INIT.
// In such a case, we need to print a message that rollbacks
// are occurring and will take some time.
if (bfirst) // Once we've printed our message, no need to waste cpu looking
{
oam.getProcessStatus(systemprocessstatus);
for (unsigned int i = 0 ; i < systemprocessstatus.processstatus.size(); i++)
{
if (systemprocessstatus.processstatus[i].ProcessName == "DMLProc")
{
if (systemprocessstatus.processstatus[i].ProcessOpState == oam::ROLLBACK_INIT)
{
cout << endl << endl <<" System Not Ready, DMLProc is checking/processing rollback of abandoned transactions. Processing could take some time, please wait..." << flush;
bfirst = false;
}
// At this point, we've found our DMLProc, so there's no need to spin the for loop
// any further.
break;
}
}
}
}
catch (...)
{
// At some point, we need to give up, ProcMgr just isn't going to respond.
if (i > 60) // 3 minutes
{
cout << "ProcMgr not responding while waiting for system to start";
break;
}
}
}
return false;
}
bool waitForStop()
{
Oam oam;
SystemStatus systemstatus;
SystemProcessStatus systemprocessstatus;
for (int i = 0 ; i < 1200 ; i ++)
{
sleep (3);
try
{
oam.getSystemStatus(systemstatus);
if (systemstatus.SystemOpState == MAN_OFFLINE)
{
return true;
}
if (systemstatus.SystemOpState == FAILED)
{
return false;
}
cout << "." << flush;
}
catch (...)
{
// At some point, we need to give up, ProcMgr just isn't going to respond.
if (i > 60) // 3 minutes
{
cout << "ProcMgr not responding while waiting for system to start";
break;
}
}
}
return false;
}
//------------------------------------------------------------------------------
// Signal handler to catch SIGTERM signal to terminate the process
//------------------------------------------------------------------------------
void handleSigTerm(int i)
{
std::cout << "Received SIGTERM to terminate MariaDB ColumnStore Console..." << std::endl;
}
//------------------------------------------------------------------------------
// Signal handler to catch Control-C signal to terminate the process
//------------------------------------------------------------------------------
void handleControlC(int i)
{
std::cout << "Received Control-C to terminate the console..." << std::endl;
exit(0);
}
//------------------------------------------------------------------------------
// Initialize signal handling
//------------------------------------------------------------------------------
void setupSignalHandlers()
{
#ifdef _MSC_VER
//FIXME
#else
// Control-C signal to terminate a command
struct sigaction act;
memset(&act, 0, sizeof(act));
act.sa_handler = handleControlC;
sigaction(SIGINT, &act, 0);
// catch SIGTERM signal to terminate the program
// memset(&act, 0, sizeof(act));
// act.sa_handler = handleSigTerm;
// sigaction(SIGTERM, &act, 0);
#endif
}
int main(int argc, char *argv[])
{
#ifndef _MSC_VER
setuid(0); // set effective ID to root; ignore return status
#endif
setlocale(LC_ALL, "");
Oam oam;
char* pcommand = 0;
string arguments[ArgNum];
const char* p = getenv("HOME");
if (!p)
p = "";
else
HOME = p;
string ccHistoryFile = HOME + "/.cc_history";
string cf = startup::StartUp::installDir() + "/etc/" + ConsoleCmdsFile;
fConfig = Config::makeConfig(cf);
// setupSignalHandlers();
// Get System Name
try{
oam.getSystemConfig("SystemName", systemName);
}
catch(...)
{
cout << endl << "**** Failed : Failed to read systemName Name" << endl;
exit(-1);
}
//get parentModule Name
parentOAMModule = getParentOAMModule();
// get Local Module Name and Single Server Install Indicator
oamModuleInfo_t st;
try {
st = oam.getModuleInfo();
localModule = boost::get<0>(st);
serverInstallType = boost::get<5>(st);
}
catch (...) {
cout << endl << "**** Failed : Failed to read Local Module Name" << endl;
exit(-1);
}
try {
oam.getSystemConfig("SingleServerInstall", SingleServerInstall);
}
catch(...) {}
//check if root-user
int user;
user = getuid();
if (user != 0)
rootUser = false;
// create/open command log file if not created
logFile.open(DEFAULT_LOG_FILE.c_str(), ios::app);
if (geteuid() == 0 && !logFile)
{
cerr << "UI Command log file cannot be opened" << endl;
}
writeLog("Start of a command session!!!");
// get and sort command list for future help display
for(int i=0; i<cmdNum ;i++)
{
// get cmd name
Section = SECTION_NAME + oam.itoa(i);
cmdName = fConfig->getConfig(Section, "Name");
if (cmdName.empty())
// no command skip
continue;
CmdList[i] = cmdName;
CmdListID[i] = i;
// sort
for(int j=0; j<i ;j++)
{
if( CmdList[i] < CmdList[j] )
{
cmdName = CmdList[i];
CmdList[i] = CmdList[j];
CmdList[j] = cmdName;
CmdID = CmdListID[i];
CmdListID[i] = CmdListID[j];
CmdListID[j] = CmdID;
}
}
}
if ( localModule != parentOAMModule ) {
// issue message informing user they aren't logged into Active OAm Parent
cout << endl;
cout << "WARNING: running on non Parent OAM Module, can't make configuration changes in this session." << endl;
cout << " Access Console from '" << parentOAMModule << "' if you need to make changes." << endl << endl;
}
// check for arguments passed in as a request
if(argc > 1)
{
int j=0;
string command;
for(; argc > 1; j++, argc--)
{
arguments[j] = argv[j+1];
command.append(arguments[j]);
command.append(" ");
}
// add to history and UI command log file
read_history(ccHistoryFile.c_str());
add_history (command.c_str());
writeLog(command.c_str());
write_history(ccHistoryFile.c_str());
checkRepeat(arguments, j);
}
else
{
cout << endl << "MariaDB ColumnStore Admin Console" << endl;
cout << " enter 'help' for list of commands" << endl;
cout << " enter 'exit' to exit the MariaDB ColumnStore Command Console" << endl;
cout << " use up/down arrows to recall commands" << endl << endl;
// output current active alarm stats
printAlarmSummary();
printCriticalAlarms();
//read readline history file
read_history(ccHistoryFile.c_str());
while (true)
{
//get parentModule Name
parentOAMModule = getParentOAMModule();
// flush agument list
for(int j=0; j < ArgNum; j++)
{
arguments[j].clear();
}
// read input
pcommand = readline("mcsadmin> ");
if (!pcommand) // user hit <Ctrl>-D
pcommand = strdup("exit");
else if (!*pcommand)
{
// just an enter-key was entered, ignore and reprompt
continue;
}
// add to history and UI command log file
add_history (pcommand);
writeLog(pcommand);
write_history(ccHistoryFile.c_str());
string command = pcommand;
//check if a argument was entered as a set of char with quotes around them
int commandLoc=0;
int numberArgs=0;
bool validCMD=true;
for(int i=0; i < ArgNum; i++)
{
string::size_type pos = command.find(" ", commandLoc);
string::size_type pos1 = command.find("\"", commandLoc);
string::size_type pos3 = command.find("\'", commandLoc);
if ( (pos == string::npos && pos1 == string::npos) ||
(pos == string::npos && pos3 == string::npos) ) {
//end of the command
string argtemp = command.substr(commandLoc,80);
if ( argtemp != "" ) {
arguments[numberArgs] = argtemp;
numberArgs++;
}
break;
}
if (pos < pos1 && pos < pos3) {
// hit ' ' first
string argtemp = command.substr(commandLoc, pos-commandLoc);
if ( argtemp != "" ) {
arguments[numberArgs] = argtemp;
numberArgs++;
}
commandLoc = pos+1;
}
else
{
if ( pos >= pos1 ) {
//hit " first
string::size_type pos2 = command.find("\"", pos1+1);
if (pos2 != string::npos) {
arguments[numberArgs] = command.substr(pos1+1,pos2-pos1-1);
numberArgs++;
commandLoc = pos2+1;
}
else
{
cout << "Invalid Command, mismatching use of quotes" << endl;
validCMD=false;
break;
}
}
else
{
//hit ' first
string::size_type pos2 = command.find("\'", pos3+1);
if (pos2 != string::npos) {
arguments[numberArgs] = command.substr(pos3+1,pos2-pos3-1);
numberArgs++;
commandLoc = pos2+1;
}
else
{
cout << "Invalid Command, mismatching use of quotes" << endl;
validCMD=false;
break;
}
}
}
}
if (validCMD)
checkRepeat(arguments, numberArgs);
free (pcommand);
}
}
}
void checkRepeat(string* arguments, int argNumber)
{
Oam oam;
bool repeat = false;
int repeatCount = 5;
for ( int i=0; i < argNumber ; i++)
{
if( arguments[i].find("-r") == 0) {
// entered
if ( arguments[i] != "-r") {
//strip report count off
repeatCount = atoi(arguments[i].substr(2,10).c_str());
if ( repeatCount < 1 || repeatCount > 60 ) {
cout << "Failed: incorrect repeat count entered, valid range is 1-60, set to default of 5" << endl;
repeatCount = 5;
}
}
repeat = true;
arguments[i].clear();
cout << "repeating the command '" << arguments[0] << "' every " << repeatCount << " seconds, enter CTRL-D to stop" << endl;
sleep(5);
break;
}
}
bool threadCreate = false;
if (repeat) {
while(true) {
system("clear");
if ( processCommand(arguments) )
return;
else {
if ( !threadCreate ) {
threadCreate = true;
repeatStop = false;
pthread_t PromptThread;
pthread_create (&PromptThread, NULL, (void*(*)(void*)) &checkPromptThread, NULL);
}
for ( int i = 0 ; i < repeatCount ; i ++ )
{
if (repeatStop)
break;
sleep(1);
}
if (repeatStop)
break;
}
}
}
else
processCommand(arguments);
}
int processCommand(string* arguments)
{
Oam oam;
// Possible command line arguments
GRACEFUL_FLAG gracefulTemp = GRACEFUL;
ACK_FLAG ackTemp = ACK_YES;
CC_SUSPEND_ANSWER suspendAnswer = CANCEL;
bool bNeedsConfirm = true;
string password;
string cmd;
// get command info from Command config file
CmdID = -1;
// put inputted command into lowercase
string inputCmd = arguments[0];
transform (inputCmd.begin(), inputCmd.end(), inputCmd.begin(), to_lower());
for (int i = 0; i < cmdNum; i++)
{
// put table command into lowercase
string cmdName_LC = CmdList[i];
transform (cmdName_LC.begin(), cmdName_LC.end(), cmdName_LC.begin(), to_lower());
if (cmdName_LC.find(inputCmd) == 0)
{
// command found, ECHO command
cout << cmdName_LC << " " << oam.getCurrentTime() << endl;
CmdID = CmdListID[i];
break;
}
}
if (CmdID == -1)
{
// get is command in the Support Command list
for (int i = 0;;i++)
{
if (supportCmds[i] == "")
// end of list
break;
if (supportCmds[i].find(inputCmd) == 0) {
// match found, go process it
cout << supportCmds[i] << " " << oam.getCurrentTime() << endl;
int status = ProcessSupportCommand(i, arguments);
if ( status == -1 )
// didn't process it for some reason
break;
return 1;
}
}
// command not valid
cout << arguments[0] << ": Unknown Command, type help for list of commands" << endl << endl;
return 1;
}
switch( CmdID )
{
case 0: // help
case 1: // ?
{
const string DESC_NAME = "Desc";
string desc;
string descName;
const string ARG_NAME = "Arg";
string arg;
string argName;
string argument1_LC = arguments[1];
transform (argument1_LC.begin(), argument1_LC.end(), argument1_LC.begin(), to_lower());
if (argument1_LC.find("-a") == 0 || argument1_LC == "")
{
// list commands and brief description (Desc1)
cout << endl << "List of commands:" << endl;
cout << "Note: the command must be the first entry entered on the command line" << endl << endl;
cout.setf(ios::left);
cout.width(34);
cout << "Command" << "Description" << endl;
cout.setf(ios::left);
cout.width(34);
cout << "------------------------------" << "--------------------------------------------------------" << endl;
for(int i=0; i<cmdNum ;i++)
{
// get cmd name
Section = SECTION_NAME + oam.itoa(CmdListID[i]);
cmdName = fConfig->getConfig(Section, "Name");
if (cmdName.empty() || cmdName == "AVAILABLE")
// no command skip
continue;
cout.setf(ios::left);
cout.width(34);
cout << cmdName << fConfig->getConfig(Section, "Desc1") << endl;
}
cout << endl << "For help on a command, enter 'help' followed by command name" << endl;
}
else
{
if (argument1_LC.find("-v") == 0)
{
// list of commands with their descriptions
cout << endl << "List of commands and descriptions:" << endl << endl;
for(int k=0 ; k < cmdNum ; k++)
{
Section = SECTION_NAME + oam.itoa(CmdListID[k]);
cmdName = fConfig->getConfig(Section, "Name");
if (cmdName.empty() || cmdName == "AVAILABLE")
//no command skip
continue;
cout << "Command: " << cmdName << endl << endl;
int i=2;
cout << " Description: " << fConfig->getConfig(Section, "Desc1") << endl;
while (true)
{
desc = DESC_NAME + oam.itoa(i);
descName = fConfig->getConfig(Section, desc);
if (descName.empty())
//end of Desc list
break;
cout << " " << descName << endl;
i++;
}
i=2;
cout << endl << " Arguments: " << fConfig->getConfig(Section, "Arg1") << endl;
while (true)
{
arg = ARG_NAME + oam.itoa(i);
argName = fConfig->getConfig(Section, arg);
if (argName.empty())
//end of arg list
break;
cout << " " << argName << endl;
i++;
}
cout << endl;
}
}
else
{ // description for a single command
int j=0;
for (j = 0; j < cmdNum; j++)
{
// get cmd description
Section = SECTION_NAME + oam.itoa(j);
cmdName = fConfig->getConfig(Section, "Name");
string cmdName_LC = cmdName;
transform (cmdName_LC.begin(), cmdName_LC.end(), cmdName_LC.begin(), to_lower());
if (cmdName_LC == argument1_LC)
{
// command found, output description
cout << endl << " Command: " << cmdName << endl << endl;
int i=2;
cout << " Description: " << fConfig->getConfig(Section, "Desc1") << endl;
while (true)
{
desc = DESC_NAME + oam.itoa(i);
descName = fConfig->getConfig(Section, desc);
if (descName.empty())
//end of Desc list
break;
cout << " " << descName << endl;
i++;
}
i=2;
cout << endl << " Arguments: " << fConfig->getConfig(Section, "Arg1") << endl;
while (true)
{
arg = ARG_NAME + oam.itoa(i);
argName = fConfig->getConfig(Section, arg);
if (argName.empty())
//end of arg list
break;
cout << " " << argName << endl;
i++;
}
break;
}
}
if (j == cmdNum)
{
// command not valid
cout << arguments[1] << ": Unknown Command, type help for list of commands" << endl << endl;
break;
}
}
}
cout << endl;
}
break;
case 2: // exit
case 3: // quit
{
// close the log file
writeLog("End of a command session!!!");
logFile.close();
cout << "Exiting the MariaDB ColumnStore Admin Console" << endl;
exit (0);
}
break;
case 4: // redistributeData
{
set<uint32_t> removeDbroots; // set of dbroots we want to leave empty
vector<uint32_t> srcDbroots; // all of the currently configured dbroots
vector<uint32_t> destDbroots; // srcDbroots - removeDbroots
set<int>::iterator dbiter;
if (arguments[1] == "start")
{
// Get a list of all the configured dbroots in the xml file.
DBRootConfigList dbRootConfigList;
std::set<int> configuredDBRoots;
oam.getSystemDbrootConfig(dbRootConfigList);
for (DBRootConfigList::iterator i = dbRootConfigList.begin(); i != dbRootConfigList.end(); ++i)
configuredDBRoots.insert(*i);
// The user may choose to redistribute in such a way as to
// leave certain dbroots empty, presumably for later removal.
if (arguments[2] == "remove")
{
int dbroot;
bool error = false;
for (int i=3; arguments[i] != ""; ++i)
{
dbroot = atoi(arguments[i].c_str());
if (dbroot == 1)
{
cout << "Not allowed to remove dbroot-1" << endl;
error = true;
}
else
{
if (configuredDBRoots.find(dbroot) == configuredDBRoots.end())
{
ostringstream oss;
cout << "DBRoot-" << dbroot << " is not configured" << endl;
error = true;
}
else
{
removeDbroots.insert((uint32_t)dbroot);
}
}
}
if (error)
{
cout << "Errors encountered. Abort" << endl;
break;
}
}
// Create a list of source dbroots -- where the data currently resides.
for (dbiter = configuredDBRoots.begin(); dbiter != configuredDBRoots.end(); ++dbiter)
srcDbroots.push_back((uint32_t)*dbiter);
// Create a list of destination dbroots -- where the data is to go.
for (dbiter = configuredDBRoots.begin(); dbiter != configuredDBRoots.end(); ++dbiter)
{
// Only use the dbroots not in the remove list
if (removeDbroots.find((uint32_t)*dbiter) == removeDbroots.end())
{
destDbroots.push_back((uint32_t)*dbiter);
}
}
// Print out what we're about to do
cout << "redistributeData START ";
if (removeDbroots.size() > 0)
{
cout << " Removing dbroots:";
set<uint32_t>::iterator iter;
for (iter = removeDbroots.begin(); iter != removeDbroots.end(); ++iter)
{
cout << " " << *iter;
}
}
cout << endl;
cout << "Source dbroots:";
vector<uint32_t>::iterator iter;
for (iter = srcDbroots.begin(); iter != srcDbroots.end(); ++iter)
cout << " " << *iter;
cout << endl << "Destination dbroots:";
for (iter = destDbroots.begin(); iter != destDbroots.end(); ++iter)
cout << " " << *iter;
cout << endl << endl;
// Connect to PM for dbroot1
ByteStream bs;
// message WES ID, sequence #, action id
uint32_t sequence = time(0);
bs << (ByteStream::byte) WriteEngine::WE_SVR_REDISTRIBUTE;
// Send the CLEAR message to WriteEngineServer (WES). Wipes out previous state.
RedistributeMsgHeader header(0, 0, sequence, RED_CNTL_CLEAR);
bs.append((const ByteStream::byte*) &header, sizeof(header));
SendToWES(oam, bs);
// Send the START message
bs.restart();
sequence = time(0);
bs << (ByteStream::byte) WriteEngine::WE_SVR_REDISTRIBUTE;
header.sequenceNum=sequence;
header.messageId = RED_CNTL_START;
bs.append((const ByteStream::byte*) &header, sizeof(header));
uint32_t options = 0;
if (removeDbroots.size() > 0)
{
options |= RED_OPTN_REMOVE;
}
bs << options;
// source db roots,
bs << (uint32_t) srcDbroots.size();
for (uint64_t i = 0; i < srcDbroots.size(); ++i)
bs << (uint32_t) srcDbroots[i];
// destination db roots,
bs << (uint32_t) destDbroots.size();
for (uint64_t i = 0; i < destDbroots.size(); ++i)
bs << (uint32_t) destDbroots[i];
SendToWES(oam, bs);
}
else if (arguments[1] == "stop")
{
ByteStream bs;
// message WES ID, sequence #, action id
uint32_t sequence = time(0);
bs << (ByteStream::byte) WriteEngine::WE_SVR_REDISTRIBUTE;
RedistributeMsgHeader header(0, 0, sequence, RED_CNTL_STOP);
bs.append((const ByteStream::byte*) &header, sizeof(header));
SendToWES(oam, bs);
}
else if (arguments[1] == "status")
{
ByteStream bs;
// message WES ID, sequence #, action id
uint32_t sequence = time(0);
bs << (ByteStream::byte) WriteEngine::WE_SVR_REDISTRIBUTE;
RedistributeMsgHeader header(0, 0, sequence, RED_CNTL_STATUS);
bs.append((const ByteStream::byte*) &header, sizeof(header));
SendToWES(oam, bs);
}
else
{
cout << "redistributeData must have one of START, STOP or STATUS" << endl;
}
}
break;
case 5: // findObjectFile
{
unsigned maxDBRoot = WriteEngine::Config::DBRootCount();
if (maxDBRoot < 1)
{
cout << endl << "findobjectfile fails because there are no dbroots defined for this server" << endl;
break;;
}
if (arguments[1] == "")
{
cout << endl << "findobjectfile requires one of" << endl;
cout << "a) oid of column for which file name is to be retrieved" << endl;
cout << "b) schema, table and column for which the file name is to be retrieved" << endl;
cout << "c) oid of table for which the file name of each column is to be retrieved" << endl;
cout << "d) schema and table for which the file name of each column is to be retrieved" << endl;
break;
}
char* endchar;
int oid = 0;
int tableOid = 0; // If a table report
int dictOid = 0; // If a dictionary oid was given
std::vector<int> columnOids;
CalpontSystemCatalog::TableName tableName;
CalpontSystemCatalog::TableColName columnName;
boost::shared_ptr<execplan::CalpontSystemCatalog> systemCatalogPtr =
execplan::CalpontSystemCatalog::makeCalpontSystemCatalog(0);
systemCatalogPtr->identity(execplan::CalpontSystemCatalog::FE);
// Try to get a numeric oid from the argument
oid = strtol(arguments[1].c_str(), &endchar, 0);
// test to see if not all numeric
if (endchar < &(*arguments[1].end())) // endchar from above will not point to the end if not numeric
{
oid = 0;
}
if (oid == 0) // A table or column name was entered
{
// Need to convert the arguments to oid
columnName.schema = arguments[1];
if (arguments[2] == "")
{
cout << endl << "findobjectfile requires a table for schema " << arguments[1] << endl;
break;
}
columnName.table = arguments[2];
if (arguments[3] == "")
{
// No column was given. Get the list of column oids for the table.
tableName.schema = arguments[1];
tableName.table = arguments[2];
try
{
tableOid = systemCatalogPtr->lookupTableOID(tableName);
if (tableOid)
{
CalpontSystemCatalog::RIDList rdlist = systemCatalogPtr->columnRIDs(tableName);
for (unsigned int i = 0; i < rdlist.size(); ++i)
{
columnOids.push_back(rdlist[i].objnum);
}
}
else
{
cout << arguments[1] << "." << arguments[2] << " is not a columnstore table" << endl;
break;
}
}
catch ( runtime_error& e )
{
cout << "error while trying to get the columns for " << tableName.schema << "." << tableName.table << ": " << e.what() << endl;
break;
}
catch (...)
{
cout << "error while trying to get the columns for " << tableName.schema << "." << tableName.table << endl;
break;
}
}
else // A column name was given
{
columnName.column = arguments[3];
oid = systemCatalogPtr->lookupOID(columnName);
if (oid < 1)
{
cout << arguments[1] << "." << arguments[2] << "." << arguments[3] << " is not a columnstore column" << endl;
break;
}
columnOids.push_back(oid);
}
}
else // An oid was given
{
try
{
// Is oid a column?
columnName = systemCatalogPtr->colName(oid);
}
catch (...){ /* Ignore */ }
if (columnName.schema.size() == 0 || columnName.table.size() == 0 || columnName.column.size() == 0)
{
// Not a column OID
// check to see if it's a dictionary oid.
try
{
columnName = systemCatalogPtr->dictColName(oid);
}
catch (...){ /* Ignore */ }
if (columnName.schema.size() == 0 || columnName.table.size() == 0 || columnName.column.size() == 0)
{
// Not a dictionary oid
// Check to see if a table oid was given. If so, get the column oid list.
try
{
tableName = systemCatalogPtr->tableName(oid);
}
catch (...){ /* Ignore */ }
if (tableName.schema.size() == 0 || tableName.table.size() == 0)
{
// Not a table or a column OID.
cout << "OID " << oid << " does not represent a table or column in columnstore" << endl;
break;
}
tableOid = oid;
try
{
CalpontSystemCatalog::RIDList rdlist = systemCatalogPtr->columnRIDs(tableName);
for (unsigned int i = 0; i < rdlist.size(); ++i)
{
columnOids.push_back(rdlist[i].objnum);
}
}