-
Notifications
You must be signed in to change notification settings - Fork 17
/
exported_functions.go
797 lines (651 loc) · 23.4 KB
/
exported_functions.go
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
package supervisor
import (
"fmt"
"net"
"sync/atomic"
"time"
"github.com/couchbase/eventing/common"
couchbase "github.com/couchbase/eventing/dcp"
"github.com/couchbase/eventing/logging"
"github.com/couchbase/eventing/util"
"github.com/couchbase/gocb/v2"
)
// ClearEventStats flushes event processing stats
func (s *SuperSupervisor) ClearEventStats() []string {
appNames := make([]string, 0)
for appName, p := range s.runningFns() {
appNames = append(appNames, appName)
p.ClearEventStats()
}
return appNames
}
// DeployedAppList returns list of deployed lambdas running under super_supervisor
func (s *SuperSupervisor) DeployedAppList() []string {
appList := make([]string, 0)
for app := range s.runningFns() {
appList = append(appList, app)
}
return appList
}
// GetEventProcessingStats returns dcp/timer event processing stats
func (s *SuperSupervisor) GetEventProcessingStats(appName string) map[string]uint64 {
if p, ok := s.runningFns()[appName]; ok {
return p.GetEventProcessingStats()
}
return nil
}
// GetAppCode returns handler code for requested appname
func (s *SuperSupervisor) GetAppCode(appName string) string {
logPrefix := "SuperSupervisor::GetAppCode"
logging.Infof("%s [%d] Function: %s request function code", logPrefix, s.runningFnsCount(), appName)
if p, ok := s.runningFns()[appName]; ok {
return p.GetAppCode()
}
return ""
}
// GetDebuggerURL returns the v8 debugger url for supplied appname
func (s *SuperSupervisor) GetDebuggerURL(appName string) (string, error) {
logPrefix := "SuperSupervisor::GetDebuggerURL"
logging.Debugf("%s [%d] Function: %s request for debugger URL", logPrefix, s.runningFnsCount(), appName)
if p, ok := s.runningFns()[appName]; ok {
return p.GetDebuggerURL()
}
return "", fmt.Errorf("App %s not running", appName)
}
// GetDeployedApps returns list of deployed apps and their last deployment time
func (s *SuperSupervisor) GetDeployedApps() map[string]string {
s.appListRWMutex.RLock()
defer s.appListRWMutex.RUnlock()
deployedApps := make(map[string]string)
for app, timeStamp := range s.deployedApps {
deployedApps[app] = timeStamp
}
return deployedApps
}
// GetLatencyStats dumps stats from cpp world
func (s *SuperSupervisor) GetLatencyStats(appName string) common.StatsData {
if p, ok := s.runningFns()[appName]; ok {
return p.GetLatencyStats()
}
return nil
}
func (s *SuperSupervisor) GetCurlLatencyStats(appName string) common.StatsData {
if p, ok := s.runningFns()[appName]; ok {
return p.GetCurlLatencyStats()
}
return nil
}
func (s *SuperSupervisor) GetInsight(appName string) *common.Insight {
logPrefix := "SuperSupervisor::GetInsight"
if p, ok := s.runningFns()[appName]; ok {
if insight := p.GetInsight(); insight != nil {
logging.Debugf("%s [%d] Function: %s insight is %ru", logPrefix, s.runningFnsCount(), appName, insight)
return insight
}
}
return common.NewInsight() // empty if error
}
// GetLocallyDeployedApps returns list of deployed apps and their last deployment time
func (s *SuperSupervisor) GetLocallyDeployedApps() map[string]string {
s.appListRWMutex.RLock()
defer s.appListRWMutex.RUnlock()
locallyDeployedApps := make(map[string]string)
for app, timeStamp := range s.locallyDeployedApps {
locallyDeployedApps[app] = timeStamp
}
return locallyDeployedApps
}
// GetExecutionStats returns aggregated failure stats from Eventing.Producer instance
func (s *SuperSupervisor) GetExecutionStats(appName string) map[string]interface{} {
if p, ok := s.runningFns()[appName]; ok {
return p.GetExecutionStats()
}
return nil
}
// GetFailureStats returns aggregated failure stats from Eventing.Producer instance
func (s *SuperSupervisor) GetFailureStats(appName string) map[string]interface{} {
if p, ok := s.runningFns()[appName]; ok {
return p.GetFailureStats()
}
return nil
}
// GetLcbExceptionsStats returns libcouchbase exception stats from CPP workers
func (s *SuperSupervisor) GetLcbExceptionsStats(appName string) map[string]uint64 {
p, ok := s.runningFns()[appName]
if ok {
return p.GetLcbExceptionsStats()
}
return nil
}
// GetSeqsProcessed returns vbucket specific sequence nos processed so far
func (s *SuperSupervisor) GetSeqsProcessed(appName string) map[int]int64 {
if p, ok := s.runningFns()[appName]; ok {
return p.GetSeqsProcessed()
}
return nil
}
// Gets the cluster url and pool supervisor is observing ns_server changes on.
func (s *SuperSupervisor) GetRegisteredPool() string {
return s.hostport + "-" + s.pool
}
// RestPort returns ns_server port(typically 8091/9000)
func (s *SuperSupervisor) RestPort() string {
return s.restPort
}
func (s *SuperSupervisor) ResetCounters(appName string) error {
p, ok := s.runningFns()[appName]
if ok {
p.ResetCounters()
return nil
}
return fmt.Errorf("No function named %v registered by supervisor")
}
// SignalStopDebugger stops V8 Debugger for a specific deployed lambda
func (s *SuperSupervisor) SignalStopDebugger(appName string) error {
p, ok := s.runningFns()[appName]
if !ok {
return fmt.Errorf("Producer %s not running", appName)
}
err := p.SignalStopDebugger()
if err != nil {
return err
}
return nil
}
// GetAppCompositeState returns current state of app
func (s *SuperSupervisor) GetAppCompositeState(appName string) int8 {
s.appRWMutex.RLock()
defer s.appRWMutex.RUnlock()
dStatus := s.appDeploymentStatus[appName]
pStatus := s.appProcessingStatus[appName]
return common.GetCompositeState(dStatus, pStatus)
}
// GetDcpEventsRemainingToProcess returns remaining dcp events to process
func (s *SuperSupervisor) GetDcpEventsRemainingToProcess(appName string) uint64 {
logPrefix := "SuperSupervisor::GetDcpEventsRemainingToProcess"
p, ok := s.runningFns()[appName]
if ok {
return p.GetDcpEventsRemainingToProcess()
}
logging.Errorf("%s [%d] Function: %s request didn't go through as Eventing.Producer instance isn't alive",
logPrefix, s.runningFnsCount(), appName)
return 0
}
// VbDcpEventsRemainingToProcess returns remaining dcp events to process
func (s *SuperSupervisor) VbDcpEventsRemainingToProcess(appName string) map[int]int64 {
logPrefix := "SuperSupervisor::VbDcpEventsRemainingToProcess"
p, ok := s.runningFns()[appName]
if ok {
return p.VbDcpEventsRemainingToProcess()
}
logging.Errorf("%s [%d] Function: %s request didn't go through as Eventing.Producer instance isn't alive",
logPrefix, s.runningFnsCount(), appName)
return nil
}
// GetEventingConsumerPids returns map of Eventing.Consumer worker name and it's os pid
func (s *SuperSupervisor) GetEventingConsumerPids(appName string) map[string]int {
logPrefix := "SuperSupervisor::GetEventingConsumerPids"
p, ok := s.runningFns()[appName]
if ok {
return p.GetEventingConsumerPids()
}
logging.Errorf("%s [%d] Function: %s request didn't go through as Eventing.Producer instance isn't alive",
logPrefix, s.runningFnsCount(), appName)
return nil
}
// Last ditch effort to kill all consumers
func (s *SuperSupervisor) KillAllConsumers() {
for _, p := range s.runningProducers {
p.KillAllConsumers()
}
}
// InternalVbDistributionStats returns internal state of vbucket ownership distribution on local eventing node
func (s *SuperSupervisor) InternalVbDistributionStats(appName string) map[string]string {
p, ok := s.runningFns()[appName]
if ok {
return p.InternalVbDistributionStats()
}
return nil
}
// VbDistributionStatsFromMetadata returns vbucket distribution across eventing nodes from metadata bucket
func (s *SuperSupervisor) VbDistributionStatsFromMetadata(appName string) map[string]map[string]string {
p, ok := s.runningFns()[appName]
if ok {
return p.VbDistributionStatsFromMetadata()
}
return nil
}
// PlannerStats returns vbucket distribution as per planner running on local eventing
// node for a given app
func (s *SuperSupervisor) PlannerStats(appName string) []*common.PlannerNodeVbMapping {
p, ok := s.runningFns()[appName]
if ok {
return p.PlannerStats()
}
return nil
}
// RebalanceTaskProgress reports vbuckets remaining to be transferred as per planner
// during the course of rebalance
func (s *SuperSupervisor) RebalanceTaskProgress(appName string) (*common.RebalanceProgress, error) {
p, ok := s.runningFns()[appName]
if ok {
return p.RebalanceTaskProgress(), nil
}
_, err := s.isFnRunningFromPrimary(appName)
if err != nil {
return nil, err
}
progress := &common.RebalanceProgress{}
// report rebalance progress for yet-to-bootstrap-apps only if node is still part of cluster
if s.checkIfNodeInCluster() {
progress.VbsRemainingToShuffle = 1
}
return progress, nil
}
// TimerDebugStats captures timer related stats to assist in debugging mismtaches during rebalance
func (s *SuperSupervisor) TimerDebugStats(appName string) (map[int]map[string]interface{}, error) {
p, ok := s.runningFns()[appName]
if ok {
return p.TimerDebugStats(), nil
}
return nil, fmt.Errorf("Eventing.Producer isn't alive")
}
// BootstrapAppStatus reports back status of bootstrap for a particular app on current node
func (s *SuperSupervisor) BootstrapAppStatus(appName string) bool {
logPrefix := "SuperSupervisor::BootstrapAppStatus"
producer, ok := s.runningFns()[appName]
if ok {
bootstrapStatus := producer.BootstrapStatus()
if bootstrapStatus {
logging.Infof("%s [%d] Bootstrap status from %s: %#v", logPrefix, s.runningFnsCount(), appName, bootstrapStatus)
}
return bootstrapStatus
}
return false
}
// BootstrapStatus reports back status of bootstrap for all running apps on current node
func (s *SuperSupervisor) BootstrapStatus() bool {
logPrefix := "SuperSupervisor::BootstrapStatus"
bootstrapStatuses := make(map[string]bool)
for appName, p := range s.runningFns() {
bootstrapStatuses[appName] = p.BootstrapStatus()
}
logging.Infof("%s [%d] Bootstrap status from all running applications: %#v", logPrefix, s.runningFnsCount(), bootstrapStatuses)
for _, bootstrapStatus := range bootstrapStatuses {
if bootstrapStatus {
return bootstrapStatus
}
}
return false
}
// RebalanceStatus reports back status of rebalance for all running apps on current node
func (s *SuperSupervisor) RebalanceStatus() bool {
logPrefix := "SuperSupervisor::RebalanceStatus"
if atomic.LoadInt32(&s.isRebalanceOngoing) == 1 {
return true
}
rebalanceStatuses := make(map[string]bool)
for appName, p := range s.runningFns() {
rebalanceStatuses[appName] = p.RebalanceStatus()
}
logging.Infof("%s [%d] Rebalance status from all running applications: %#v",
logPrefix, s.runningFnsCount(), rebalanceStatuses)
for _, rebStatus := range rebalanceStatuses {
if rebStatus {
return rebStatus
}
}
return false
}
// PausingAppList returns list of apps which are being Paused
func (s *SuperSupervisor) PausingAppList() map[string]string {
logPrefix := "SuperSupervisor::PausingAppList"
pausingApps := make(map[string]string)
s.appListRWMutex.RLock()
defer s.appListRWMutex.RUnlock()
for appName, ts := range s.pausingApps {
pausingApps[appName] = ts
}
if len(pausingApps) != 0 {
logging.Infof("%s [%d] pausingApps: %+v", logPrefix, s.runningFnsCount(), pausingApps)
}
return pausingApps
}
// BootstrapAppList returns list of apps undergoing bootstrap
func (s *SuperSupervisor) BootstrapAppList() map[string]string {
logPrefix := "SuperSupervisor::BootstrapAppList"
bootstrappingApps := make(map[string]string)
s.appListRWMutex.RLock()
defer s.appListRWMutex.RUnlock()
for appName, ts := range s.bootstrappingApps {
bootstrappingApps[appName] = ts
}
if len(bootstrappingApps) > 0 {
logging.Infof("%s [%d] bootstrappingApps: %+v", logPrefix, s.runningFnsCount(), bootstrappingApps)
}
return bootstrappingApps
}
// VbSeqnoStats returns seq no stats, which can be useful in figuring out missed events during rebalance
func (s *SuperSupervisor) VbSeqnoStats(appName string) (map[int][]map[string]interface{}, error) {
p, ok := s.runningFns()[appName]
if ok {
return p.VbSeqnoStats(), nil
}
return nil, fmt.Errorf("Eventing.Producer isn't alive")
}
// RemoveProducerToken takes out appName from supervision tree
func (s *SuperSupervisor) RemoveProducerToken(appName string) {
if p, exists := s.runningFns()[appName]; exists {
s.stopAndDeleteProducer(p)
}
}
// CheckpointBlobDump returns state of metadata blobs stored in Couchbase bucket
func (s *SuperSupervisor) CheckpointBlobDump(appName string) (interface{}, error) {
p, ok := s.runningFns()[appName]
if ok {
return p.CheckpointBlobDump(), nil
}
return nil, fmt.Errorf("Eventing.Producer isn't alive")
}
// StopProducer tries to gracefully stop running producer instance for a function
func (s *SuperSupervisor) StopProducer(appName string, msg common.UndeployAction) {
logPrefix := "SuperSupervisor::StopProducer"
if swapped := s.checkAndSwapStatus(appName, false, false); !swapped {
// Some other routine must have undeployed this app
return
}
logging.Infof("%s [%d] Function: %s stopping running producer instance, %s",
logPrefix, s.runningFnsCount(), appName, msg)
s.deleteFromLocallyDeployedApps(appName)
s.cleanupProducer(appName, msg)
s.deleteFromDeployedApps(appName)
}
func (s *SuperSupervisor) addToDeployedApps(appName string) {
logPrefix := "SuperSupervisor::addToDeployedApps"
s.appListRWMutex.Lock()
defer s.appListRWMutex.Unlock()
logging.Infof("%s [%d] Function: %s adding to deployed apps map", logPrefix, s.runningFnsCount(), appName)
s.deployedApps[appName] = time.Now().String()
}
func (s *SuperSupervisor) addToLocallyDeployedApps(appName string) {
logPrefix := "SuperSupervisor::addToLocallyDeployedApps"
s.appListRWMutex.Lock()
defer s.appListRWMutex.Unlock()
logging.Infof("%s [%d] Function: %s adding to locally deployed apps map", logPrefix, s.runningFnsCount(), appName)
s.locallyDeployedApps[appName] = time.Now().String()
}
func (s *SuperSupervisor) deleteFromDeployedApps(appName string) {
logPrefix := "SuperSupervisor::deleteFromDeployedApps"
s.appListRWMutex.Lock()
defer s.appListRWMutex.Unlock()
logging.Infof("%s [%d] Function: %s deleting from deployed apps map", logPrefix, s.runningFnsCount(), appName)
delete(s.deployedApps, appName)
}
func (s *SuperSupervisor) deleteFromLocallyDeployedApps(appName string) {
logPrefix := "SuperSupervisor::deleteFromLocallyDeployedApps"
s.appListRWMutex.Lock()
defer s.appListRWMutex.Unlock()
logging.Infof("%s [%d] Function: %s deleting from locally deployed apps map", logPrefix, s.runningFnsCount(), appName)
delete(s.locallyDeployedApps, appName)
}
// GetMetaStoreStats returns metastore related stats from all running functions on current node
func (s *SuperSupervisor) GetMetaStoreStats(appName string) map[string]uint64 {
stats := make(map[string]uint64)
if p, ok := s.runningFns()[appName]; ok {
stats = p.GetMetaStoreStats()
}
return stats
}
// WriteDebuggerToken signals running function to write debug token
func (s *SuperSupervisor) WriteDebuggerToken(appName, token string, hostnames []string) {
logPrefix := "SuperSupervisor::WriteDebuggerToken"
p, exists := s.runningFns()[appName]
if !exists {
logging.Errorf("%s [%d] Function %s not found", logPrefix, s.runningFnsCount(), appName)
return
}
p.WriteDebuggerToken(token, hostnames)
}
// WriteDebuggerURL signals running function to write debug url
func (s *SuperSupervisor) WriteDebuggerURL(appName, url string) {
logPrefix := "SuperSupervisor::WriteDebuggerURL"
p, exists := s.runningFns()[appName]
if !exists {
logging.Errorf("%s [%d] Function %s not found", logPrefix, s.runningFnsCount(), appName)
return
}
p.WriteDebuggerURL(url)
}
func (s *SuperSupervisor) runningFnsCount() int {
s.runningProducersRWMutex.RLock()
defer s.runningProducersRWMutex.RUnlock()
return len(s.runningProducers)
}
func (s *SuperSupervisor) runningFns() map[string]common.EventingProducer {
runningFns := make(map[string]common.EventingProducer)
s.runningProducersRWMutex.RLock()
defer s.runningProducersRWMutex.RUnlock()
for k, v := range s.runningProducers {
runningFns[k] = v
}
return runningFns
}
func (s *SuperSupervisor) deleteFromRunningProducers(appName string) {
logPrefix := "SuperSupervisor::deleteFromRunningProducers"
s.runningProducersRWMutex.Lock()
delete(s.runningProducers, appName)
s.runningProducersRWMutex.Unlock()
logging.Infof("%s [%d] Function: %s deleted from running functions", logPrefix, s.runningFnsCount(), appName)
}
func (s *SuperSupervisor) addToRunningProducers(appName string, p common.EventingProducer) {
logPrefix := "SuperSupervisor::addToRunningProducers"
s.runningProducersRWMutex.Lock()
s.runningProducers[appName] = p
s.runningProducersRWMutex.Unlock()
logging.Infof("%s [%d] Function: %s added to running functions", logPrefix, s.runningFnsCount(), appName)
}
// SpanBlobDump returns state of timer span blobs stored in metadata bucket
func (s *SuperSupervisor) SpanBlobDump(appName string) (interface{}, error) {
p, ok := s.runningFns()[appName]
if ok {
return p.SpanBlobDump(), nil
}
return nil, fmt.Errorf("Eventing.Producer isn't alive")
}
func (s *SuperSupervisor) addToCleanupApps(appName string) {
logPrefix := "SuperSupervisor::addToCleanupApps"
s.Lock()
defer s.Unlock()
_, ok := s.cleanedUpAppMap[appName]
if !ok {
s.cleanedUpAppMap[appName] = struct{}{}
logging.Infof("%s [%d] Function: %s added", logPrefix, s.runningFnsCount(), appName)
}
}
func (s *SuperSupervisor) deleteFromCleanupApps(appName string) {
logPrefix := "SuperSupervisor::deleteFromCleanupApps"
s.Lock()
defer s.Unlock()
delete(s.cleanedUpAppMap, appName)
logging.Infof("%s [%d] Function: %s deleted", logPrefix, s.runningFnsCount(), appName)
}
// DcpFeedBoundary returns feed boundary used for vb dcp streams
func (s *SuperSupervisor) DcpFeedBoundary(fnName string) (string, error) {
p, ok := s.runningFns()[fnName]
if ok {
return p.DcpFeedBoundary(), nil
}
return "", fmt.Errorf("Eventing.Producer isn't alive")
}
// GetAppLog returns tail of app log
func (s *SuperSupervisor) GetAppLog(fnName string, sz int64) []string {
p, ok := s.runningFns()[fnName]
if !ok {
logging.Infof("Could not find app %v to tail", fnName)
return nil
}
return p.GetAppLog(sz)
}
// GetBucket returns the bucket to the caller
func (s *SuperSupervisor) GetBucket(bucketName, appName string) (*couchbase.Bucket, error) {
s.bucketsRWMutex.Lock()
defer s.bucketsRWMutex.Unlock()
if bucketWatch, ok := s.buckets[bucketName]; ok {
if _, ok := bucketWatch.apps[appName]; !ok {
return nil, fmt.Errorf("Function: %s is no longer watching bucket: %s", appName, bucketName)
}
return bucketWatch.b, nil
}
return nil, fmt.Errorf("Function: %s requested bucket: %s is not in watch list", appName, bucketName)
}
func (s *SuperSupervisor) GetGocbHandle(bucketName, appName string) (*gocb.Bucket, error) {
return s.gocbGlobalConfigHandle.getBucket(bucketName, appName)
}
func (s *SuperSupervisor) CheckAndSwitchgocbBucket(bucketName, appName string, setting *common.SecuritySetting) error {
return s.gocbGlobalConfigHandle.maybeRegistergocbBucket(bucketName, appName, setting, s)
}
func (s *SuperSupervisor) GetCurrentManifestId(bucketName string) (string, error) {
s.bucketsRWMutex.Lock()
defer s.bucketsRWMutex.Unlock()
bucketWatch, ok := s.buckets[bucketName]
if !ok {
return "0", common.BucketNotWatched
}
return bucketWatch.GetManifestId(), nil
}
// Empty collectionName returns collection id as 0
// Caller of this functions should take care of it
func (s *SuperSupervisor) GetKeyspaceID(bucketName, scopeName, collectionName string) (keyspaceID common.KeyspaceID, err error) {
s.bucketsRWMutex.RLock()
defer s.bucketsRWMutex.RUnlock()
bucketWatch, ok := s.buckets[bucketName]
if !ok {
err = common.BucketNotWatched
return
}
keyspaceID.Bid = bucketWatch.b.UUID
manifest := bucketWatch.b.Manifest
if manifest == nil {
return
}
if scopeName == "*" && collectionName == "*" {
keyspaceID.StreamType = common.STREAM_BUCKET
return
}
if collectionName == "*" {
collectionName = ""
keyspaceID.StreamType = common.STREAM_SCOPE
} else {
keyspaceID.StreamType = common.STREAM_COLLECTION
}
sid, cid, err := manifest.GetScopeAndCollectionID(scopeName, collectionName)
if err != nil {
return keyspaceID, err
}
keyspaceID.Sid = sid
keyspaceID.Cid = cid
return keyspaceID, nil
}
func (s *SuperSupervisor) GetMetadataHandle(bucketName, scopeName, collectionName, appName string) (*gocb.Collection, error) {
return s.gocbGlobalConfigHandle.getBucketCollection(bucketName, scopeName, collectionName, appName)
}
func (s *SuperSupervisor) IncWorkerRespawnedCount() {
atomic.AddUint32(&s.workerRespawnedCount, 1)
}
func (s *SuperSupervisor) WorkerRespawnedCount() uint32 {
return atomic.LoadUint32(&s.workerRespawnedCount)
}
func (s *SuperSupervisor) CheckLifeCycleOpsDuringRebalance() bool {
return s.serviceMgr.CheckLifeCycleOpsDuringRebalance()
}
// SetSecuritySetting Sets the new security settings and returns whether reload is required or not
func (s *SuperSupervisor) SetSecuritySetting(setting *common.SecuritySetting) bool {
defer func() {
s.securityMutex.Unlock()
if setting != nil {
// Push encryption change notifications to all consumers of all producers
s.UpdateEncryptionLevel(setting.DisableNonSSLPorts, setting.EncryptData)
}
}()
s.securityMutex.Lock()
if s.securitySetting != nil {
// TODO: 7.0.1 Change return value based on EncryptData and DisableNonSSLPorts since both can change
if s.securitySetting.EncryptData == false && setting.EncryptData == false {
s.securitySetting = setting
return false
}
s.securitySetting = setting
return true
}
s.securitySetting = setting
return false
}
func (s *SuperSupervisor) GetSecuritySetting() *common.SecuritySetting {
s.securityMutex.RLock()
defer s.securityMutex.RUnlock()
return s.securitySetting
}
func (s *SuperSupervisor) EncryptionChangedDuringLifecycle() bool {
s.initEncryptDataMutex.RLock()
initencryptData := s.initLifecycleEncryptData
defer s.initEncryptDataMutex.RUnlock()
currentencryptData := false
if securitySetting := s.GetSecuritySetting(); securitySetting != nil {
currentencryptData = securitySetting.EncryptData
}
if initencryptData != currentencryptData {
return true
}
return false
}
func (s *SuperSupervisor) GetGocbSubscribedApps(encryptionEnabled bool) map[string]struct{} {
apps := make(map[string]struct{})
s.gocbGlobalConfigHandle.RLock()
defer s.gocbGlobalConfigHandle.RUnlock()
for appName, appencrypted := range s.gocbGlobalConfigHandle.appEncryptionMap {
if appencrypted == encryptionEnabled {
apps[appName] = struct{}{}
}
}
return apps
}
func (s *SuperSupervisor) GetBSCSnapshot() (map[string]map[string][]string, error) {
hostAddress := net.JoinHostPort(util.Localhost(), s.restPort)
cic, err := util.FetchClusterInfoClient(hostAddress)
if err != nil {
return nil, err
}
cinfo := cic.GetClusterInfoCache()
cinfo.RLock()
defer cinfo.RUnlock()
snapshot := make(map[string]map[string][]string)
buckets := cinfo.GetBuckets()
for _, bucketName := range buckets {
scopeList := cinfo.GetScopes(bucketName)
if scopeList == nil {
snapshot[bucketName] = make(map[string][]string)
continue
}
snapshot[bucketName] = scopeList
}
return snapshot, nil
}
func (s *SuperSupervisor) GetNumVbucketsForBucket(bucketName string) int {
hostAddress := net.JoinHostPort(util.Localhost(), s.restPort)
cic, err := util.FetchClusterInfoClient(hostAddress)
if err != nil {
return 1024
}
cinfo := cic.GetClusterInfoCache()
cinfo.RLock()
defer cinfo.RUnlock()
return cinfo.GetNumVbucketsForBucket(bucketName)
}
func (s *SuperSupervisor) UpdateEncryptionLevel(enforceTLS, encryptOn bool) {
for _, p := range s.runningFns() {
p.UpdateEncryptionLevel(enforceTLS, encryptOn)
}
}
func (s *SuperSupervisor) GetSystemMemoryQuota() float64 {
return s.systemMemLimit * memQuotaThreshold
}