-
Notifications
You must be signed in to change notification settings - Fork 0
/
Useful_Info
2162 lines (1509 loc) · 64.6 KB
/
Useful_Info
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
def cmp(a, b):
return (a > b) - (a < b)
nTestCases = input()
resList = []
print("no of Test Cases: ",nTestCases)
for x in range(int(nTestCases)):
nHouses = input()
ticket = input()
ticket = ticket.split()
ind = 0
flag = 0
tSize = len(ticket)
for x in range(tSize):
if flag == 0:
if int(ticket[ind]) == 0:
del ticket[ind]
else:
flag = 1
ticket[ind] = int(ticket[ind])
ind = ind + 1
else:
ticket[ind] = int(ticket[ind])
ind = ind + 1
if len(ticket) == 0:
resList.append(0)
else:
tSize = len(ticket)
included_map = dict()
excluded_map = dict()
l_list1 = [ticket[0]]
l_list2 = list()
included_map[0] = l_list1
excluded_map[0] = l_list2
g_includedSum = int(ticket[0])
g_excludedSum = -1001
for x in range(tSize):
x = int(x)
includedSum=g_includedSum
excludedSum=g_excludedSum
if ticket[x] != 0:
g_includedSum = max(-1002, ticket[x], ticket[x]+excludedSum)
if g_includedSum == ticket[x]:
included_map[x].append(ticket[x])
else:
included_map[x]=excluded_map[x-1]
included_map[x].append(ticket[x])
g_excludedSum = max(-1002,excludedSum,includedSum)
if g_excludedSum == excludedSum:
excluded_map[x] = excluded_map[x-1]
#else:
# excluded_map[x] = included_map[x-1]
else:
g_excludedSum=maxSum(excludedSum,includedSum)
if g_excludedSum == excludedSum:
excluded_map[x]=excluded_map[x-1]
else:
excluded_map[x]=included_map[x-1]
included_map[x]=included_map[x-1]
if(g_includedSum > g_excludedSum):
ref = included_map[tSize-1];
ref.reverse()
l_res = " ".join(str(resStr) for resStr in ref)
resList.append(l_res)
elif g_includedSum < g_excludedSum:
ref = excluded_map[tSize-1]
ref.reverse()
l_res = " ".join(str(resStr) for resStr in ref)
resList.append(l_res)
else:
resCode = cmp(included_map[tSize-1], excluded_map[tSize-1])
if resCode == 1:
ref = included_map[tSize-1];
ref.reverse()
l_res = " ".join(str(resStr) for resStr in ref)
resList.append(l_res)
else:
ref = excluded_map[tSize-1];
ref.reverse()
l_res = " ".join(str(resStr) for resStr in ref)
resList.append(l_res)
for x in resList:
print(x)
code forces 1
#include<iostream>
#include<vector>
#include<unistd.h>
#include<string>
#include<sstream>
#include<iterator>
#include<assert.h>
using namespace std;
int main()
{
int T;
cin>>T;
vector<int>result;
for(int i=0;i<T;++i)
{
vector<int> arr;
int n;
cin>>n;
int prev=-1,curr;
bool sorted=true;
for(int j=0;j<n;++j)
{
cin>>curr;
if(curr<prev)
sorted=false;
prev=curr;
arr.push_back(curr);
}
if(sorted)
{
result.push_back(n);
continue;
}
int l_result=0;
while(!sorted)
{
if(n==1)
{
l_result = 1;
break;
}
n=n/2;
assert(n!=0);
int n_loops=arr.size()/n;
for(int j=0;j<n_loops;++j)
{
int start_index=j*2;
int stop_index=(j+1)*2;
prev=-1;
for(int k=start_index;k<stop_index;++k)
{
if(arr[k]<prev)
{
sorted = false;
break;
}
else
sorted = true;
prev=arr[k];
}
if(sorted)
l_result = n;
}
}
result.push_back(l_result);
}
for(auto&x:result)
cout<<endl<<x<<endl;
return 0;
}
techgig 2
#include<iostream>
#include<vector>
#include<map>
using namespace std;
int64_t maxSum(int64_t a,int64_t b)
{
return (a>b?a:b);
}
int main()
{
int64_t T;
cin>>T;
vector<string>result;
for(int t=0;t<T;++t)
{
int64_t N;
cin>>N;
map<int,vector<int> >included_map,excluded_map;
vector<int64_t>included_sum,excluded_sum;
bool firstNonZeroFlag=false;
vector<int>ticket;
for(int n=0;n<N;++n)
{
int temp;
cin>>temp;
//This ensures that our vector's first element will be non zero
if(firstNonZeroFlag==false && temp !=0)
{
firstNonZeroFlag=true;
}
if(firstNonZeroFlag)
ticket.push_back(temp);
}
//If all inputs are zero(added for extra safety although not required)
if(firstNonZeroFlag==false)
{
result.push_back(to_string(0));
continue;
}
included_sum.push_back(ticket[0]);
excluded_sum.push_back(-1001);
{
vector<int>temp;
temp.push_back(ticket[0]);
included_map[0]=temp;
}
for(int n=1;n<N;++n)
{
int64_t includedSum,excludedSum;
if(ticket[n]!=0)
{
includedSum=maxSum(ticket[n], ticket[n]+excluded_sum[n-1]);
included_sum.push_back(includedSum);
if(includedSum==ticket[n])
{
vector<int> temp;
temp.push_back(ticket[n]);
included_map[n]=temp;
}
else
{
vector<int> temp;
temp=excluded_map[n-1];
temp.push_back(ticket[n]);
included_map[n]=temp;
}
excludedSum=maxSum(excluded_sum[n-1],included_sum[n-1]);
excluded_sum.push_back(excludedSum);
if(excludedSum==excluded_sum[n-1])
excluded_map[n]=excluded_map[n-1];
else
excluded_map[n]=included_map[n-1];
}
else
{
excludedSum=maxSum(excluded_sum[n-1],included_sum[n-1]);
excluded_sum.push_back(excludedSum);
if(excludedSum==excluded_sum[n-1])
excluded_map[n]=excluded_map[n-1];
else
excluded_map[n]=included_map[n-1];
included_sum.push_back(included_sum[n-1]);
included_map[n]=included_map[n-1];
}
cout<<endl<<"n = "<<n<<endl;
cout<<endl<<"printing included map"<<endl;
for(auto&x : included_map[n])
cout<<x;
cout<<endl<<"printing excluded map"<<endl;
for(auto&x : excluded_map[n])
cout<<x;
}
//case 1 included_sum[N-1] > excluded_sum[N-1]
if(included_sum[N-1] > excluded_sum[N-1])
{
printf("\n[%s::%d] case 1 included_sum[N-1] > excluded_sum[N-1]\n",__FILE__,__LINE__);
string temp;
for(auto&x:included_sum)
temp=to_string(x)+temp;
result.push_back(temp);
}
//case 2 included_sum[N-1] < excluded_sum[N-1]
else if(included_sum[N-1] < excluded_sum[N-1])
{
printf("\n[%s::%d] case 2 included_sum[N-1] < excluded_sum[N-1]\n",__FILE__,__LINE__);
string temp;
for(auto&x:excluded_sum)
temp=to_string(x)+temp;
result.push_back(temp);
}
//case 3 included_sum[N-1] == excluded_sum[N-1]
else
{
printf("\n[%s::%d] case 3 included_sum[N-1] == excluded_sum[N-1]\n",__FILE__,__LINE__);
int i,j;
vector<int>& inc=included_map[N-1];
vector<int>& exc=excluded_map[N-1];
for(i=inc.size()-1, j= exc.size()-1;i>=0;--i)
{
//case 1
if(inc[i]>exc[j])
{
printf("\n[%s::%d] case 1\n",__FILE__,__LINE__);
string temp;
for(auto&x:inc)
temp=to_string(x)+temp;
result.push_back(temp);
break;
}
//case 2
else if(inc[i]<exc[j])
{
printf("\n[%s::%d] case 2\n",__FILE__,__LINE__);
string temp;
for(auto&x:exc)
temp=to_string(x)+temp;
result.push_back(temp);
break;
}
//case 3
else
{
printf("\n[%s::%d] case 3\n",__FILE__,__LINE__);
--j;
continue;
}
}
}
}
for(auto&x: result)
cout<<x<<endl;
return 0;
}
techgig 1
#include<iostream>
#include<vector>
#include<algorithm>
using std::cout;
using std::vector;
using std::string;
using std::cin;
using std::endl;
int main()
{
int t,n;
vector<string> win_flag;
vector<int>s_v,s_p;
cin>>t;
for(int i=0;i<t;i++)
{
cin>>n;
for(int j=0;j<n;j++)
{
int temp;
cin>>temp;
s_v.push_back(temp);
}
for(int j=0;j<n;j++)
{
int temp;
cin>>temp;
s_p.push_back(temp);
}
sort(s_v.begin(), s_v.end());
sort(s_p.begin(), s_p.end());
int l_count=0;
for(int i=0;i<n;i++)
{
if(s_v[i]>s_p[i])
{
l_count=-1;
win_flag.push_back("LOSE");
break;
}
}
if(l_count==0)
win_flag.push_back("WIN");
}
for(auto&x:win_flag)
cout<<x<<endl;
return 0;
}
HIREDIS SAMPLE CODE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<unistd.h>
#include <hircluster.h>
#include<iostream>
using namespace std;
int main(int argc, char **argv)
{
struct timeval timeout = { 1, 500000 }; // 1.5 seconds
redisClusterContext *cc = redisClusterContextInit();
redisClusterSetOptionAddNodes(cc, "172.16.129.68:6380");
redisClusterSetOptionConnectTimeout(cc, timeout);
redisClusterSetOptionRouteUseSlots(cc);
redisClusterConnect2(cc);
if (cc != NULL && cc->err)
{
printf("Error: %s\n", cc->errstr);
// handle error
exit(-1);
}
/*
//To print all the master nodes
print_cluster_node_list(cc);
*/
/*
//Finding hash slot of the key
unsigned int key_slot=keyHashSlot("temp", 4);
cout<<"Key slot for temp: "<<key_slot<<endl;
redisReply *reply;
reply = (redisReply*)(redisClusterCommand(cc,"cluster nodes"));
if (cc != NULL && cc->err)
printf("Error: %s\n", cc->errstr);
else
printf("cluster nodes: %s\n", reply->str);
freeReplyObject(reply);
*/
/*
// Set a hash map
redisReply *reply;
reply = (redisReply*)(redisClusterCommand(cc,"hmset test_hash bin1_name bin1_value bin2_name bin2_value bin3_name bin3_val"));
if (cc != NULL && cc->err)
printf("Error: %s\n", cc->errstr);
else
printf("Status: %s\n", reply->str);
freeReplyObject(reply);
*/
/*
// Get the complete hash map
redisReply *reply;
reply = (redisReply*)(redisClusterCommand(cc,"hgetall test_hash"));
if (cc != NULL && cc->err)
printf("Error: %s\n", cc->errstr);
else
{
cout<<endl<<"reply type: "<<reply->type<<endl;
if (reply->type == REDIS_REPLY_ARRAY)
{
for (int j = 0; j < reply->elements; j++)
{
printf("%u) %s\n", j, reply->element[j]->str);
}
}
}
freeReplyObject(reply);
*/
//Get specific bins of hash map
redisReply *reply;
reply = (redisReply*)(redisClusterCommand(cc,"hmget test_hash bin1_name bin3_name"));
if (cc != NULL && cc->err)
printf("Error: %s\n", cc->errstr);
else
{
cout<<endl<<"reply type: "<<reply->type<<endl;
if (reply->type == REDIS_REPLY_ARRAY)
{
for (int j = 0; j < reply->elements; j++)
{
printf("%u) %s\n", j, reply->element[j]->str);
}
}
}
freeReplyObject(reply);
/*
// PING server //
while(1)
{
reply = (redisReply*)(redisClusterCommand(cc,"PING"));
if (cc != NULL && cc->err)
printf("Error: %s\n", cc->errstr);
else
printf("PING: %s\n", reply->str);
freeReplyObject(reply);
}
*/
/*
// GET key //
while(1)
{
sleep(3);
reply = (redisReply*)(redisClusterCommand(cc,"GET foo"));
if (cc != NULL && cc->err)
printf("Error: %s\n", cc->errstr);
else
printf("GET foo: %s\n", reply->str);
freeReplyObject(reply);
}
*/
/*
// Set a key //
reply = (redisReply*)(redisClusterCommand(cc,"SET %s %s", "foo", "hello vishal"));
if(cc->err)
printf("\n[%s::%d]Error: %s\n", __FILE__,__LINE__,cc->errstr);
else
printf("SET: %s\n", reply->str);
freeReplyObject(reply);
*/
/*
// Set a key using binary safe API //
reply = (redisReply*)redisClusterCommand(cc,"SET %b %b", "bar", (size_t) 3, "hello", (size_t) 5);
printf("SET (binary API): %s\n", reply->str);
freeReplyObject(reply);
// Try a GET and two INCR //
reply = (redisReply*)redisClusterCommand(cc,"GET foo");
printf("GET foo: %s\n", reply->str);
freeReplyObject(reply);
reply = (redisReply*)redisClusterCommand(cc,"INCR counter");
printf("INCR counter: %lld\n", reply->integer);
freeReplyObject(reply);
// again ... //
reply = (redisReply*)redisClusterCommand(cc,"INCR counter");
printf("INCR counter: %lld\n", reply->integer);
freeReplyObject(reply);
// Create a list of numbers, from 0 to 9 //
reply = (redisReply*)redisClusterCommand(cc,"DEL mylist");
freeReplyObject(reply);
for (j = 0; j < 10; j++)
{
char buf[64];
snprintf(buf,64,"%d",j);
reply = (redisReply*)redisClusterCommand(cc,"LPUSH mylist element-%s", buf);
freeReplyObject(reply);
}
// Let's check what we have inside the list //
reply = (redisReply*)redisClusterCommand(cc,"LRANGE mylist 0 -1");
if (reply->type == REDIS_REPLY_ARRAY)
{
for (j = 0; j < reply->elements; j++)
{
printf("%u) %s\n", j, reply->element[j]->str);
}
}
freeReplyObject(reply);
*/
// Disconnects and frees the context //
redisClusterFree(cc);
return 0;
}
ns1.cp-ht-9.webhostbox.net
ns2.cp-ht-9.webhostbox.net
OJV-359-30749(ticket no)
673 footprints niti khand 2
email account: [email protected]
password: Password@5
dsscokhla.com/cpanel
username dsscoplb
password +@~M7^3+RrZk
database name: dsscoplb_sailing_club_db_2992018
user name: dsscoplb_cptnav
password: Password@9
wordpress admin user name:
dsscokhla_sailing_club_cptnav2992018
password: Password@cptnav2992018
Database Name: wp236(old) wp764(new)
Table prefix: wpgf_(old) wpkm_(new)
wordpress administrative url: http://dsscokhla.com/wp/wp-admin/
Linux Commands
To find the resources consumed by each thread of a pid
top -p PID -H
To find port forwarding in linux gateway
Ps –ef | grep fnNl(or just fn)
To find info about cpu (lscpu)
To find bits of OS(getconf LONG_BIT or uname -a)
To monitor system metrics
dstat -lrvn 10
finding number of java applications running on linux
ps -ef | grep "[j]ava" | wc –l
finding pid of running java applications
ps aux | grep java
finding info from pid
ps -p 3339 -o comm=
To create a user account from a shell prompt:
1. Open a shell prompt.
2. If you are not logged in as root, type the command su - and enter the root password.
3. Type useradd followed by a space and the username for the new account you are creating at the command line (for example, useradd jsmith). Press [Enter]. Often, usernames are variations on the user's name, such as jsmith for John Smith. User account names can be anything from the user's name, initials, or birthplace to something more creative.
4. Type passwd followed by a space and the username again (for example, passwd jsmith).
5. At the New password: prompt enter a password for the new user and press [Enter].
6. At the Retype new password: prompt, enter the same password to confirm your selection.
Route –n command will tell about the default gateway of the subnet.
http://cassandra.apache.org/doc/latest/operating/index.html
Datastax’s C++ driver mailing list
https://groups.google.com/a/lists.datastax.com/forum/#!newtopic/cpp-driver-user
To Increase CQL timeout
Edit cqlsh.py file in bin folder. Modify the DEFAULT_REQUEST_TIMEOUT_SECONDS.
Installing Cassandra
(open ports 7000 and 9160)
1. Install latest stable JDK package from oracle website.(to check java version type “java –version”
Install the jdk rpm package by using below given command.
rpm -ivh jdk-8u45-linux-x64.rpm
2. Download and extract apache-cassandra tar.gz file in a directory of your choice(download from “http://www-eu.apache.org/dist/cassandra/” or “http://cassandra.apache.org/download/”.
(to extract) tar -zxvf apache-cassandra-3.9-bin.tar.gz
3. Next is to create necessary directories (for cassandra to store data) and assign permissions on those directories.
mkdir /var/lib/cassandra/data
mkdir /var/log/cassandra
mkdir /var/lib/cassandra/commitlog
chown -R cassandra:cassandra /var/lib/cassandra/data
chown -R cassandra:cassandra /var/log/cassandra/
chown -R cassandra:cassandra /var/lib/cassandra/commitlog
Installing C++ driver
1. Install rpm “libuv-1.13.1-1.el6.x86_64.rpm” by rpm –ivh libuv-1.13.1-1.el6.x86_64.rpm
2. Install rpm –ivh libuv-devel-1.13.1-1.el6.x86_64.rpm
3. Install rpm –ivh cassandra-cpp-driver-2.7.0-1.el6.x86_64.rpm
4. Install rpm –ivh cassandra-cpp-driver-devel-2.7.0-1.el6.x86_64.rpm
The libraries will be installed at /usr/lib64 and the header file at /usr/include
To synchronize time between different servers
Vi /etc/ntp.conf
Add the following line
Server ip iburst
Replace ip in above command with the ip address of the server with which you want to sync time.
And then use following command
/etc/init.d/ntpd restart
https://www.rootusers.com/how-to-synchronize-time-in-linux-with-ntp-peers/
Taking backup of a node
To fully restore data, you must have a complete backup, which consists of the following:
• A snapshot at a point in time
• All incremental backups from the time you took the snapshot
• All commitlog segments since the time you took the last incremental
backup
Cassandra can only restore data from a snapshot when the table schema exists. If the schema does not exist and has not been backed up, you must recreate the schema.
First take backup of schema via
./cqlsh 172.16.128.130 -e "DESC SCHEMA" > db_schema.cql
To recreate the schema,
./cqlsh 172.16.128.130 -e "SOURCE '/home/cass/share/cassandra/data/hss_1/subscriber_master_table-abd04bf00c9711e8b214c75879db7963/snapshots/1518439698119/schema.cql'"
1.The nodetool clearsnapshot command removes all existing snapshot files from the snapshot directory of each keyspace. You should make it part of your back-up process to clear old snapshots before taking a new one.
./nodetool clearsnapshot
2. To take snapshot of all the keyspaces on a node:
./nodetool snapshot
The snapshot is created in data_directory/keyspace_name/table_name-UUID/snapshots/snapshot_name directory.
3. To use the snapshot, copy all the snapshot files into the data/keyspace/table-uuid folder
e.g. cp snapshots/1303701623423/* /home/cass/share/cassandra/data/hss_1/subscriber_master_table-abd04bf00c9711e8b214c75879db7963/
(here hss_1 is the keyspace and subscriber_master_table is the table name)
4. If incremental_backups was set as true in yaml, copy all the files in the data/keyspace/table-uuid/backup/ folder into data/keyspace/table-uuid/.
5. Run the nodetool refresh command, specifying the keyspace and table name.
./nodetool refresh hss_1 subscriber_master_table
6. Run nodetool repair at the end on all replicas.
The snapshots and incremental backup files are not automatically deleted, therefore you’ll have to manually delete the older backup files.
To restore a node from a snapshot and incremental backups:
1. Shut down the node to be restored.
2. Clear all files the /var/lib/cassandra/commitlog (by default).
3. Clear all *.db files in <data_directory_location>/<keyspace_name>, but DO NOT delete the /snapshots and /backupssubdirectories.
4. Locate the most recent snapshot folder in <data_directory_location>/<keyspace_name>/snapshots/<snapshot_name>, and copy its contents into <data_directory_location>/<keyspace_name>.
5. If using incremental backups as well, copy all contents of <data_directory_location>/<keyspace_name>/backups into <data_directory_location>/<keyspace_name>.
6. Restart the node, keeping in mind that a temporary burst of I/O activity will consume a large amount of CPU resources.
Restoring a snapshot into a new cluster
(When we have to recover data from a snapshot from some other cluster into some new cluster)
First we have to setup the new cluster with exact same settings as were there in the older cluster. Also we’ll have to use the same tokens for each of the nodes.
1. In the yaml file, uncomment the ‘initial_token’ and specify the tokens you want the node to use. Also make sure all other configurations are same as before.
2. Delete all the data from data/system folder i.e. rm –rf *
3. Start the node.
4. All the schemas from the old cluster must be reproduced in the new cluster.
5. Stop the node.
6. Copy all the files from the snapshot directory into the relevant table’s directory in the new cluster.
7. Restart the node.
Adding a new node
Edit the topology files of all nodes. Start the new node and then run nodetool repair on all nodes after the new node has been added. Lastly, run nodetool cleanup.
https://stackoverflow.com/questions/24559907/cassandra-avoid-nodetool-cleanup
Replacing a dead node
In order to replace a dead node, start cassandra with the JVM startup flag -Dcassandra.replace_address_first_boot=<dead_node_ip>. Once this property is enabled the node starts in a hibernate state, during which all the other nodes will see this node to be down.
The replacing node will now start to bootstrap the data from the rest of the nodes in the cluster. The main difference between normal bootstrapping of a new node is that this new node will not accept any writes during this phase.
Once the bootstrapping is complete the node will be marked “UP”, we rely on the hinted handoff’s for making this node consistent (since we don’t accept writes since the start of the bootstrap).
Note
If the replacement process takes longer than max_hint_window_in_ms you MUST run repair to make the replaced node consistent again, since it missed ongoing writes during bootstrapping.
Insufficient user resource limit errors
https://docs.datastax.com/en/archived/cassandra/2.0/cassandra/troubleshooting/trblshootInsufficientResources_r.html
check current values by “ulimit –a”
change values(if any):
vim /etc/security/limits.conf
cass soft nofile 32768
cass hard nofile 32768
cass soft memlock unlimited
cass hard memlock unlimited
cass soft as unlimited
cass hard as unlimited
Decommissioning a node
Decommissioning a node will copy it’s data to other nodes. Use “./nodetool decommission”.
Changing rack/dc of a node
stop the node, change the rack/dc in the relevant configuration files and then restart the node with the flags: -Dcassandra.ignore_dc=true -Dcassandra.ignore_rack=true
Copying data from CQL