forked from couchbase/indexing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coordinator.go
799 lines (633 loc) · 20.9 KB
/
coordinator.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
798
799
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package manager
import (
"errors"
"fmt"
common "github.com/couchbase/gometa/common"
message "github.com/couchbase/gometa/message"
protocol "github.com/couchbase/gometa/protocol"
r "github.com/couchbase/gometa/repository"
co "github.com/couchbase/indexing/secondary/common"
"github.com/couchbase/indexing/secondary/logging"
"path/filepath"
"sync"
"time"
)
/////////////////////////////////////////////////////////////////////////////
// Type Declaration
/////////////////////////////////////////////////////////////////////////////
const (
OPCODE_ADD_IDX_DEFN common.OpCode = iota
OPCODE_DEL_IDX_DEFN
)
type Coordinator struct {
state *CoordinatorState
repo *MetadataRepo
env *env
txn *common.TxnState
config *r.ServerConfig
configRepo *r.Repository
site *protocol.ElectionSite
listener *common.PeerListener
factory protocol.MsgFactory
skillch chan bool
idxMgr *IndexManager
basepath string
mutex sync.Mutex
cond *sync.Cond
ready bool
}
type CoordinatorState struct {
incomings chan *protocol.RequestHandle
// mutex protected variables
mutex sync.Mutex
done bool
status protocol.PeerStatus
pendings map[uint64]*protocol.RequestHandle // key : request id
proposals map[common.Txnid]*protocol.RequestHandle // key : txnid
}
/////////////////////////////////////////////////////////////////////////////
// Public API
/////////////////////////////////////////////////////////////////////////////
func NewCoordinator(repo *MetadataRepo, idxMgr *IndexManager, basepath string) *Coordinator {
coordinator := new(Coordinator)
coordinator.repo = repo
coordinator.ready = false
coordinator.cond = sync.NewCond(&coordinator.mutex)
coordinator.idxMgr = idxMgr
coordinator.state = newCoordinatorState()
coordinator.basepath = basepath
return coordinator
}
//
// Run Coordinator
//
func (s *Coordinator) Run(config string) {
repeat := true
for repeat {
pauseTime := s.runOnce(config)
if !s.IsDone() {
if pauseTime > 0 {
// wait before restart
time.Sleep(time.Duration(pauseTime) * time.Millisecond)
}
} else {
repeat = false
}
}
}
//
// Terminate the Coordinator
//
func (s *Coordinator) Terminate() {
defer func() {
if r := recover(); r != nil {
logging.Warnf("panic in Coordinator.Terminate() : %s. Ignored.\n", r)
}
}()
s.state.mutex.Lock()
defer s.state.mutex.Unlock()
if s.state.done {
return
}
s.state.done = true
if s.site != nil {
s.site.Close()
s.site = nil
}
if s.configRepo != nil {
s.configRepo.Close()
s.configRepo = nil
}
if s.skillch != nil {
s.skillch <- true // kill leader/follower server
}
}
//
// Check if server is terminated
//
func (s *Coordinator) IsDone() bool {
s.state.mutex.Lock()
defer s.state.mutex.Unlock()
return s.state.done
}
//
// Handle a new request. This function will block until the request is being processed
// (by returning true) or until the request is being interrupted (by returning false).
// If request is interrupted, then the request may still be processed by some other
// nodes. So the outcome of the request is unknown when this function returns false.
//
func (s *Coordinator) NewRequest(opCode uint32, key string, content []byte) bool {
uuid, err := co.NewUUID()
if err != nil {
return false
}
id := uuid.Uint64()
s.waitForReady()
req := s.factory.CreateRequest(id, opCode, key, content)
handle := &protocol.RequestHandle{Request: req, Err: nil}
handle.CondVar = sync.NewCond(&handle.Mutex)
handle.CondVar.L.Lock()
defer handle.CondVar.L.Unlock()
s.state.incomings <- handle
handle.CondVar.Wait()
return handle.Err == nil
}
/////////////////////////////////////////////////////////////////////////////
// Main Control Loop
/////////////////////////////////////////////////////////////////////////////
//
// Run the server until it stop. Will not attempt to re-run.
//
func (c *Coordinator) runOnce(config string) int {
logging.Debugf("Coordinator.runOnce() : Start Running Coordinator")
pauseTime := 0
defer func() {
if r := recover(); r != nil {
logging.Warnf("panic in Coordinator.runOnce() : %s\n", r)
}
common.SafeRun("Coordinator.cleanupState()",
func() {
c.cleanupState()
})
}()
err := c.bootstrap(config)
if err != nil {
pauseTime = 200
}
// Check if the server has been terminated explicitly. If so, don't run.
if !c.IsDone() {
// runElection() finishes if there is an error, election result is known or
// it being terminated. Unless being killed explicitly, a goroutine
// will continue to run to responds to other peer election request
leader, err := c.runElection()
if err != nil {
logging.Warnf("Coordinator.runOnce() : Error Encountered During Election : %s", err.Error())
pauseTime = 100
} else {
// Check if the server has been terminated explicitly. If so, don't run.
if !c.IsDone() {
// runCoordinator() is done if there is an error or being terminated explicitly (killch)
err := c.runProtocol(leader)
if err != nil {
logging.Warnf("Coordinator.RunOnce() : Error Encountered From Coordinator : %s", err.Error())
}
}
}
} else {
logging.Infof("Coordinator.RunOnce(): Coordinator has been terminated explicitly. Terminate.")
}
return pauseTime
}
/////////////////////////////////////////////////////////////////////////////
// Bootstrap and cleanup
/////////////////////////////////////////////////////////////////////////////
//
// Bootstrp
//
func (s *Coordinator) bootstrap(config string) (err error) {
s.state.mutex.Lock()
defer s.state.mutex.Unlock()
if s.state.done {
return
}
s.env, err = newEnv(config)
if err != nil {
return err
}
// Initialize server state
s.state.resetCoordinatorState()
// Initialize various callback facility for leader election and
// voting protocol.
s.factory = message.NewConcreteMsgFactory()
s.skillch = make(chan bool, 1) // make it buffered to unblock sender
s.site = nil
// Create and initialize new txn state.
s.txn = common.NewTxnState()
// Initialize the state to enable voting
repoName := filepath.Join(s.basepath, COORDINATOR_CONFIG_STORE)
s.configRepo, err = r.OpenRepositoryWithName(repoName, s.idxMgr.GetMemoryQuota())
if err != nil {
return err
}
s.config = r.NewServerConfig(s.configRepo)
lastLoggedTxid, err := s.config.GetLastLoggedTxnId()
if err != nil {
return err
}
s.txn.InitCurrentTxnid(common.Txnid(lastLoggedTxid))
// Need to start the peer listener before election. A follower may
// finish its election before a leader finishes its election. Therefore,
// a follower node can request a connection to the leader node before that
// node knows it is a leader. By starting the listener now, it allows the
// follower to establish the connection and let the leader handles this
// connection at a later time (when it is ready to be a leader).
s.listener, err = common.StartPeerListener(s.getHostTCPAddr())
if err != nil {
return NewError(ERROR_COOR_LISTENER_FAIL, NORMAL, COORDINATOR, err,
fmt.Sprintf("Index Coordinator : Fail to start PeerListener"))
}
// tell boostrap is ready
s.markReady()
return nil
}
//
// Cleanup internal state upon exit
//
func (s *Coordinator) cleanupState() {
// tell that coordinator is no longer ready
s.markNotReady()
s.state.mutex.Lock()
defer s.state.mutex.Unlock()
common.SafeRun("Coordinator.cleanupState()",
func() {
if s.listener != nil {
s.listener.Close()
}
})
common.SafeRun("Coordinator.cleanupState()",
func() {
if s.site != nil {
s.site.Close()
}
})
for len(s.state.incomings) > 0 {
request := <-s.state.incomings
request.Err = fmt.Errorf("Terminate Request due to server termination")
common.SafeRun("Coordinator.cleanupState()",
func() {
request.CondVar.L.Lock()
defer request.CondVar.L.Unlock()
request.CondVar.Signal()
})
}
for _, request := range s.state.pendings {
request.Err = fmt.Errorf("Terminate Request due to server termination")
common.SafeRun("Coordinator.cleanupState()",
func() {
request.CondVar.L.Lock()
defer request.CondVar.L.Unlock()
request.CondVar.Signal()
})
}
for _, request := range s.state.proposals {
request.Err = fmt.Errorf("Terminate Request due to server termination")
common.SafeRun("Coordinator.cleanupState()",
func() {
request.CondVar.L.Lock()
defer request.CondVar.L.Unlock()
request.CondVar.Signal()
})
}
}
func (s *Coordinator) markReady() {
s.mutex.Lock()
defer s.mutex.Unlock()
s.ready = true
s.cond.Signal()
}
func (s *Coordinator) markNotReady() {
s.mutex.Lock()
defer s.mutex.Unlock()
s.ready = false
}
func (s *Coordinator) isReady() bool {
s.mutex.Lock()
defer s.mutex.Unlock()
return s.ready
}
func (s *Coordinator) waitForReady() {
s.mutex.Lock()
defer s.mutex.Unlock()
for !s.ready {
s.cond.Wait()
}
}
/////////////////////////////////////////////////////////////////////////////
// Election
/////////////////////////////////////////////////////////////////////////////
//
// run election
//
func (s *Coordinator) runElection() (leader string, err error) {
host := s.getHostUDPAddr()
peers := s.getPeerUDPAddr()
// Create an election site to start leader election.
logging.Debugf("Coordinator.runElection(): Local Coordinator %s start election", host)
logging.Debugf("Coordinator.runElection(): Peer in election")
for _, peer := range peers {
logging.Debugf(" peer : %s", peer)
}
s.site, err = protocol.CreateElectionSite(host, peers, s.factory, s, false)
if err != nil {
return "", err
}
// blocked until leader is elected. coordinator.Terminate() will unblock this.
resultCh := s.site.StartElection()
leader, ok := <-resultCh
if !ok {
return "", NewError(ERROR_COOR_ELECTION_FAIL, NORMAL, COORDINATOR, nil,
fmt.Sprintf("Index Coordinator Election Fails"))
}
return leader, nil
}
/////////////////////////////////////////////////////////////////////////////
// Run Leader/Follower protocol
/////////////////////////////////////////////////////////////////////////////
//
// run server (as leader or follower)
//
func (s *Coordinator) runProtocol(leader string) (err error) {
host := s.getHostUDPAddr()
// If this host is the leader, then start the leader server.
// Otherwise, start the followerCoordinator.
if leader == host {
logging.Debugf("Coordinator.runServer() : Local Coordinator %s is elected as leader. Leading ...", leader)
s.state.setStatus(protocol.LEADING)
// start other master services if this node is a candidate as master
s.idxMgr.startMasterService()
defer s.idxMgr.stopMasterService()
err = protocol.RunLeaderServer(s.getHostTCPAddr(), s.listener, s, s, s.factory, s.skillch)
} else {
logging.Debugf("Coordinator.runServer() : Remote Coordinator %s is elected as leader. Following ...", leader)
s.state.setStatus(protocol.FOLLOWING)
leaderAddr := s.findMatchingPeerTCPAddr(leader)
if len(leaderAddr) == 0 {
return NewError(ERROR_COOR_ELECTION_FAIL, NORMAL, COORDINATOR, nil,
fmt.Sprintf("Index Coordinator cannot find matching TCP addr for leader "+leader))
}
err = protocol.RunFollowerServer(s.getHostTCPAddr(), leaderAddr, s, s, s.factory, s.skillch)
}
return err
}
/////////////////////////////////////////////////////////////////////////////
// CoordinatorState
/////////////////////////////////////////////////////////////////////////////
//
// Create a new CoordinatorState
//
func newCoordinatorState() *CoordinatorState {
incomings := make(chan *protocol.RequestHandle, common.MAX_PROPOSALS)
pendings := make(map[uint64]*protocol.RequestHandle)
proposals := make(map[common.Txnid]*protocol.RequestHandle)
state := &CoordinatorState{
incomings: incomings,
pendings: pendings,
proposals: proposals,
status: protocol.ELECTING,
done: false}
return state
}
func (c *CoordinatorState) resetCoordinatorState() {
c.incomings = make(chan *protocol.RequestHandle, common.MAX_PROPOSALS)
c.pendings = make(map[uint64]*protocol.RequestHandle)
c.proposals = make(map[common.Txnid]*protocol.RequestHandle)
c.status = protocol.ELECTING
c.done = false
}
func (s *CoordinatorState) getStatus() protocol.PeerStatus {
s.mutex.Lock()
defer s.mutex.Unlock()
return s.status
}
func (s *CoordinatorState) setStatus(status protocol.PeerStatus) {
s.mutex.Lock()
defer s.mutex.Unlock()
s.status = status
}
/////////////////////////////////////////////////////////////////////////////
// Coordinator Action (Callback)
/////////////////////////////////////////////////////////////////////////////
func (c *Coordinator) GetEnsembleSize() uint64 {
return uint64(len(c.getPeerUDPAddr())) + 1 // including myself
}
func (c *Coordinator) GetLastLoggedTxid() (common.Txnid, error) {
val, err := c.config.GetLastLoggedTxnId()
return common.Txnid(val), err
}
func (c *Coordinator) GetLastCommittedTxid() (common.Txnid, error) {
val, err := c.config.GetLastCommittedTxnId()
return common.Txnid(val), err
}
func (c *Coordinator) GetStatus() protocol.PeerStatus {
return c.state.getStatus()
}
func (c *Coordinator) GetCurrentEpoch() (uint32, error) {
return c.config.GetCurrentEpoch()
}
func (c *Coordinator) GetAcceptedEpoch() (uint32, error) {
return c.config.GetAcceptedEpoch()
}
func (c *Coordinator) GetCommitedEntries(txid1, txid2 common.Txnid) (<-chan protocol.LogEntryMsg, <-chan error, chan<- bool, error) {
// The coordinator does not use the commit log. So nothing to stream.
return nil, nil, nil, nil
}
func (c *Coordinator) LogAndCommit(txid common.Txnid, op uint32, key string, content []byte, toCommit bool) error {
// The coordinator does not use the commit log. So nothing to log.
return nil
}
func (c *Coordinator) NotifyNewAcceptedEpoch(epoch uint32) error {
oldEpoch, _ := c.GetAcceptedEpoch()
// update only if the new epoch is larger
if oldEpoch < epoch {
err := c.config.SetAcceptedEpoch(epoch)
if err != nil {
return err
}
}
return nil
}
func (c *Coordinator) NotifyNewCurrentEpoch(epoch uint32) error {
oldEpoch, _ := c.GetCurrentEpoch()
// update only if the new epoch is larger
if oldEpoch < epoch {
err := c.config.SetCurrentEpoch(epoch)
if err != nil {
return err
}
// update the election site with the new epoch, such that
// for new incoming vote, the server can reply with the
// new and correct epoch
c.site.UpdateWinningEpoch(epoch)
// any new tnxid from now on will use the new epoch
c.txn.SetEpoch(epoch)
}
return nil
}
func (c *Coordinator) GetFollowerId() string {
return c.getHostUDPAddr()
}
// TODO : what to do if createIndex returns error
func (c *Coordinator) LogProposal(proposal protocol.ProposalMsg) error {
if c.GetStatus() == protocol.LEADING {
switch common.OpCode(proposal.GetOpCode()) {
case OPCODE_ADD_IDX_DEFN:
success := c.createIndex(proposal.GetKey(), proposal.GetContent())
logging.Debugf("Coordinator.LogProposal(): (createIndex) success = %s", success)
case OPCODE_DEL_IDX_DEFN:
success := c.deleteIndex(proposal.GetKey())
logging.Debugf("Coordinator.LogProposal(): (deleteIndex) success = %s", success)
}
}
c.updateRequestOnNewProposal(proposal)
return nil
}
func (c *Coordinator) Commit(txid common.Txnid) error {
c.updateRequestOnCommit(txid)
return nil
}
func (c *Coordinator) Abort(fid string, reqId uint64, err string) error {
c.updateRequestOnRespond(fid, reqId, err, nil)
return nil
}
func (c *Coordinator) Respond(fid string, reqId uint64, err string, content []byte) error {
c.updateRequestOnRespond(fid, reqId, err, content)
return nil
}
func (c *Coordinator) GetQuorumVerifier() protocol.QuorumVerifier {
return c
}
func (c *Coordinator) GetNextTxnId() common.Txnid {
return c.txn.GetNextTxnId()
}
// TODO : Quorum should be based on active participants
func (c *Coordinator) HasQuorum(count int) bool {
ensembleSz := c.GetEnsembleSize()
return count > int(ensembleSz/2)
}
/////////////////////////////////////////////////////////////////////////////
// Request Handling
/////////////////////////////////////////////////////////////////////////////
// Return a channel of request for the leader to process on.
func (c *Coordinator) GetRequestChannel() <-chan *protocol.RequestHandle {
return (<-chan *protocol.RequestHandle)(c.state.incomings)
}
// This is called when the leader has de-queued the request for processing.
func (c *Coordinator) AddPendingRequest(handle *protocol.RequestHandle) {
c.state.mutex.Lock()
defer c.state.mutex.Unlock()
c.state.pendings[handle.Request.GetReqId()] = handle
}
func (c *Coordinator) CleanupOnError() {
// no-op. Coorindator will cleanup itself in runOnce()
}
//
// Update the request upon new proposal.
//
func (c *Coordinator) updateRequestOnNewProposal(proposal protocol.ProposalMsg) {
fid := proposal.GetFid()
reqId := proposal.GetReqId()
txnid := proposal.GetTxnid()
logging.Debugf("Coorindator.updateRequestOnNewProposal(): recieve proposal. Txnid %d, follower id %s, coorindator fid %s",
txnid, fid, c.GetFollowerId())
// If this host is the one that sends the request to the leader
if fid == c.GetFollowerId() {
c.state.mutex.Lock()
defer c.state.mutex.Unlock()
// look up the request handle from the pending list and
// move it to the proposed list
handle, ok := c.state.pendings[reqId]
if ok {
delete(c.state.pendings, reqId)
c.state.proposals[common.Txnid(txnid)] = handle
}
}
}
func (c *Coordinator) updateRequestOnRespond(fid string, reqId uint64, err string, content []byte) {
// If this host is the one that sends the request to the leader
if fid == c.GetFollowerId() {
c.state.mutex.Lock()
defer c.state.mutex.Unlock()
// look up the request handle from the pending list and
// move it to the proposed list
handle, ok := c.state.pendings[reqId]
if ok {
delete(c.state.pendings, reqId)
handle.CondVar.L.Lock()
defer handle.CondVar.L.Unlock()
if len(err) != 0 {
handle.Err = errors.New(err)
}
handle.CondVar.Signal()
}
}
}
//
// Update the request upon new commit
//
func (c *Coordinator) updateRequestOnCommit(txnid common.Txnid) {
c.state.mutex.Lock()
defer c.state.mutex.Unlock()
logging.Debugf("Coorindator.updateRequestOnCommit(): recieve proposal. Txnid %d, coorindator fid %s",
txnid, c.GetFollowerId())
// If I can find the proposal based on the txnid in this host, this means
// that this host originates the request. Get the request handle and
// notify the waiting goroutine that the request is done.
handle, ok := c.state.proposals[txnid]
if ok {
delete(c.state.proposals, txnid)
handle.CondVar.L.Lock()
defer handle.CondVar.L.Unlock()
handle.CondVar.Signal()
}
}
/////////////////////////////////////////////////////////////////////////////
// Environment
/////////////////////////////////////////////////////////////////////////////
func (c *Coordinator) getHostUDPAddr() string {
return c.env.getHostUDPAddr()
}
func (c *Coordinator) getHostTCPAddr() string {
return c.env.getHostTCPAddr()
}
func (c *Coordinator) findMatchingPeerTCPAddr(udpAddr string) string {
return c.env.findMatchingPeerTCPAddr(udpAddr)
}
func (c *Coordinator) getPeerUDPAddr() []string {
return c.env.getPeerUDPAddr()
}
/////////////////////////////////////////////////////////////////////////////
// Metadata Operations
/////////////////////////////////////////////////////////////////////////////
//
// Handle create Index request in the dictionary. If this function
// returns true, it means createIndex request completes successfully.
// If this function returns false, then the result is unknown.
//
func (c *Coordinator) createIndex(key string, content []byte) bool {
defn, err := co.UnmarshallIndexDefn(content)
if err != nil {
return false
}
// For now, use the local host. This logic is not called in sherlock production code.
// But still will be called in uint test.
if err := c.idxMgr.getLifecycleMgr().CreateIndex(defn, false, nil); err != nil {
logging.Debugf("Coordinator.createIndexy() : createIndex fails. Reason = %s", err.Error())
return false
}
return true
}
//
// Handle delete Index request in the dictionary. If this function
// returns true, it means deleteIndex request completes successfully.
// If this function returns false, then the result is unknown.
//
func (c *Coordinator) deleteIndex(key string) bool {
id, err := indexDefnId(key)
if err != nil {
logging.Debugf("Coordinator.deleteIndex() : deleteIndex fails. Reason = %s", err.Error())
return false
}
if err := c.idxMgr.getLifecycleMgr().DeleteIndex(id, true, nil); err != nil {
logging.Debugf("Coordinator.deleteIndex() : deleteIndex fails. Reason = %s", err.Error())
return false
}
return true
}