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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
|
/*-------------------------------------------------------------------------
*
* do_command.c
*
* Main command module of Postgres-XC configuration and operation tool.
*
* Copyright (c) 2013 Postgres-XC Development Group
*
*-------------------------------------------------------------------------
*/
/*
* This file provides a frontend module to pgxc_ctl operation.
*/
#include <stdio.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <setjmp.h>
#include <string.h>
#include <readline/readline.h>
#include <readline/history.h>
#include "pgxc_ctl.h"
#include "do_command.h"
#include "variables.h"
#include "varnames.h"
#include "pgxc_ctl_log.h"
#include "config.h"
#include "do_shell.h"
#include "utils.h"
#include "gtm_cmd.h"
#include "coord_cmd.h"
#include "datanode_cmd.h"
#include "gtm_util.h"
#include "monitor.h"
extern char *pgxc_ctl_conf_prototype[];
extern char *pgxc_ctl_conf_prototype_minimal[];
extern char *pgxc_ctl_conf_prototype_empty[];
int forceInit = false;
#define Exit(c) exit(myWEXITSTATUS(c))
#define GetToken() (line = get_word(line, &token))
#define TestToken(word) ((token != NULL) && (strcasecmp(token, word) == 0))
#define testToken(word) ((token != NULL) && (strcmp(token, word) == 0))
static void kill_something(char *token);
static void do_deploy(char *line);
static void deploy_xc(char **hostlist);
static void show_config_something(char *nodeName);
static void show_config_something_multi(char **nodeList);
extern void show_config_hostList(char **hostList);
static void show_config_host(char *hostname);
static void show_basicConfig(void);
static void show_config_servers(char **hostList);
static void do_clean_command(char *line);
static void do_start_command(char *line);
static void start_all(void);
static void do_stop_command(char *line);
static void stop_all(char *immediate);
static int show_Resource(char *datanodeName, char *databasename, char *username);
static void do_show_help(char *line);
typedef enum ConfigType
{
CONFIG_EMPTY,
CONFIG_MINIMAL,
CONFIG_COMPLETE
} ConfigType;
static void do_echo_command(char * line)
{
printf("do_echo_command\n");
}
static void do_prepareConfFile(char *Path, ConfigType config_type)
{
char *path = NULL;
FILE *conf;
int ii;
char **my_pgxc_conf_prototype;
if (Path)
path = Path;
else
{
if (find_var(VAR_configFile) && sval(VAR_configFile))
path = sval(VAR_configFile);
else
{
elog(ERROR, "ERROR: Configuration file path was not specified.\n");
return;
}
}
conf = fopen(path, "w");
if (conf == NULL)
{
elog(ERROR, "ERROR: Could not open the configuration file \"%s\", %s.\n", path, strerror(errno));
return;
}
if (config_type == CONFIG_EMPTY)
my_pgxc_conf_prototype = pgxc_ctl_conf_prototype_empty;
else if (config_type == CONFIG_MINIMAL)
my_pgxc_conf_prototype = pgxc_ctl_conf_prototype_minimal;
else
my_pgxc_conf_prototype = pgxc_ctl_conf_prototype;
for (ii = 0; my_pgxc_conf_prototype[ii]; ii++)
{
fprintf(conf, "%s\n", my_pgxc_conf_prototype[ii]);
}
fclose(conf);
return;
}
/*
* Deploy pgxc binaries
*/
static void do_deploy(char *line)
{
char *token;
char **hostlist = NULL;
if (GetToken() == NULL)
{
elog(ERROR, "ERROR: Please specify option for deploy command.\n");
return;
}
if (TestToken("all"))
{
elog(NOTICE, "Deploying Postgres-XL components to all the target servers.\n");
deploy_xc(aval(VAR_allServers));
}
else
{
elog(NOTICE, "Deploying Postgres-XL components.\n");
/*
* Please note that the following code does not check if the specified nost
* appears in the configuration file.
* We should deploy xc binary to the target not in the current configuraiton
* to add gtm slave, gtm_proxy, coordinator/datanode master/slave online.
*/
do {
AddMember(hostlist, token);
} while(GetToken());
deploy_xc(hostlist);
CleanArray(hostlist);
}
}
static void deploy_xc(char **hostlist)
{
char tarFile[MAXPATH+1];
cmdList_t *cmdList;
int ii;
/* Build tarball --> need to do foreground */
elog(NOTICE, "Prepare tarball to deploy ... \n");
snprintf(tarFile, MAXPATH, "%d.tgz", getpid());
doImmediate(NULL, NULL, "tar czCf %s %s/%s bin include lib share",
sval(VAR_pgxcInstallDir),
sval(VAR_localTmpDir), tarFile);
/* Backgroud jobs */
cmdList = initCmdList();
/* Build install dir */
for (ii = 0; hostlist[ii]; ii++)
{
cmd_t *cmd;
cmd_t *cmdScp;
cmd_t *cmdTarExtract;
elog(NOTICE, "Deploying to the server %s.\n", hostlist[ii]);
/* Build target directory */
addCmd(cmdList, (cmd = initCmd(hostlist[ii])));
snprintf(newCommand(cmd), MAXLINE,
"rm -rf %s/bin %s/include %s/lib %s/share; mkdir -p %s",
sval(VAR_pgxcInstallDir),
sval(VAR_pgxcInstallDir),
sval(VAR_pgxcInstallDir),
sval(VAR_pgxcInstallDir),
sval(VAR_pgxcInstallDir));
/* SCP tarball */
appendCmdEl(cmd, (cmdScp = initCmd(NULL)));
snprintf(newCommand(cmdScp), MAXLINE,
"scp %s/%s %s@%s:%s",
sval(VAR_localTmpDir), tarFile, sval(VAR_pgxcUser), hostlist[ii], sval(VAR_tmpDir));
/* Extract Tarball and remove it */
appendCmdEl(cmd, (cmdTarExtract = initCmd(hostlist[ii])));
snprintf(newCommand(cmdTarExtract), MAXLINE,
"tar xzCf %s %s/%s; rm %s/%s",
sval(VAR_pgxcInstallDir),
sval(VAR_tmpDir), tarFile,
sval(VAR_tmpDir), tarFile);
}
doCmdList(cmdList);
cleanCmdList(cmdList);
doImmediate(NULL, NULL, "rm -f %s/%s",
sval(VAR_tmpDir), tarFile);
elog(NOTICE, "Deployment done.\n");
}
static void do_set(char *line)
{
char *token;
char *varname;
pgxc_ctl_var *var;
if (GetToken() == NULL)
{
elog(ERROR, "ERROR: No variable name was given\n");
return;
}
varname = Strdup(token);
var = confirm_var(varname);
reset_value(var);
while(GetToken())
{
add_val(var, token);
}
print_var(varname);
log_var(varname);
return;
}
/*
* Failover command ... failover gtm
* failover coordinator nodename
* failover datanode nodename
* failover nodename
*/
static void do_failover_command(char *line)
{
char *token;
int idx;
if (GetToken() == NULL)
{
elog(ERROR, "ERROR: Please specify failover command option.\n");
return;
}
else if (TestToken("gtm"))
{
if (isVarYes(VAR_gtmSlave) && !is_none(sval(VAR_gtmSlaveServer)))
failover_gtm();
else
elog(ERROR, "ERROR: no gtm slave is configured.\n");
return;
}
else if (TestToken("coordinator"))
{
if (!isVarYes(VAR_coordSlave))
elog(ERROR, "ERROR: coordinator slave is not configured.\n");
else if (!GetToken())
elog(ERROR, "ERROR: please specify failover coordinator command option.\n");
else
{
char **nodeList = NULL;
do
{
if ((idx = coordIdx(token)) < 0)
elog(ERROR, "ERROR: %s is not a coordinator\n", token);
else if (is_none(aval(VAR_coordSlaveServers)[idx]))
elog(ERROR, "ERROR: slave for the coordinator %s is not configured.\n", token);
else
AddMember(nodeList, token);
} while(GetToken());
if (nodeList)
failover_coordinator(nodeList);
CleanArray(nodeList);
}
return;
}
else if (TestToken("datanode"))
{
if (!isVarYes(VAR_datanodeSlave))
elog(ERROR, "ERROR: datanode slave is not configured.\n");
else if (!GetToken())
elog(ERROR, "ERROR: please specify failover datanode command option.\n");
else
{
char **nodeList = NULL;
do
{
if ((idx = datanodeIdx(token)) < 0)
elog(ERROR, "ERROR: %s is not a datanode.\n", token);
else if (is_none(aval(VAR_datanodeSlaveServers)[idx]))
elog(ERROR, "ERROR: slave for the datanode %s is not configured,\n", token);
else
AddMember(nodeList, token);
} while(GetToken());
if (nodeList)
failover_datanode(nodeList);
CleanArray(nodeList);
}
}
else
elog(ERROR, "ERROR: invalid failover command option %s.\n", token);
}
/*
* Reconnect command ... reconnect gtm_proxy [all | nodename ... ]
*/
static void do_reconnect_command(char *line)
{
char *token;
if (GetToken() == NULL)
elog(ERROR, "ERROR: Please specifiy option to reconnect command.\n");
else if (TestToken("gtm_proxy"))
{
if (!isVarYes(VAR_gtmProxy))
elog(ERROR, "ERROR: gtm proxy is not configured.\n");
else if ((GetToken() == NULL) || TestToken("all"))
reconnect_gtm_proxy_all();
else
{
char **nodeList = NULL;
int idx;
do
{
if ((idx = gtmProxyIdx(token)) < 0)
elog(ERROR, "ERROR: %s is not gtm_proxy.\n", token);
else
AddMember(nodeList, token);
} while(GetToken());
if (nodeList)
reconnect_gtm_proxy(nodeList);
CleanArray(nodeList);
}
}
else
elog(ERROR, "ERROR: invalid option %s for reconnect command.\n", token);
return;
}
/*
* Kill command ... kill nodename, kill all,
* kill gtm [master|slave|all],
* kill gtm_proxy [nodename|all] ...
* kill coordinator [nodename ... |master [all | nodenames ... ] | slave [all | nodenames ... ] |all]
* kill datanode [nodename ... |master [all | nodenames ... ] | slave [all | nodenames ... ] |all]
*/
static void do_kill_command(char *line)
{
char *token;
if (GetToken() == NULL)
elog(ERROR, "ERROR: Please specifiy option to kill command\n");
else if (TestToken("gtm"))
{
if ((GetToken() == NULL) || TestToken("all"))
{
kill_gtm_master();
if (isVarYes(VAR_gtmSlave))
kill_gtm_slave();
}
else if (TestToken("master"))
kill_gtm_master();
else if (TestToken("slave"))
{
if (isVarYes(VAR_gtmSlave))
kill_gtm_slave();
else
elog(ERROR, "ERROR: GTM slave is not configured.\n");
}
else
elog(ERROR, "ERROR: input value \"%s\" is invalid.\n", token);
return;
}
else if (TestToken("gtm_proxy"))
{
if (GetToken() == NULL)
elog(ERROR, "ERROR: Please specify additonal option to kill gtm_proxies\n");
else if (TestToken("all"))
kill_gtm_proxy(aval(VAR_gtmProxyNames));
else
{
char **nodeList = Malloc0(sizeof(char*));
do {
AddMember(nodeList, token);
} while(GetToken());
kill_gtm_proxy(nodeList);
clean_array(nodeList);
}
return;
}
else if (TestToken("coordinator"))
{
if ((GetToken() == NULL) || TestToken("all"))
{
kill_coordinator_master(aval(VAR_coordNames));
if (isVarYes(VAR_coordSlave))
kill_coordinator_slave(aval(VAR_coordNames));
}
if (TestToken("master"))
{
if ((GetToken() == NULL) || (TestToken("all")))
kill_coordinator_master(aval(VAR_coordNames));
else
{
char **nodeList = Malloc0(sizeof(char *));
do {
AddMember(nodeList, token);
} while (GetToken());
kill_coordinator_master(nodeList);
clean_array(nodeList);
}
}
else if (TestToken("slave"))
{
if ((GetToken() == NULL) || (TestToken("all")))
kill_coordinator_slave(aval(VAR_coordNames));
else
{
char **nodeList = Malloc0(sizeof(char *));
do {
AddMember(nodeList, token);
} while (GetToken());
kill_coordinator_slave(nodeList);
clean_array(nodeList);
}
}
else
{
char **nodeList = Malloc0(sizeof(char *));
do {
AddMember(nodeList, token);
} while (GetToken());
kill_coordinator_master(nodeList);
if (isVarYes(VAR_coordSlave))
kill_coordinator_slave(nodeList);
clean_array(nodeList);
}
return;
}
else if (TestToken("datanode"))
{
if ((GetToken() == NULL) || (TestToken("all")))
{
kill_datanode_master(aval(VAR_datanodeNames));
if (isVarYes(VAR_datanodeSlave))
kill_datanode_slave(aval(VAR_coordNames));
}
else if (TestToken("master"))
{
if ((GetToken() == NULL) || (TestToken("all")))
kill_datanode_master(aval(VAR_datanodeNames));
else
{
char **nodeList = Malloc0(sizeof(char *));
do{
AddMember(nodeList, token);
} while (GetToken());
kill_datanode_master(nodeList);
clean_array(nodeList);
}
}
else if (TestToken("slave"))
{
if ((GetToken() == NULL) || (TestToken("all")))
kill_datanode_slave(aval(VAR_datanodeNames));
else
{
char **nodeList = Malloc0(sizeof(char *));
do {
AddMember(nodeList, token);
} while (GetToken());
kill_datanode_slave(nodeList);
clean_array(nodeList);
}
}
else
{
char **nodeList = Malloc0(sizeof(char *));
do {
AddMember(nodeList, token);
} while (GetToken());
kill_datanode_master(nodeList);
if (isVarYes(VAR_datanodeSlave))
kill_datanode_slave(nodeList);
clean_array(nodeList);
}
}
else if (TestToken("all"))
{
if(isVarYes(VAR_datanodeSlave))
kill_datanode_slave(aval(VAR_datanodeNames));
kill_datanode_master(aval(VAR_datanodeNames));
if (isVarYes(VAR_coordSlave))
kill_coordinator_slave(aval(VAR_coordNames));
kill_coordinator_master(aval(VAR_coordNames));
if (isVarYes(VAR_gtmProxy))
kill_gtm_proxy(aval(VAR_gtmProxyNames));
if (isVarYes(VAR_gtmSlave))
kill_gtm_slave();
kill_gtm_master();
}
else
{
do {
kill_something(token);
} while (GetToken());
}
return;
}
static void init_all(void)
{
init_gtm_master(true);
start_gtm_master();
if (isVarYes(VAR_gtmSlave))
{
init_gtm_slave();
start_gtm_slave();
}
if (isVarYes(VAR_gtmProxy))
{
init_gtm_proxy_all();
start_gtm_proxy_all();
}
init_coordinator_master_all();
start_coordinator_master_all();
if (isVarYes(VAR_coordSlave))
{
init_coordinator_slave_all();
start_coordinator_slave_all();
}
init_datanode_master_all();
start_datanode_master_all();
if (isVarYes(VAR_datanodeSlave))
{
init_datanode_slave_all();
start_datanode_slave_all();
}
configure_nodes_all();
}
/*
* Init command ... init all
* init gtm [master|slave|all],
* init gtm_proxy [all| nodename ...]
* init coordinator [all | master [all | nodename ... ]| slave [all | nodename ... ]| nodename ... ]
* init datanode [all | master [all | nodename ...] | slave [all | nodename ... ] | nodename ... ]
*/
static void do_init_command(char *line)
{
char *token;
if (GetToken() == NULL)
elog(ERROR, "ERROR: Please specify option to init command.\n");
if (TestToken("force"))
{
forceInit = true;
if (GetToken() == NULL)
elog(ERROR, "ERROR: Please specify option to init command.\n");
}
if (TestToken("all"))
init_all();
else if (TestToken("gtm"))
{
if (!GetToken() || (TestToken("all")))
{
init_gtm_master(true);
if (isVarYes(VAR_gtmSlave))
init_gtm_slave();
}
else if (TestToken("master"))
init_gtm_master(true);
else if (TestToken("slave"))
init_gtm_slave();
else
elog(ERROR, "ERROR: please specify master, slave or all for init gtm command.\n");
}
else if (TestToken("gtm_proxy"))
if (!GetToken() || TestToken("all"))
init_gtm_proxy_all();
else
{
char **nodeList = Malloc0(sizeof(char *));
do {
AddMember(nodeList, token);
} while(GetToken());
init_gtm_proxy(nodeList);
clean_array(nodeList);
}
else if (TestToken("coordinator"))
if (!GetToken() || TestToken("all"))
{
init_coordinator_master_all();
if (isVarYes(VAR_coordSlave))
init_coordinator_slave_all();
}
else if (TestToken("master"))
if (!GetToken() || TestToken("all"))
init_coordinator_master_all();
else
{
char **nodeList = Malloc0(sizeof(char *));
do {
AddMember(nodeList, token);
} while(GetToken());
init_coordinator_master(nodeList);
clean_array(nodeList);
}
else if (TestToken("slave"))
if (!GetToken() || TestToken("all"))
init_coordinator_slave_all();
else
{
char **nodeList = Malloc0(sizeof(char *));
do {
AddMember(nodeList, token);
} while(GetToken());
init_coordinator_slave(nodeList);
clean_array(nodeList);
}
else
{
char **nodeList = Malloc0(sizeof(char *));
do
AddMember(nodeList, token);
while(GetToken());
init_coordinator_master(nodeList);
if (isVarYes(VAR_coordSlave))
init_coordinator_slave(nodeList);
clean_array(nodeList);
}
else if (TestToken("datanode"))
if (!GetToken() || TestToken("all"))
{
init_datanode_master_all();
if (isVarYes(VAR_datanodeSlave))
init_datanode_slave_all();
}
else if (TestToken("master"))
if (!GetToken() || TestToken("all"))
init_datanode_master_all();
else
{
char **nodeList = Malloc0(sizeof(char *));
do
AddMember(nodeList, token);
while(GetToken());
init_datanode_master(nodeList);
clean_array(nodeList);
}
else if (TestToken("slave"))
if (!GetToken() || TestToken("all"))
init_datanode_slave_all();
else
{
char **nodeList = Malloc0(sizeof(char *));
do
AddMember(nodeList, token);
while(GetToken());
init_datanode_slave(nodeList);
clean_array(nodeList);
}
else
{
char **nodeList = Malloc0(sizeof(char *));
do
AddMember(nodeList, token);
while(GetToken());
init_datanode_master(nodeList);
if (isVarYes(VAR_datanodeSlave))
init_datanode_slave(nodeList);
}
else
elog(ERROR, "ERROR: invalid option for init command.\n");
return;
}
/*
* Start command ... start nodename, start all,
* start gtm [master|slave|all],
* start gtm_proxy [nodename|all] ...
* start coordinator [nodename ... |master [all | nodenames ... ] | slave [all | nodenames ... ] |all]
* start datanode [nodename ... |master [all | nodenames ... ] | slave [all | nodenames ... ] |all]
*/
static void start_all(void)
{
start_gtm_master();
if (isVarYes(VAR_gtmSlave))
start_gtm_slave();
if (isVarYes(VAR_gtmProxy))
start_gtm_proxy_all();
start_coordinator_master_all();
if (isVarYes(VAR_coordSlave))
start_coordinator_slave_all();
start_datanode_master_all();
if (isVarYes(VAR_datanodeSlave))
start_datanode_slave_all();
}
static void do_start_command(char *line)
{
char *token;
if (GetToken() == NULL)
elog(ERROR, "ERROR: Please specify option to start command.\n");
else if (TestToken("all"))
start_all();
else if (TestToken("gtm"))
{
if (!GetToken() || (TestToken("all")))
{
start_gtm_master();
if (isVarYes(VAR_gtmSlave))
start_gtm_slave();
}
else if (TestToken("master"))
start_gtm_master();
else if (TestToken("slave"))
start_gtm_slave();
else
elog(ERROR, "ERROR: please specify master, slave or all for start gtm command.\n");
}
else if (TestToken("gtm_proxy"))
if (!GetToken() || TestToken("all"))
start_gtm_proxy_all();
else
{
char **nodeList = NULL;
do
AddMember(nodeList, token);
while (GetToken());
start_gtm_proxy(nodeList);
clean_array(nodeList);
}
else if (TestToken("coordinator"))
if (!GetToken() || TestToken("all"))
{
start_coordinator_master_all();
if (isVarYes(VAR_coordSlave))
start_coordinator_slave_all();
}
else if (TestToken("master"))
if (!GetToken() || TestToken("all"))
start_coordinator_master_all();
else
{
char **nodeList = NULL;
do
AddMember(nodeList, token);
while(GetToken());
start_coordinator_master(nodeList);
clean_array(nodeList);
}
else if (TestToken("slave"))
if (!GetToken() || TestToken("all"))
start_coordinator_slave_all();
else
{
char **nodeList = NULL;
do
AddMember(nodeList, token);
while(GetToken());
start_coordinator_slave(nodeList);
clean_array(nodeList);
}
else
{
char **nodeList = NULL;
do
AddMember(nodeList, token);
while(GetToken());
start_coordinator_master(nodeList);
if (isVarYes(VAR_coordSlave))
start_coordinator_slave(nodeList);
clean_array(nodeList);
}
else if (TestToken("datanode"))
if (!GetToken() || TestToken("all"))
{
start_datanode_master_all();
if (isVarYes(VAR_datanodeSlave))
start_datanode_slave_all();
}
else if (TestToken("master"))
if (!GetToken() || TestToken("all"))
start_datanode_master_all();
else
{
char **nodeList = Malloc0(sizeof(char *));
do
AddMember(nodeList, token);
while(GetToken());
start_datanode_master(nodeList);
clean_array(nodeList);
}
else if (TestToken("slave"))
if (!GetToken() || TestToken("all"))
start_datanode_slave_all();
else
{
char **nodeList = Malloc0(sizeof(char *));
do
AddMember(nodeList, token);
while(GetToken());
start_datanode_slave(nodeList);
clean_array(nodeList);
}
else
{
char **nodeList = Malloc0(sizeof(char *));
do
AddMember(nodeList, token);
while(GetToken());
start_datanode_master(nodeList);
if (isVarYes(VAR_datanodeSlave))
start_datanode_slave(nodeList);
}
else
elog(ERROR, "ERROR: invalid option for start command.\n");
return;
}
/*
* Stop command ... stop [-m smart | fast | immediate] all
* stop gtm [master | slave | all],
* stop gtm_proxy [ nodename | all] ...
* stop [-m smart | fast | immediate ] coordinator [nodename ... | master [all | nodenames ... ] | slave [all | nodenames ... ] |all]
* stop [-m smart | fast | immediate ] datanode [nodename ... | master [all | nodenames ... ] | slave [all | nodenames ... ] |all]
*
*/
static void stop_all(char *immediate)
{
if (isVarYes(VAR_coordSlave))
stop_coordinator_slave_all(immediate);
stop_coordinator_master_all(immediate);
if (isVarYes(VAR_datanodeSlave))
stop_datanode_slave_all(immediate);
stop_datanode_master_all(immediate);
if (isVarYes(VAR_gtmProxy))
stop_gtm_proxy_all();
if (isVarYes(VAR_gtmSlave))
stop_gtm_slave();
if (!is_none(sval(VAR_gtmMasterServer)))
stop_gtm_master();
}
#define GetAndSet(var, msg) do{if(!GetToken()){elog(ERROR, msg); return;} var=Strdup(token);}while(0)
/*
* Add command
*/
static void do_add_command(char *line)
{
char *token;
char *name;
char *host;
char *port;
char *pooler;
char *dir;
char *walDir;
char *archDir;
char *extraConf;
char *extraPgHbaConf;
if (!GetToken())
{
elog(ERROR, "ERROR: Specify options for add command.\n");
return;
}
if (!TestToken("gtm") && is_none(sval(VAR_gtmMasterServer)))
{
elog(ERROR, "ERROR: GTM master must be added before adding any other component.\n");
return;
}
if (TestToken("gtm"))
{
/*
* add gtm master name host port dir
*/
if (!GetToken())
{
elog(ERROR, "ERROR: Specify option for add gtm command.\n");
return;
}
if (TestToken("master"))
{
GetAndSet(name, "ERROR: please specify the name of gtm master\n");
GetAndSet(host, "ERROR: please specify the host name for gtm master\n");
GetAndSet(port, "ERROR: please specify the port number for gtm master\n");
GetAndSet(dir, "ERROR: please specify the working director for gtm master\n");
add_gtmMaster(name, host, atoi(port), dir);
}
else if (TestToken("slave"))
{
GetAndSet(name, "ERROR: please specify the name of gtm slave\n");
GetAndSet(host, "ERROR: please specify the host name for gtm slave\n");
GetAndSet(port, "ERROR: please specify the port number for gtm slave\n");
GetAndSet(dir, "ERROR: please specify the working director for gtm slave\n");
add_gtmSlave(name, host, atoi(port), dir);
}
else
{
elog(ERROR, "ERROR: you can specify only master/slave to add gtm command. %s is invalid.\n", token);
return;
}
freeAndReset(name);
freeAndReset(host);
freeAndReset(port);
freeAndReset(dir);
}
else if (TestToken("gtm_proxy"))
{
/*
* Add gtm_proxy name host port dir
*/
GetAndSet(name, "ERROR: please specify the name of gtm_proxy\n");
GetAndSet(host, "ERROR: please specify the host name for gtm_proxy\n");
GetAndSet(port, "ERROR: please specify the port number for gtm_proxy\n");
GetAndSet(dir, "ERROR: please specify the working director for gtm_proxy\n");
add_gtmProxy(name, host, atoi(port), dir);
freeAndReset(name);
freeAndReset(host);
freeAndReset(port);
freeAndReset(dir);
}
else if (TestToken("coordinator"))
{
/*
* Add coordinator master name host port pooler dir
* Add coordinator slave name host dir
*/
if (!GetToken() || (!TestToken("master") && !TestToken("slave")))
{
elog(ERROR, "ERROR: please specify master or slave.\n");
return;
}
if (TestToken("master"))
{
GetAndSet(name, "ERROR: please specify the name of the coordinator master\n");
GetAndSet(host, "ERROR: please specify the host for the coordinator masetr\n");
GetAndSet(port, "ERROR: please specify the port number for the coordinator master\n");
GetAndSet(pooler, "ERROR: please specify the pooler port number for the coordinator master.\n");
GetAndSet(dir, "ERROR: please specify the working directory for the coordinator master\n");
GetAndSet(extraConf, "ERROR: please specify file to read extra configuration. Specify 'none' if nothing extra to be added.\n");
GetAndSet(extraPgHbaConf, "ERROR: please specify file to read extra pg_hba configuration. Specify 'none' if nothing extra to be added.\n");
add_coordinatorMaster(name, host, atoi(port), atoi(pooler), dir,
extraConf, extraPgHbaConf);
freeAndReset(name);
freeAndReset(host);
freeAndReset(port);
freeAndReset(pooler);
freeAndReset(dir);
}
else
{
GetAndSet(name, "ERROR: please specify the name of the coordinator slave\n");
GetAndSet(host, "ERROR: please specify the host for the coordinator slave\n");
GetAndSet(port, "ERROR: please specify the port number for the coordinator slave\n");
GetAndSet(pooler, "ERROR: please specify the pooler port number for the coordinator slave.\n");
GetAndSet(dir, "ERROR: please specify the working director for coordinator slave\n");
GetAndSet(archDir, "ERROR: please specify WAL archive directory for coordinator slave\n");
add_coordinatorSlave(name, host, atoi(port), atoi(pooler), dir, archDir);
freeAndReset(name);
freeAndReset(host);
freeAndReset(dir);
}
}
else if (TestToken("datanode"))
{
if (!GetToken() || (!TestToken("master") && !TestToken("slave")))
{
elog(ERROR, "ERROR: please specify master or slave.\n");
return;
}
if (TestToken("master"))
{
GetAndSet(name, "ERROR: please specify the name of the datanode master\n");
GetAndSet(host, "ERROR: please specify the host for the datanode masetr\n");
GetAndSet(port, "ERROR: please specify the port number for the datanode master\n");
GetAndSet(pooler, "ERROR: please specify the pooler port number for the datanode master.\n");
GetAndSet(dir, "ERROR: please specify the working director for the datanode master\n");
GetAndSet(walDir, "ERROR: please specify the WAL directory for the datanode master WAL. Specify 'none' for default\n");
GetAndSet(extraConf, "ERROR: please specify file to read extra configuration. Specify 'none' if nothig extra to be added.\n");
GetAndSet(extraPgHbaConf, "ERROR: please specify file to read extra pg_hba configuration. Specify 'none' if nothig extra to be added.\n");
add_datanodeMaster(name, host, atoi(port), atoi(pooler), dir,
walDir, extraConf, extraPgHbaConf);
freeAndReset(name);
freeAndReset(host);
freeAndReset(port);
freeAndReset(pooler);
freeAndReset(dir);
freeAndReset(walDir);
}
else
{
GetAndSet(name, "ERROR: please specify the name of the datanode slave\n");
GetAndSet(host, "ERROR: please specify the host for the datanode slave\n");
GetAndSet(port, "ERROR: please specify the port number for the datanode slave\n");
GetAndSet(pooler, "ERROR: please specify the pooler port number for the datanode slave.\n");
GetAndSet(dir, "ERROR: please specify the working directory for datanode slave\n");
GetAndSet(walDir, "ERROR: please specify the WAL directory for datanode slave WAL. Specify 'none' for default.\n");
GetAndSet(archDir, "ERROR: please specify WAL archive directory for datanode slave\n");
add_datanodeSlave(name, host, atoi(port), atoi(pooler), dir,
walDir, archDir);
freeAndReset(name);
freeAndReset(host);
freeAndReset(port);
freeAndReset(pooler);
freeAndReset(dir);
freeAndReset(walDir);
}
}
return;
}
static void do_remove_command(char *line)
{
char *token;
char *name;
bool clean_opt = FALSE;
if (!GetToken())
{
elog(ERROR, "ERROR: Please specify gtm, gtm_master, coordinator or datanode after add command.\n");
return;
}
if (TestToken("gtm"))
{
if (!GetToken())
{
elog(ERROR, "ERROR: Specify option to remove gtm command\n");
return;
}
if (TestToken("master"))
{
if (GetToken() && TestToken("clean"))
clean_opt = TRUE;
remove_gtmMaster(clean_opt);
}
else if (TestToken("slave"))
{
if (GetToken() && TestToken("clean"))
clean_opt = TRUE;
remove_gtmSlave(clean_opt);
}
else
{
elog(ERROR, "ERROR: you can specify only master/slave to remove gtm command. %s is invalid.\n", token);
return;
}
}
else if (TestToken("gtm_proxy"))
{
GetAndSet(name, "ERROR: please specify gtm proxy name to remove.\n");
if (GetToken() && TestToken("clean"))
clean_opt = TRUE;
remove_gtmProxy(name, clean_opt );
freeAndReset(name);
}
else if (TestToken("coordinator"))
{
if (!GetToken() || (!TestToken("master") && !TestToken("slave")))
{
elog(ERROR, "ERROR: please specify master or slave.\n");
return;
}
if (TestToken("master"))
{
GetAndSet(name, "ERROR: please specify the name of the coordinator master\n");
if (GetToken() && TestToken("clean"))
clean_opt = TRUE;
remove_coordinatorMaster(name, clean_opt);
freeAndReset(name);
}
else
{
GetAndSet(name, "ERROR: please specify the name of the coordinator slave\n");
if (GetToken() && TestToken("clean"))
clean_opt = TRUE;
remove_coordinatorSlave(name, clean_opt);
freeAndReset(name);
}
}
else if (TestToken("datanode"))
{
if (!GetToken() || (!TestToken("master") && !TestToken("slave")))
{
elog(ERROR, "ERROR: please specify master or slave.\n");
return;
}
if (TestToken("master"))
{
GetAndSet(name, "ERROR: please specify the name of the datanode master\n");
if (GetToken() && TestToken("clean"))
clean_opt = TRUE;
remove_datanodeMaster(name, clean_opt);
freeAndReset(name);
}
else
{
GetAndSet(name, "ERROR: please specify the name of the datanode slave\n");
if (GetToken() && TestToken("clean"))
clean_opt = TRUE;
remove_datanodeSlave(name, clean_opt);
freeAndReset(name);
}
}
else
elog(ERROR, "ERROR: invalid argument %s to add command.\n", token);
return;
}
static char *m_Option;
static char *handle_m_option(char *line, char **m_option)
{
char *token;
freeAndReset(m_Option);
if (GetToken() == NULL)
return(line);
else if (TestToken("immediate"))
m_Option = Strdup("immediate");
else if (TestToken("fast"))
m_Option = Strdup("fast");
else if (TestToken("smart"))
m_Option = Strdup("smart");
else
elog(ERROR, "ERROR: specify smart, fast or immediate for -m option value.\n");
return(line);
}
static void do_stop_command(char *line)
{
char *token;
freeAndReset(m_Option);
if (GetToken() == NULL)
elog(ERROR, "ERROR: Please specify option to stop command.\n");
else if (testToken("-m"))
{
line = handle_m_option(line, &m_Option);
GetToken();
}
if (TestToken("all"))
{
if (GetToken() && TestToken("-m"))
handle_m_option(line, &m_Option);
stop_all(m_Option);
}
else if (TestToken("gtm"))
{
if (m_Option)
elog(WARNING, "-m option is not available with gtm. Ignoring.\n");
if (!GetToken() || (TestToken("all")))
{
if (!is_none(sval(VAR_gtmMasterServer)))
stop_gtm_master();
if (isVarYes(VAR_gtmSlave))
stop_gtm_slave();
}
else if (TestToken("master") && !is_none(sval(VAR_gtmMasterServer)))
stop_gtm_master();
else if (TestToken("slave") && isVarYes(VAR_gtmSlave))
stop_gtm_slave();
else
elog(ERROR, "ERROR: please specify master, slave or all for stop gtm command.\n");
}
else if (TestToken("gtm_proxy"))
{
if (m_Option)
elog(WARNING, "-m option is not available with gtm_prxy. Ignoring.\n");
if (!GetToken() || TestToken("all"))
stop_gtm_proxy_all();
else
{
char **nodeList = NULL;
do
AddMember(nodeList, token);
while (GetToken());
stop_gtm_proxy(nodeList);
clean_array(nodeList);
}
}
else if (TestToken("coordinator"))
{
if (!GetToken() || TestToken("all"))
{
stop_coordinator_master_all(m_Option);
if (isVarYes(VAR_coordSlave))
stop_coordinator_slave_all(m_Option);
}
else if (TestToken("master"))
if (!GetToken() || TestToken("all"))
stop_coordinator_master_all(m_Option);
else
{
char **nodeList = NULL;
do
AddMember(nodeList, token);
while(GetToken());
stop_coordinator_master(nodeList, m_Option);
clean_array(nodeList);
}
else if (TestToken("slave"))
if (!GetToken() || TestToken("all"))
stop_coordinator_slave_all(m_Option);
else
{
char **nodeList = NULL;
do
AddMember(nodeList, token);
while(GetToken());
stop_coordinator_slave(nodeList, m_Option);
clean_array(nodeList);
}
else
{
char **nodeList = NULL;
do
AddMember(nodeList, token);
while(GetToken());
stop_coordinator_master(nodeList, m_Option);
if (isVarYes(VAR_coordSlave))
stop_coordinator_slave(nodeList, m_Option);
clean_array(nodeList);
}
}
else if (TestToken("datanode"))
{
if (!GetToken() || TestToken("all"))
{
stop_datanode_master_all(m_Option);
if (isVarYes(VAR_datanodeSlave))
stop_datanode_slave_all(m_Option);
}
else if (TestToken("master"))
if (!GetToken() || TestToken("all"))
stop_datanode_master_all(m_Option);
else
{
char **nodeList = Malloc0(sizeof(char *));
do
AddMember(nodeList, token);
while(GetToken());
stop_datanode_master(nodeList, m_Option);
clean_array(nodeList);
}
else if (TestToken("slave"))
if (!GetToken() || TestToken("all"))
stop_datanode_slave_all(m_Option);
else
{
char **nodeList = Malloc0(sizeof(char *));
do
AddMember(nodeList, token);
while(GetToken());
stop_datanode_slave(nodeList, m_Option);
clean_array(nodeList);
}
else
{
char **nodeList = Malloc0(sizeof(char *));
do
AddMember(nodeList, token);
while(GetToken());
stop_datanode_master(nodeList, m_Option);
if (isVarYes(VAR_datanodeSlave))
stop_datanode_slave(nodeList, m_Option);
}
}
else
elog(ERROR, "ERROR: invalid option for stop command.\n");
return;
}
/*
* Test staff
*/
static void do_test(char *line)
{
char *token;
int logLevel;
int printLevel;
logLevel = setLogMsgLevel(DEBUG3);
printLevel = setPrintMsgLevel(DEBUG3);
GetToken();
if (TestToken("ssh"))
{
cmdList_t *cmdList;
cmd_t *cmd;
GetToken();
cmdList = initCmdList();
cmd = Malloc0(sizeof(cmd_t));
cmd->host = Strdup(token);
cmd->command = Strdup(line);
cmd->localStdin = NULL;
addCmd(cmdList, cmd);
elog(INFO, "INFO: Testing ssh %s \"%s\"\n", token, line);
doCmdList(cmdList);
cleanCmdList(cmdList);
}
else if (TestToken("ssh-stdin"))
{
cmdList_t *cmdList;
cmd_t *cmd;
cmdList = initCmdList();
cmd = Malloc0(sizeof(cmd_t));
GetToken();
cmd->host = Strdup(token);
GetToken();
cmd->localStdin = Strdup(token);
cmd->command = Strdup(line);
addCmd(cmdList, cmd);
elog(INFO, "Testing ssh %s \"%s\" < %s\n", cmd->host, cmd->command, cmd->localStdin);
doCmdList(cmdList);
cleanCmdList(cmdList);
}
else if (TestToken("local"))
{
cmdList_t *cmdList;
cmd_t *cmd;
cmdList = initCmdList();
addCmd(cmdList, (cmd = initCmd(NULL)));
cmd->command = Strdup(line);
elog(INFO, "Testing local, \"%s\"\n", cmd->command);
doCmdList(cmdList);
cleanCmdList(cmdList);
}
else if (TestToken("local-stdin"))
{
cmdList_t *cmdList;
cmd_t *cmd;
cmdList = initCmdList();
addCmd(cmdList, (cmd = initCmd(NULL)));
GetToken();
cmd->localStdin = Strdup(token);
cmd->command = Strdup(line);
elog(INFO, "Testing local-stdin, \"%s\"\n", cmd->command);
doCmdList(cmdList);
cleanCmdList(cmdList);
}
setLogMsgLevel(logLevel);
setPrintMsgLevel(printLevel);
}
/* ==================================================================
*
* Staff specified by "node name", not node type
*
* ==================================================================
*/
static void kill_something(char *nodeName)
{
char *nodeList[2];
nodeList[1] = NULL;
switch(getNodeType(nodeName))
{
case NodeType_UNDEF:
elog(ERROR, "ERROR: Could not find name \"%s\" in any node type.\n", nodeName);
return;
case NodeType_GTM:
elog(ERROR, "ERROR: Issue kill gtm command to kill gtm master/slave\n");
return;
case NodeType_GTM_PROXY:
nodeList[0] = nodeName;
kill_gtm_proxy(nodeList);
return;
case NodeType_COORDINATOR:
nodeList[0] = nodeName;
kill_coordinator_master(nodeList);
if (isVarYes(VAR_coordSlave))
kill_coordinator_slave(nodeList);
return;
case NodeType_DATANODE:
nodeList[0] = nodeName;
kill_datanode_master(nodeList);
if (isVarYes(VAR_datanodeSlave))
kill_datanode_slave(nodeList);
return;
default:
elog(ERROR, "ERROR: internal error. Should not come here!\n");
return;
}
}
static void show_config_something_multi(char **nodeList)
{
int ii;
for (ii = 0; nodeList[ii]; ii++)
show_config_something(nodeList[ii]);
}
static void show_config_something(char *nodeName)
{
int idx;
switch(getNodeType(nodeName))
{
case NodeType_UNDEF:
elog(ERROR, "ERROR: Could not find name \"%s\" in any node type.\n", nodeName);
return;
case NodeType_GTM:
show_config_gtmMaster(TRUE, sval(VAR_gtmMasterServer));
if (isVarYes(VAR_gtmSlave))
show_config_gtmSlave(TRUE, sval(VAR_gtmSlaveServer));
return;
case NodeType_GTM_PROXY:
idx = gtmProxyIdx(nodeName);
show_config_gtmProxy(TRUE, idx, aval(VAR_gtmProxyServers)[idx]);
return;
case NodeType_COORDINATOR:
idx = coordIdx(nodeName);
show_config_coordMaster(TRUE, idx, aval(VAR_coordMasterServers)[idx]);
if (isVarYes(VAR_coordSlave))
show_config_coordSlave(TRUE, idx, aval(VAR_coordSlaveServers)[idx]);
return;
case NodeType_DATANODE:
idx = datanodeIdx(nodeName);
show_config_datanodeMaster(TRUE, idx, aval(VAR_datanodeMasterServers)[idx]);
if (isVarYes(VAR_datanodeSlave))
show_config_datanodeSlave(TRUE, idx, aval(VAR_datanodeSlaveServers)[idx]);
return;
case NodeType_SERVER:
{
char *hostList[2];
hostList[0] = nodeName;
hostList[1] = NULL;
show_config_servers(hostList);
return;
}
default:
elog(ERROR, "ERROR: internal error. Should not come here!\n");
return;
}
}
/* ========================================================================================
*
* Configuration staff
*
* ========================================================================================
*/
static void show_config_servers(char **hostList)
{
int ii;
for (ii = 0; hostList[ii]; ii++)
if (!is_none(hostList[ii]))
show_config_host(hostList[ii]);
return;
}
/*
* show {config|configuration} [all | name .... | gtm [master|slave|all] | gtm_proxy [all | name ...] |
* coordinator [all | master | slave | name ... ] |
* host name .... ]
* With no option, will print common configuartion parameters and exit.
*
*/
static void show_basicConfig(void)
{
elog(NOTICE, "========= Postgres-XL configuration Common Info ========================\n");
elog(NOTICE, "=== Overall ===\n");
elog(NOTICE, "Postgres-XL owner: %s\n", sval(VAR_pgxcOwner));
elog(NOTICE, "Postgres-XL user: %s\n", sval(VAR_pgxcUser));
elog(NOTICE, "Postgres-XL install directory: %s\n", sval(VAR_pgxcInstallDir));
elog(NOTICE, "pgxc_ctl home: %s\n", pgxc_ctl_home);
elog(NOTICE, "pgxc_ctl configuration file: %s\n", pgxc_ctl_config_path);
elog(NOTICE, "pgxc_ctl tmpDir: %s\n", sval(VAR_tmpDir));
elog(NOTICE, "pgxc_ctl localTempDir: %s\n", sval(VAR_localTmpDir));
elog(NOTICE, "pgxc_ctl log file: %s\n", logFileName);
elog(NOTICE, "pgxc_ctl configBackup: %s\n", isVarYes(VAR_configBackup) ? "y" : "n");
elog(NOTICE, "pgxc_ctl configBackupHost: %s\n", isVarYes(VAR_configBackup) ? sval(VAR_configBackupHost) : "none");
elog(NOTICE, "pgxc_ctl configBackupFile: %s\n", isVarYes(VAR_configBackup) ? sval(VAR_configBackupFile) : "none");
elog(NOTICE, "========= Postgres-XL configuration End Common Info ===================\n");
}
static void show_configuration(char *line)
{
char *token;
GetToken();
if (line == NULL)
elog(ERROR, "ERROR: No configuration option is specified. Retruning.\n");
else if (TestToken("basic"))
show_basicConfig();
else if (TestToken("all"))
{
show_basicConfig();
show_config_servers(aval(VAR_allServers));
}
else if (TestToken("basic"))
{
show_basicConfig();
}
else if (TestToken("host"))
{
char **hostList = Malloc0(sizeof(char *));
do {
AddMember(hostList, token);
} while(GetToken());
if (hostList[0])
show_config_servers(hostList);
clean_array(hostList);
}
else if (TestToken("gtm"))
{
if ((GetToken() == NULL) || (TestToken("all")))
{
show_config_gtmMaster(TRUE, sval(VAR_gtmMasterServer));
if (isVarYes(VAR_gtmSlave))
show_config_gtmSlave(TRUE, sval(VAR_gtmSlaveServer));
}
else if (TestToken("master"))
show_config_gtmMaster(TRUE, sval(VAR_gtmMasterServer));
else if (TestToken("slave"))
{
if (isVarYes(VAR_gtmSlave))
show_config_gtmSlave(TRUE, sval(VAR_gtmSlaveServer));
else
elog(NOTICE, "NOTICE: gtm slave is not configured.\n");
}
else
elog(ERROR, "ERROR: invalid option %s for 'show config gtm' command.\n", token);
}
else if (TestToken("gtm_proxy"))
{
if (!isVarYes(VAR_gtmProxy))
{
elog(ERROR, "ERROR: gtm proxies are not configured.\n");
}
else if ((GetToken() == NULL) || (TestToken("all")))
show_config_gtmProxies(aval(VAR_gtmProxyNames));
else
{
char **nodeList = Malloc0(sizeof(char *));
do{
int idx;
idx = gtmProxyIdx(token);
if (idx < 0)
elog(ERROR, "ERROR: Specified name %s is not GTM Proxy.\n", token);
else
AddMember(nodeList, token);
} while(GetToken());
show_config_gtmProxies(nodeList);
clean_array(nodeList);
}
}
else if (TestToken("coordinator"))
{
if ((GetToken() == NULL) || (TestToken("all")))
show_config_coordMasterSlaveMulti(aval(VAR_coordNames));
else if (TestToken("master"))
{
if (GetToken() == NULL)
show_config_coordMasterMulti(aval(VAR_coordNames));
else
{
char **nodeList = Malloc0(sizeof(char *));
do
AddMember(nodeList, token);
while(GetToken());
show_config_coordMasterMulti(nodeList);
clean_array(nodeList);
}
}
else if (TestToken("slave"))
{
if (!isVarYes(VAR_coordSlave))
elog(ERROR, "ERROR: Coordinator slave is not configured.\n");
else if (GetToken() == NULL)
show_config_coordMasterMulti(aval(VAR_coordNames));
else
{
char **nodeList = Malloc0(sizeof(char *));
do
AddMember(nodeList, token);
while(GetToken());
show_config_coordMasterMulti(nodeList);
clean_array(nodeList);
}
}
else
elog(ERROR, "ERROR: Invalid option %s for 'show config coordinator' command.\n", token);
}
else if (TestToken("datanode"))
{
if ((GetToken() == NULL) || (TestToken("all")))
show_config_datanodeMasterSlaveMulti(aval(VAR_datanodeNames));
else if (TestToken("master"))
{
if (GetToken() == NULL)
show_config_datanodeMasterMulti(aval(VAR_datanodeNames));
else
{
char **nodeList = Malloc0(sizeof(char *));
do
AddMember(nodeList, token);
while(GetToken());
show_config_datanodeMasterMulti(nodeList);
clean_array(nodeList);
}
}
else if (TestToken("slave"))
{
if (!isVarYes(VAR_datanodeSlave))
elog(ERROR, "ERROR: Datanode slave is not configured.\n");
else if (GetToken() == NULL)
show_config_datanodeMasterMulti(aval(VAR_datanodeNames));
else
{
char **nodeList = Malloc0(sizeof(char *));
do
AddMember(nodeList, token);
while(GetToken());
show_config_datanodeMasterMulti(nodeList);
clean_array(nodeList);
}
}
else
elog(ERROR, "ERROR: Invalid option %s for 'show config datanode' command.\n", token);
}
else
{
char **nodeList = NULL;
do
AddMember(nodeList, token);
while(GetToken());
show_config_something_multi(nodeList);
clean_array(nodeList);
}
return;
}
void print_simple_node_info(char *nodeName, char *port, char *dir,
char *extraConfig, char *specificExtraConfig)
{
elog(NOTICE,
" Nodename: '%s', port: %s, dir: '%s'"
" ExtraConfig: '%s', Specific Extra Config: '%s'\n",
nodeName, port, dir, extraConfig, specificExtraConfig);
}
static void show_config_host(char *hostname)
{
int ii;
lockLogFile();
elog(NOTICE, "====== Server: %s =======\n", hostname);
/* GTM Master */
if (strcmp(hostname, sval(VAR_gtmMasterServer)) == 0)
show_config_gtmMaster(TRUE, NULL);
/* GTM Slave */
if (isVarYes(VAR_gtmSlave) && (strcmp(sval(VAR_gtmSlaveServer), hostname) == 0))
show_config_gtmSlave(TRUE, NULL);
/* GTM Proxy */
if (isVarYes(VAR_gtmProxy))
for (ii = 0; aval(VAR_gtmProxyServers)[ii]; ii++)
if (strcmp(aval(VAR_gtmProxyServers)[ii], hostname) == 0)
show_config_gtmProxy(TRUE, ii, NULL);
/* Coordinator Master */
for (ii = 0; aval(VAR_coordMasterServers)[ii]; ii++)
if (strcmp(aval(VAR_coordMasterServers)[ii], hostname) == 0)
show_config_coordMaster(TRUE, ii, NULL);
/* Coordinator Slave */
if (isVarYes(VAR_coordSlave))
for (ii = 0; aval(VAR_coordSlaveServers)[ii]; ii++)
if (strcmp(aval(VAR_coordSlaveServers)[ii], hostname) == 0)
show_config_coordSlave(TRUE, ii, NULL);
/* Datanode Master */
for (ii = 0; aval(VAR_datanodeMasterServers)[ii]; ii++)
if (strcmp(aval(VAR_datanodeMasterServers)[ii], hostname) == 0)
show_config_datanodeMaster(TRUE, ii, NULL);
/* Datanode Slave */
if (isVarYes(VAR_datanodeSlave))
for (ii = 0; aval(VAR_datanodeSlaveServers)[ii]; ii++)
if (strcmp(aval(VAR_datanodeSlaveServers)[ii], hostname) == 0)
show_config_datanodeSlave(TRUE, ii, NULL);
unlockLogFile();
}
void show_config_hostList(char **hostList)
{
int ii;
for (ii = 0; hostList[ii]; ii++)
show_config_host(hostList[ii]);
}
/*
* Clean command
*
* clean {all |
* gtm [ all | master | slave ] |
* gtm_proxy [ all | nodename ... ]
* coordinator [[all | master | slave ] [nodename ... ]] |
* datanode [ [all | master | slave] [nodename ... ]}
*/
static void do_clean_command(char *line)
{
char *token;
cmdList_t *cmdList = NULL;
GetToken();
if (token == NULL)
{
elog(ERROR, "ERROR: Please specify options for clean command.\n");
return;
}
if (TestToken("all"))
{
elog(INFO, "Stopping all components before cleaning\n");
stop_all("immediate");
elog(INFO, "Cleaning all the directories and sockets.\n");
if (!is_none(sval(VAR_gtmMasterServer)))
clean_gtm_master();
if (isVarYes(VAR_gtmSlave))
clean_gtm_slave();
if (isVarYes(VAR_gtmProxy))
clean_gtm_proxy_all();
clean_coordinator_master_all();
if (isVarYes(VAR_coordSlave))
clean_coordinator_slave_all();
clean_datanode_master_all();
if (isVarYes(VAR_datanodeSlave))
clean_datanode_slave_all();
}
else if (TestToken("gtm"))
{
GetToken();
if ((token == NULL) || TestToken("all"))
{
elog(INFO, "Stopping and cleaning GTM slave/master \n");
if (!is_none(sval(VAR_gtmMasterServer)))
stop_gtm_master();
if (isVarYes(VAR_gtmSlave))
stop_gtm_slave();
if (!is_none(sval(VAR_gtmMasterServer)))
clean_gtm_master();
if (isVarYes(VAR_gtmSlave))
clean_gtm_slave();
}
else if (TestToken("master") && !is_none(sval(VAR_gtmMasterServer)))
{
stop_gtm_master();
clean_gtm_master();
}
else if (TestToken("slave"))
{
if (isVarYes(VAR_gtmSlave))
{
stop_gtm_slave();
clean_gtm_slave();
}
else
elog(ERROR, "ERROR: gtm slave is not configured.\n");
}
else
elog(ERROR, "ERROR: invalid clean command option %s.\n", token);
}
else if (TestToken("gtm_proxy"))
{
elog(INFO, "Stopping and cleaning specified gtm_proxy.\n");
GetToken();
if (!isVarYes(VAR_gtmProxy))
elog(ERROR, "ERROR: gtm proxy is not configured.\n");
else if ((token == NULL) || TestToken("all"))
{
stop_gtm_proxy_all();
clean_gtm_proxy_all();
}
else
{
char **nodeList = NULL;
do
AddMember(nodeList, token);
while(GetToken());
stop_gtm_proxy(nodeList);
clean_gtm_proxy(nodeList);
CleanArray(nodeList);
}
}
else if (TestToken("coordinator"))
{
GetToken();
if (token == NULL)
{
elog(INFO, "Stopping and cleaning coordinator master and slave.\n");
stop_coordinator_master_all("immediate");
if (isVarYes(VAR_coordSlave))
stop_coordinator_slave_all("immediate");
clean_coordinator_master_all();
if (isVarYes(VAR_coordSlave))
clean_coordinator_slave_all();
}
else if (TestToken("all"))
{
elog(INFO, "Stopping and cleaning coordinator master and slave.\n");
GetToken();
if (token == NULL)
{
stop_coordinator_master_all("immediate");
clean_coordinator_master_all();
if (isVarYes(VAR_coordSlave))
{
stop_coordinator_slave_all("immediate");
clean_coordinator_slave_all();
}
}
else
{
char **nodeList = NULL;
do
AddMember(nodeList, token);
while(GetToken());
stop_coordinator_master(nodeList, "immediate");
clean_coordinator_master(nodeList);
if (isVarYes(VAR_coordSlave))
{
stop_coordinator_slave(nodeList,"immediate");
clean_coordinator_slave(nodeList);
}
CleanArray(nodeList);
}
}
else if (TestToken("master"))
{
elog(INFO, "Stopping and cleaning specified coordinator master.\n");
GetToken();
if (token == NULL)
{
stop_coordinator_master_all("immediate");
clean_coordinator_master_all();
}
else
{
char **nodeList = NULL;
do
AddMember(nodeList, token);
while (GetToken());
stop_coordinator_master(nodeList, "immediate");
clean_coordinator_master(nodeList);
CleanArray(nodeList);
}
}
else if (TestToken("slave"))
{
elog(INFO, "Stopping and cleaning specified coordinator slave.\n");
if (!isVarYes(VAR_coordSlave))
{
elog(ERROR, "ERROR: Coordinator slave is not configured.\n");
return;
}
GetToken();
if (token == NULL)
{
stop_coordinator_slave_all("immediate");
clean_coordinator_slave_all();
}
else
{
char **nodeList = NULL;
do
AddMember(nodeList, token);
while (GetToken());
stop_coordinator_slave(nodeList, "immediate");
clean_coordinator_slave(nodeList);
CleanArray(nodeList);
}
}
else
{
char **nodeList = NULL;
elog(INFO, "Stopping and cleaning specified coordinator.\n");
do
AddMember(nodeList, token);
while (GetToken());
stop_coordinator_master(nodeList, "immediate");
clean_coordinator_master(nodeList);
if (isVarYes(VAR_coordSlave))
{
stop_coordinator_slave(nodeList, "immediate");
clean_coordinator_slave(nodeList);
}
CleanArray(nodeList);
}
}
else if(TestToken("datanode"))
{
GetToken();
if (token == NULL)
{
elog(INFO, "Stopping and cleaning all the datanodes.\n");
stop_datanode_master_all("immediate");
clean_datanode_master_all();
if (isVarYes(VAR_datanodeSlave))
{
stop_datanode_slave_all("immediate");
clean_datanode_slave_all();
}
}
else if (TestToken("all"))
{
GetToken();
if (token == NULL)
{
elog(INFO, "Stopping and cleaning all the datanodes.\n");
stop_datanode_master_all("immediate");
clean_datanode_master_all();
if (isVarYes(VAR_datanodeSlave))
{
stop_datanode_slave_all("immediate");
clean_datanode_slave_all();
}
}
else
{
char **nodeList = NULL;
elog(INFO, "Stopping and cleaning specified datanodes\n");
do
AddMember(nodeList, token);
while(GetToken());
stop_datanode_master(nodeList, "immediate");
clean_datanode_master(nodeList);
if (isVarYes(VAR_datanodeSlave))
{
stop_datanode_slave(nodeList, "immediate");
clean_datanode_slave(nodeList);
}
}
}
else if (TestToken("master"))
{
GetToken();
if (token == NULL)
{
elog(INFO, "Stopping and cleaning all the datanode masters.\n");
stop_datanode_master_all("immediate");
clean_datanode_master_all();
}
else
{
char **nodeList = NULL;
elog(INFO, "Stopping and cleaning specified datanode masters.\n");
do
AddMember(nodeList, token);
while (GetToken());
stop_datanode_master(nodeList, "immediate");
clean_datanode_master(nodeList);
CleanArray(nodeList);
}
}
else if (TestToken("slave"))
{
elog(INFO, "Stopping and cleaning specified datanode slaves.\n");
if (!isVarYes(VAR_datanodeSlave))
{
elog(ERROR, "ERROR: Datanode slave is not configured.\n");
return;
}
GetToken();
if (token == NULL)
{
stop_datanode_slave_all("immediate");
clean_datanode_slave_all();
}
else
{
char **nodeList = NULL;
do
AddMember(nodeList, token);
while (GetToken());
stop_datanode_slave(nodeList, "immediate");
clean_datanode_slave(nodeList);
CleanArray(nodeList);
}
}
else
{
char **nodeList = NULL;
do
AddMember(nodeList, token);
while (GetToken());
stop_datanode_master(nodeList, "immediate");
clean_datanode_master(nodeList);
if (isVarYes(VAR_datanodeSlave))
{
stop_datanode_slave(nodeList, "immediate");
clean_datanode_slave(nodeList);
}
CleanArray(nodeList);
}
}
else
{
elog(INFO, "Stopping and cleaning specifieid nodes.\n");
do
{
switch(getNodeType(token))
{
case NodeType_UNDEF:
elog(ERROR, "ERROR: %s is not found, skipping\n", token);
continue;
case NodeType_GTM:
elog(INFO, "Stopping and cleaning GTM master.\n");
if (cmdList == NULL)
cmdList = initCmdList();
addCmd(cmdList, prepare_stopGtmMaster());
addCmd(cmdList, prepare_cleanGtmMaster());
if (isVarYes(VAR_gtmSlave))
{
elog(INFO, "Stopping and cleaning GTM slave.\n");
addCmd(cmdList, prepare_stopGtmSlave());
addCmd(cmdList, prepare_cleanGtmSlave());
}
continue;
case NodeType_GTM_PROXY:
elog(INFO, "Stopping and cleaning GTM proxy %s.\n", token);
if (cmdList == NULL)
cmdList = initCmdList();
addCmd(cmdList, prepare_stopGtmProxy(token));
addCmd(cmdList, prepare_cleanGtmProxy(token));
continue;
case NodeType_COORDINATOR:
elog(INFO, "Stopping and cleaning coordinator master %s\n", token);
if (cmdList == NULL)
cmdList = initCmdList();
addCmd(cmdList, prepare_stopCoordinatorMaster(token, "immediate"));
addCmd(cmdList, prepare_cleanCoordinatorMaster(token));
if (isVarYes(VAR_coordSlave))
{
elog(INFO, "Stopping and cleaning coordinator slave %s\n", token);
addCmd(cmdList, prepare_stopCoordinatorSlave(token, "immediate"));
addCmd(cmdList, prepare_cleanCoordinatorSlave(token));
}
continue;
case NodeType_DATANODE:
elog(INFO, "Stopping and cleaning datanode master %s\n", token);
if (cmdList == NULL)
cmdList = initCmdList();
addCmd(cmdList, prepare_stopDatanodeMaster(token, "immediate"));
addCmd(cmdList, prepare_cleanDatanodeMaster(token));
if (isVarYes(VAR_coordSlave))
{
elog(INFO, "Stopping and cleaning datanode slave %s\n", token);
addCmd(cmdList, prepare_stopDatanodeSlave(token, "immediate"));
addCmd(cmdList, prepare_cleanDatanodeSlave(token));
}
continue;
case NodeType_SERVER:
elog(ERROR, "ERROR: clearing host is not supported yet. Skipping\n");
continue;
default:
elog(ERROR, "ERROR: internal error.\n");
continue;
}
} while(GetToken());
if (cmdList)
{
int rc;
rc = doCmdList(cmdList);
cleanCmdList(cmdList);
elog(INFO, "Done.\n");
}
return;
}
}
static void do_configure_command(char *line)
{
char *token;
char **nodeList = NULL;
if (!GetToken() || TestToken("all"))
{
configure_nodes_all();
}
else
{
bool is_datanode;
if (TestToken("datanode"))
is_datanode = true;
else if (TestToken("coordinator"))
is_datanode = false;
else
{
elog(ERROR, "ERROR: must specify either coordinator or datanode\n");
return;
}
while (GetToken())
AddMember(nodeList, token);
if (is_datanode)
configure_datanodes(nodeList);
else
configure_nodes(nodeList);
CleanArray(nodeList);
}
}
static int selectCoordinator(void)
{
int sz = arraySizeName(VAR_coordNames);
int i;
for (;;)
{
i = rand() % sz;
if (is_none(aval(VAR_coordMasterServers)[i]))
continue;
else
return i;
}
return -1;
}
static int show_Resource(char *datanodeName, char *databasename, char *username)
{
int cdIdx = selectCoordinator();
int dnIdx = datanodeIdx(datanodeName);
FILE *f;
char queryFname[MAXPATH+1];
elog(NOTICE, "NOTICE: showing tables in the datanode '%s', database %s, user %s\n",
datanodeName,
databasename ? databasename : "NULL",
username ? username : "NULL");
if (dnIdx < 0)
{
elog(ERROR, "ERROR: %s is not a datanode.\n", datanodeName);
return 1;
}
createLocalFileName(GENERAL, queryFname, MAXPATH);
if ((f = fopen(queryFname, "w")) == NULL)
{
elog(ERROR, "ERROR: Could not create temporary file %s, %s\n", queryFname, strerror(errno));
return 1;
}
fprintf(f,
"SELECT pg_class.relname relation,\n"
" CASE\n"
" WHEN pclocatortype = 'H' THEN 'Hash'\n"
" WHEN pclocatortype = 'M' THEN 'Modulo'\n"
" WHEN pclocatortype = 'N' THEN 'Round Robin'\n"
" WHEN pclocatortype = 'R' THEN 'Replicate'\n"
" ELSE 'Unknown'\n"
" END AS distribution,\n"
" pg_attribute.attname attname,\n"
" pgxc_node.node_name nodename\n"
" FROM pg_class, pgxc_class, pg_attribute, pgxc_node\n"
" WHERE pg_class.oid = pgxc_class.pcrelid\n"
" and pg_class.oid = pg_attribute.attrelid\n"
" and pgxc_class.pcattnum = pg_attribute.attnum\n"
" and pgxc_node.node_name = '%s'\n"
" and pgxc_node.oid = ANY (pgxc_class.nodeoids)\n"
" UNION\n"
" SELECT pg_class.relname relation,\n"
" CASE\n"
" WHEN pclocatortype = 'H' THEN 'Hash'\n"
" WHEN pclocatortype = 'M' THEN 'Modulo'\n"
" WHEN pclocatortype = 'N' THEN 'Round Robin'\n"
" WHEN pclocatortype = 'R' THEN 'Replicate'\n"
" ELSE 'Unknown'\n"
" END AS distribution,\n"
" '- none -' attname,\n"
" pgxc_node.node_name nodename\n"
" FROM pg_class, pgxc_class, pg_attribute, pgxc_node\n"
" WHERE pg_class.oid = pgxc_class.pcrelid\n"
" and pg_class.oid = pg_attribute.attrelid\n"
" and pgxc_class.pcattnum = 0\n"
" and pgxc_node.node_name = '%s'\n"
" and pgxc_node.oid = ANY (pgxc_class.nodeoids)\n"
" ;\n",
datanodeName, datanodeName);
fclose(f);
if (databasename == NULL)
doImmediateRaw("psql -p %d -h %s --quiet -f %s",
atoi(aval(VAR_coordPorts)[cdIdx]), aval(VAR_coordMasterServers)[cdIdx],
queryFname);
else if (username == NULL)
doImmediateRaw("psql -p %d -h %s --quiet -f %s -d %s",
atoi(aval(VAR_coordPorts)[cdIdx]), aval(VAR_coordMasterServers)[cdIdx],
queryFname, databasename);
else
doImmediateRaw("psql -p %d -h %s --quiet -f %s -d %s -U %s",
atoi(aval(VAR_coordPorts)[cdIdx]), aval(VAR_coordMasterServers)[cdIdx],
queryFname, databasename, username);
doImmediateRaw("rm -f %s", queryFname);
return 0;
}
/*
* =======================================================================================
*
* Loop of main command processor
*
* ======================================================================================
*/
void do_command(FILE *inf, FILE *outf)
{
int istty = ((inf == stdin) && isatty(fileno(stdin)));
int interactive = ((inf == stdin) && (outf == stdout));
char *wkline = NULL;
char buf[MAXLINE+1];
int rc;
char histfile[MAXPATH + 20];
#define HISTFILE ".pgxc_ctl_history"
histfile[0] = '\0';
if (pgxc_ctl_home[0] != '\0')
{
snprintf(histfile, MAXPATH + 20, "%s/%s", pgxc_ctl_home, HISTFILE);
read_history(histfile);
}
/*
* Set the long jump path so that we can come out straight here in case of
* an error. There is not much to reinitialize except may be freeing up the
* wkline buffer and resetting the long jump buffer pointer. But if
* anything else needs to reset, that should happen in the following block
*/
if (setjmp(dcJmpBufMainLoop) != 0)
{
whereToJumpMainLoop = NULL;
if (wkline)
freeAndReset(wkline);
}
for (;;)
{
if (wkline)
free(wkline);
if (istty)
{
wkline = readline(sval(VAR_xc_prompt));
if (wkline == NULL)
{
wkline = Strdup("q\n");
putchar('\n');
}
else if (wkline[0] != '\0')
add_history(wkline);
strncpy(buf, wkline, MAXLINE);
}
else
{
if (interactive)
fputs(sval(VAR_xc_prompt), stdout);
if (fgets(buf, MAXLINE+1, inf) == NULL)
break;
}
trimNl(buf);
writeLogOnly("PGXC %s\n", buf);
whereToJumpMainLoop = &dcJmpBufMainLoop;
rc = do_singleLine(buf, wkline);
whereToJumpMainLoop = NULL;
freeAndReset(wkline);
if (rc) /* "q" command was found */
{
if (histfile[0] != '\0')
write_history(histfile);
return;
}
}
}
/*
* ---------------------------------------------------------------------------
*
* Single line command processor
*
* -----------------------------------------------------------------------------
*/
int do_singleLine(char *buf, char *wkline)
{
char *token;
char *line = buf;
GetToken();
/*
* Parsecommand
*/
if (!token) return 0;
if (TestToken("q") || TestToken("quit") || TestToken("exit"))
/* Exit command */
return 1;
else if (TestToken("echo"))
{
do_echo_command(line);
return 0;
}
else if (TestToken("deploy"))
{
do_deploy(line);
return 0;
}
else if (TestToken("prepare"))
{
char *config_path = NULL;
ConfigType config_type = CONFIG_COMPLETE;
if (GetToken() != NULL)
{
if (TestToken("config"))
GetToken();
if (TestToken("empty"))
config_type = CONFIG_EMPTY;
else if (TestToken("minimal"))
config_type = CONFIG_MINIMAL;
else if (TestToken("complete"))
config_type = CONFIG_COMPLETE;
else if (token)
config_path = strdup(token);
if (GetToken() != NULL)
config_path = strdup(token);
}
do_prepareConfFile(config_path, config_type);
return 0;
}
else if (TestToken("kill"))
{
do_kill_command(line);
return 0;
}
else if (TestToken("init"))
{
do_init_command(line);
return 0;
}
else if (TestToken("start"))
{
do_start_command(line);
return 0;
}
else if (TestToken("stop"))
{
do_stop_command(line);
return 0;
}
else if (TestToken("monitor"))
{
do_monitor_command(line);
return 0;
}
else if (TestToken("failover"))
{
do_failover_command(line);
return 0;
}
else if (TestToken("reconnect"))
{
do_reconnect_command(line);
return 0;
}
else if (TestToken("add"))
{
do_add_command(line);
return 0;
}
else if (TestToken("remove"))
{
do_remove_command(line);
return 0;
}
/*
* Show commnand ... show [variable | var] varname ...
* show [variable | var] all
* show config[uration] ....
*/
else if (TestToken("show"))
{
if (GetToken() == NULL)
elog(ERROR, "ERROR: Please specify what to show\n");
else
{
if (TestToken("variable") || TestToken("var"))
{
/* Variable */
if (GetToken() == NULL)
elog(ERROR, "ERROR: Please specify variable name to print\n");
else if (TestToken("all"))
print_vars();
else while (line)
{
print_var(token);
GetToken();
}
}
else if (TestToken("configuration") || TestToken("config") || TestToken("configure"))
/* Configuration */
show_configuration(line);
else if (TestToken("resource"))
{
if ((GetToken() == NULL) || !TestToken("datanode"))
elog(ERROR, "ERROR: please specify datanode for show resource command.\n");
else
{
char *datanodeName = NULL;
char *dbname = NULL;
char *username = NULL;
if (GetToken() == NULL)
elog(ERROR, "ERROR: please specify datanode name\n");
else
{
datanodeName = Strdup(token);
if (GetToken())
{
dbname = Strdup(token);
if (GetToken())
username = Strdup(token);
}
show_Resource(datanodeName, dbname, username);
Free(datanodeName);
Free(dbname);
Free(username);
}
}
}
else
elog(ERROR, "ERROR: Cannot show %s now, sorry.\n", token);
}
return 0;
}
/*
* Log command log variable varname ...
* log variable all
* log msg artitrary_message_to_the_end_of_the_line
*/
else if (TestToken("log"))
{
if (GetToken() == NULL)
elog(ERROR, "ERROR: Please specify what to log\n");
else
{
if (TestToken("variable") || TestToken("var"))
{
if (GetToken() == NULL)
elog(ERROR, "ERROR: Please specify variable name to log\n");
else if (TestToken("all"))
print_vars();
else while (line)
{
print_var(token);
GetToken();
}
fflush(logFile);
}
else if (TestToken("msg") || TestToken("message"))
writeLogOnly("USERLOG: \"%s\"\n", line);
else
elog(ERROR, "ERROR: Cannot log %s in this version.\n", token);
}
return 0;
}
else if (TestToken("deploy"))
{
do_deploy(line);
return 0;
}
else if (TestToken("configure"))
{
do_configure_command(line);
return 0;
}
else if (testToken("Psql"))
{
int idx;
char *cmdLine;
cmdLine = Strdup(line);
if (GetToken() && TestToken("-"))
{
if (!GetToken())
elog(ERROR, "ERROR: Please specify coordinator name after '-'.\n");
else if ((idx = coordIdx(token)) < 0)
elog(ERROR, "ERROR: Specified node %s is not a coordinator.\n", token);
else
doImmediateRaw("psql -p %d -h %s %s",
atoi(aval(VAR_coordPorts)[idx]),
aval(VAR_coordMasterServers)[idx],
line);
}
else
{
idx = selectCoordinator();
elog(INFO, "Selected %s.\n", aval(VAR_coordNames)[idx]);
doImmediateRaw("psql -p %d -h %s %s",
atoi(aval(VAR_coordPorts)[idx]),
aval(VAR_coordMasterServers)[idx],
cmdLine);
}
Free(cmdLine);
return 0;
}
else if (testToken("Createdb"))
{
int idx;
char *cmdLine;
cmdLine = Strdup(line);
if (GetToken() && TestToken("-"))
{
if (!GetToken())
elog(ERROR, "ERROR: Please specify coordinator name after '-'.\n");
else if ((idx = coordIdx(token)) < 0)
elog(ERROR, "ERROR: Specified node %s is not a coordinator.\n", token);
else
doImmediateRaw("createdb -p %d -h %s %s",
atoi(aval(VAR_coordPorts)[idx]),
aval(VAR_coordMasterServers)[idx],
line);
}
else
{
idx = selectCoordinator();
elog(INFO, "Selected %s.\n", aval(VAR_coordNames)[idx]);
doImmediateRaw("createdb -p %d -h %s %s",
atoi(aval(VAR_coordPorts)[idx]),
aval(VAR_coordMasterServers)[idx],
cmdLine);
}
Free(cmdLine);
return 0;
}
else if (testToken("Createuser"))
{
int idx;
char *cmdLine;
cmdLine = Strdup(line);
if (GetToken() && TestToken("-"))
{
if (!GetToken())
elog(ERROR, "ERROR: Please specify coordinator name after '-'.\n");
else if ((idx = coordIdx(token)) < 0)
elog(ERROR, "ERROR: Specified node %s is not a coordinator.\n", token);
else
doImmediateRaw("createuser -p %d -h %s %s",
atoi(aval(VAR_coordPorts)[idx]),
aval(VAR_coordMasterServers)[idx],
line);
}
else
{
idx = selectCoordinator();
elog(INFO, "Selected %s.\n", aval(VAR_coordNames)[idx]);
doImmediateRaw("createuser -p %d -h %s %s",
atoi(aval(VAR_coordPorts)[idx]),
aval(VAR_coordMasterServers)[idx],
cmdLine);
}
Free(cmdLine);
return 0;
}
else if (TestToken("test"))
{
do_test(line);
return 0;
}
else if (TestToken("set"))
{
do_set(line);
return 0;
}
/*
* Clean command
*
* clean [all |
* gtm [ all | master | slave ] |
* gtm_proxy [ all | nodename ... ]
* coordinator [[all | master | slave ] [nodename ... ]] |
* datanode [ [all | master | slave] [nodename ... ]
*/
else if (TestToken("clean"))
{
do_clean_command(line);
}
else if (TestToken("cd"))
{
/*
* CD command
*/
if (GetToken() == NULL)
Chdir(pgxc_ctl_home, FALSE);
else
Chdir(token, FALSE);
return 0;
}
else if (TestToken("ssh"))
{
doImmediateRaw("%s", wkline);
}
else if (TestToken("help"))
{
do_show_help(line);
}
else
{
doImmediateRaw("%s", wkline);
return 0;
}
return 0;
}
static void
show_all_help()
{
printf("You are using pgxc_ctl, the configuration utility for PGXL\n"
"Type:\n"
" help <command>\n"
" where <command> is either add, Createdb, Createuser, clean,\n"
" configure, deploy, failover, init, kill, log, monitor,\n"
" prepare, q, reconnect, remove, set, show, start, \n"
" stop or unregister\n");
}
static void
do_show_help(char *line)
{
char *token;
GetToken();
if ((token == NULL) || TestToken("all"))
{
show_all_help();
return;
}
if (TestToken("add"))
{
printf(
"\n"
"add gtm slave slave_name host port dir\n"
"add gtm_proxy name host port dir\n"
"add coordinator master name host port pooler dir extra_conf extra_pghba\n"
"add coordinator slave name host port pooler dir archDir\n"
"add datanode master name host port pooler dir waldir restore_datanode_name extra_conf extra_pghba\n"
"add datanode slave name host port pooler dir waldir archDir\n"
"\n"
"Add the specified node to your postgres-xl cluster:\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("Createdb"))
{
printf(
"\n"
"Createdb [ - coordinator ] createdb_option ...\n"
"\n"
"Invokes createdb utility to create a new database using specified coordinator\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("Createuser"))
{
printf(
"\n"
"Createuser[ - coordinator ] createuser_option ...\n"
"\n"
"Invokes createuser utility to create a new user using specified coordinator\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("clean"))
{
printf(
"\n"
"clean all\n"
"clean gtm [all | master | slave]\n"
"clean gtm_proxy [all | nodename ... ]\n"
"clean coordinator [[all | master | slave ] [nodename ... ]]\n"
"clean datanode [[all | master | slave ] [nodename ... ]]\n"
"\n"
"Stop specified node in immediate mode and clean all resources including data directory\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("configure"))
{
printf("\n"
"configure all\n"
"configure datanode nodename ...\n"
"configure coordinator nodename ...\n"
"\n"
"Configure specified node with the node information and reload pooler information\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("deploy"))
{
printf(
"\n"
"deploy [ all | host ... ]\n"
"\n"
"Deploys postgres-xl binaries and other installation material to specified hosts\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("failover"))
{
printf(
"\n"
"failover [ gtm | coordinator nodename | datanode nodename | nodename ]\n"
"\n"
"Failover specified node to its master\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("init"))
{
printf(
"\n"
"init [force] all\n"
"init [force] nodename ...\n"
"init [force] gtm [ master | slave | all ]\n"
"init [force] gtm_proxy [ all | nodename ... ]\n"
"init [force] coordinator nodename ...\n"
"init [force] coordinator [ master | slave ] [ all | nodename ... ]\n"
"init [force] datanode nodename ...\n"
"init [force] datanode [ master | slave ] [ all | nodename ... ]\n"
"\n"
"Initializes specified nodes.\n"
" [force] option removes existing data directories even if they are not empty\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("kill"))
{
printf(
"\n"
"kill all\n"
"kill nodename ...\n"
"kill gtm [ master | slave | all ]\n"
"kill gtm_proxy [ all | nodename ... ]\n"
"kill coordinator nodename ...\n"
"kill coordinator [ master | slave ] [ all | nodename ... ]\n"
"kill datanode nodename ...\n"
"kill datanode [ master | slave ] [ all | nodename ... ]\n"
"\n"
"Kills specified node:\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("log"))
{
printf(
"\n"
"log [ variable | var ] varname\n"
"log [ message | msg ] message_body\n"
"\n"
"Prints the specified contents to the log file\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("monitor"))
{
printf(
"\n"
"monitor all\n"
"monitor nodename ...\n"
"monitor gtm [ master | slave | all ]\n"
"monitor gtm_proxy [ all | nodename ... ]\n"
"monitor coordinator nodename ...\n"
"monitor coordinator [ master | slave ] [ all | nodename ... ]\n"
"monitor datanode nodename ...\n"
"monitor datanode [ master | slave ] [ all | nodename ... ]\n"
"\n"
"Monitors if specified nodes are running\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("prepare"))
{
printf(
"\n"
"prepare [ path ]\n"
"\n"
"Write pgxc_ctl configuration file template to the specified file\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("Psql"))
{
printf(
"\n"
"Psql [ - coordinator ] psql_option ... \n"
"\n"
"Invokes psql targetted to specified coordinator\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("q"))
{
printf(
"\n"
"q | quit | exit\n"
"\n"
"Exits pgxc_ctl\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("reconnect"))
{
printf(
"\n"
"reconnect gtm_proxy [ all | nodename ... ]\n"
"\n"
"Reconnects specified gtm_proxy to new gtm\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("remove"))
{
printf(
"\n"
"remove gtm slave\n"
"remove gtm_proxy nodename [ clean ]\n"
"remove coordinator [ master| slave ] nodename [ clean ]\n"
"remove datanode [ master| slave ] nodename [ clean ]\n"
"\n"
"Removes the specified node from the cluster\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("set"))
{
printf(
"\n"
"set varname value ...\n"
"\n"
"Set variable value\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("show"))
{
printf(
"\n"
"show [ configuration | configure | config ] [ all | basic ]\n"
"show [ configuration | configure | config ] host hostname ... \n"
"show [ configuration | configure | config ] gtm [ all | master | slave ]\n"
"show [ configuration | configure | config ] gtm_proxy [ all | gtm_proxy_name ... ]\n"
"show [ configuration | configure | config ] [ coordinator | datanode ] [ all | master | slave ] nodename ...\n"
"\n"
"Shows postgres-xl configuration\n"
"\n"
"show resource datanode datanodename [ databasename [ username ] ]\n"
"\n"
"Shows table names specified datanode is involved\n"
"\n"
"show [ variable | var ] [ all | varname ... ]\n"
"\n"
"Displays configuration or variable name and its value\n"
"For more details, please see the pgxc_ctl documentation\n"
);
}
else if (TestToken("start"))
{
printf(
"\n"
"start all\n"
"start nodename ...\n"
"start gtm [ master | slave | all ]\n"
"start gtm_proxy [ all | nodename ... ]\n"
"start coordinator nodename ...\n"
"start coordinator [ master | slave ] [ all | nodename ... ]\n"
"start datanode nodename ...\n"
"start datanode [ master | slave ] [ all | nodename ... ]\n"
"\n"
"Starts specified node\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("stop"))
{
printf(
"\n"
"stop [ -m smart | fast | immediate ] all\n"
"stop gtm [ master | slave | all ]\n"
"stop gtm_proxy [ all | nodename ... ]\n"
"stop [ -m smart | fast | immediate ] coordinator nodename ... \n"
"stop [ -m smart | fast | immediate ] coordinator [ master | slave ] [ all | nodename ... ] \n"
"stop [ -m smart | fast | immediate ] datanode nodename ... \n"
"stop [ -m smart | fast | immediate ] datanode [ master | slave ] [ all | nodename ... ] \n"
"\n"
"Stops specified node\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else if (TestToken("unregister"))
{
printf(
"\n"
"unregister unregister_option ...\n"
"\n"
"Unregisteres specified node from the gtm\n"
"For more details, please see the pgxc_ctl documentation\n"
"\n"
);
}
else
{
printf(
"\n"
"Unrecognized command: such commands are sent to shell for execution\n"
"\n"
);
}
}
int
get_any_available_coord(int except)
{
int ii;
for (ii = 0; aval(VAR_coordMasterServers)[ii]; ii++)
{
if (ii == except)
continue;
if (!is_none(aval(VAR_coordMasterServers)[ii]))
{
if (pingNode(aval(VAR_coordMasterServers)[ii],
aval(VAR_coordPorts)[ii]) == 0)
return ii;
}
}
/*
* this could be the first coordinator that is being added.
* This call would happen *after* expanding the array to
* accomodate the new coordinator. Hence we check for size
* being more than 1
*/
if (arraySizeName(VAR_coordNames) > 1)
{
for (ii = 0; aval(VAR_coordNames)[ii]; ii++)
{
if (!is_none(aval(VAR_coordNames)[ii]))
{
elog(ERROR, "ERROR: failed to find any running coordinator");
return -1;
}
}
}
return -1;
}
int
get_any_available_datanode(int except)
{
int ii;
for (ii = 0; aval(VAR_datanodeMasterServers)[ii]; ii++)
{
if (ii == except)
continue;
if (!is_none(aval(VAR_datanodeMasterServers)[ii]))
{
if (pingNode(aval(VAR_datanodeMasterServers)[ii],
aval(VAR_datanodePorts)[ii]) == 0)
return ii;
}
}
/*
* this could be the first datanode that is being added.
* This call would happen *after* expanding the array to
* accomodate the new datanode. Hence we check for size
* being more than 1
*/
if (arraySizeName(VAR_datanodeNames) > 1)
{
for (ii = 0; aval(VAR_datanodeNames)[ii]; ii++)
{
if (!is_none(aval(VAR_datanodeNames)[ii]))
{
elog(ERROR, "ERROR: failed to find any running datanode");
return -1;
}
}
}
return -1;
}
|