-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfs_replicated.go
777 lines (735 loc) · 20.2 KB
/
fs_replicated.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
package notebrew
import (
"context"
"fmt"
"io"
"io/fs"
"log/slog"
"sync"
"sync/atomic"
"time"
"github.com/bokwoon95/notebrew/stacktrace"
)
// ReplicatedFSConfig holds the parameters needed to construct a ReplicatedFS.
type ReplicatedFSConfig struct {
// (Required) Leader is the primary FS that we read from and write to.
Leader FS
// Followers are the secondary FSes that writes are replicated to.
Followers []FS
// If SynchronousReplication is true, writes will be synchronously
// replicated to the followers.
SynchronousReplication bool
// (Required) Logger is used for reporting errors that cannot be handled
// and are thrown away.
Logger *slog.Logger
}
// SFTPFS implements a writeable filesystem on a leader FS and zero or more
// follower FSes. All reads come from the leader FS, while all writes will be
// sent to the leader FS as well as the follower FSes (synchronously or
// asynchronously depending on the SynchronousReplication field).
type ReplicatedFS struct {
// Leader is the primary FS that we read from and write to.
Leader FS
// Followers are the secondary FSes that writes are replicated to.
Followers []FS
// If SynchronousReplication is true, writes will be synchronously
// replicated to the followers.
SynchronousReplication bool
// (Required) Logger is used for reporting errors that cannot be handled
// and are thrown away.
Logger *slog.Logger
// ctx provides the context of all operations called on the ReplicatedFS.
ctx context.Context
// baseCtx is the base context of the ReplicatedFS.
baseCtx context.Context
// baseCtxCancel cancels the base context.
baseCtxCancel func()
// baseCtxWaitGroup tracks the number of asynchronous replication jobs
// running in the background. Each async job should take in the base
// context, and should should initiate shutdown when the base context is
// canceled.
baseCtxWaitGroup *sync.WaitGroup
}
// NewReplicatedFS constructs a new ReplicatedFS.
func NewReplicatedFS(config ReplicatedFSConfig) (*ReplicatedFS, error) {
baseCtx, baseCtxCancel := context.WithCancel(context.Background())
replicatedFS := &ReplicatedFS{
Leader: config.Leader,
Followers: config.Followers,
SynchronousReplication: config.SynchronousReplication,
Logger: config.Logger,
ctx: context.Background(),
baseCtx: baseCtx,
baseCtxCancel: baseCtxCancel,
baseCtxWaitGroup: &sync.WaitGroup{},
}
return replicatedFS, nil
}
// As calls the `As(any) bool` method on the leader FS if it exists.
func (fsys *ReplicatedFS) As(target any) bool {
switch v := fsys.Leader.(type) {
case interface{ As(any) bool }:
return v.As(target)
default:
return false
}
}
// WithContext returns a new FS with the given context.
func (fsys *ReplicatedFS) WithContext(ctx context.Context) FS {
return &ReplicatedFS{
Leader: fsys.Leader,
Followers: fsys.Followers,
SynchronousReplication: fsys.SynchronousReplication,
Logger: fsys.Logger,
ctx: ctx,
baseCtx: fsys.baseCtx,
baseCtxCancel: fsys.baseCtxCancel,
baseCtxWaitGroup: fsys.baseCtxWaitGroup,
}
}
// WithValues returns a new ReplicatedFS where the leader FS and each follower
// FS has `WithValues(any) FS` method called on it if it exists.
func (fsys *ReplicatedFS) WithValues(values map[string]any) FS {
replicatedFS := &ReplicatedFS{
Leader: fsys.Leader,
Followers: append(make([]FS, 0, len(fsys.Followers)), fsys.Followers...),
SynchronousReplication: fsys.SynchronousReplication,
Logger: fsys.Logger,
ctx: fsys.ctx,
baseCtx: fsys.baseCtx,
baseCtxCancel: fsys.baseCtxCancel,
baseCtxWaitGroup: fsys.baseCtxWaitGroup,
}
if v, ok := replicatedFS.Leader.(interface {
WithValues(map[string]any) FS
}); ok {
replicatedFS.Leader = v.WithValues(values)
}
for i, follower := range replicatedFS.Followers {
if v, ok := follower.(interface {
WithValues(map[string]any) FS
}); ok {
replicatedFS.Followers[i] = v.WithValues(values)
}
}
return replicatedFS
}
// Open implements the Open FS operation for SFTPFS.
func (fsys *ReplicatedFS) Open(name string) (fs.File, error) {
return fsys.Leader.WithContext(fsys.ctx).Open(name)
}
// Stat implements the fs.StatFS interface.
func (fsys *ReplicatedFS) Stat(name string) (fs.FileInfo, error) {
if statFS, ok := fsys.Leader.WithContext(fsys.ctx).(fs.StatFS); ok {
return statFS.Stat(name)
}
file, err := fsys.Leader.WithContext(fsys.ctx).Open(name)
if err != nil {
return nil, err
}
defer file.Close()
return file.Stat()
}
// ReplicatedFileWriter represents a writable file on a ReplicatedFS.
type ReplicatedFileWriter struct {
// name is the name that was passed to OpenWriter().
name string
// perm is the permissions that was passed to OpenWriter().
perm fs.FileMode
// writer is the io.WriteCloser returned by the leader FS's OpenWriter().
writer io.WriteCloser
// writeFailed records if any writes to the writer failed.
writeFailed bool
// leader FS.
leader FS
// follower FSes.
followers []FS
// If synchronousReplication is true, writes will be synchronously
// replicated to the followers.
synchronousReplication bool
// logger is used for reporting errors that cannot be handled and are
// thrown away.
logger *slog.Logger
// ctx provides the context of all operations called on the file.
ctx context.Context
// baseCtx is the base context of the ReplicatedFS that created the
// ReplicatedFileWriter.
baseCtx context.Context
// baseCtxWaitGroup keeps track of the asynchronous replication jobs
// running in the background. Each async job should take in the base
// context to be notified of when the base context is done.
baseCtxWaitGroup *sync.WaitGroup
}
// OpenWriter implements the OpenWriter FS operation for ReplicatedFS.
func (fsys *ReplicatedFS) OpenWriter(name string, perm fs.FileMode) (io.WriteCloser, error) {
writer, err := fsys.Leader.WithContext(fsys.ctx).OpenWriter(name, perm)
if err != nil {
return nil, err
}
file := &ReplicatedFileWriter{
name: name,
perm: perm,
writer: writer,
leader: fsys.Leader,
followers: fsys.Followers,
synchronousReplication: fsys.SynchronousReplication,
logger: fsys.Logger,
ctx: fsys.ctx,
baseCtx: fsys.baseCtx,
baseCtxWaitGroup: fsys.baseCtxWaitGroup,
}
return file, nil
}
// Write writes len(b) bytes from b to the ReplicatedFileWriter. It returns the
// number of bytes written and an error, if any. Write returns a non-nil error
// when n != len(b).
func (file *ReplicatedFileWriter) Write(p []byte) (n int, err error) {
err = file.ctx.Err()
if err != nil {
file.writeFailed = true
return n, err
}
n, err = file.writer.Write(p)
if err != nil {
file.writeFailed = true
return n, err
}
return n, err
}
// Close saves the contents of the ReplicatedFileWriter to the leader FS and
// follower FSes and closes the ReplicatedFileWriter.
func (file *ReplicatedFileWriter) Close() error {
if file.writer == nil {
return fs.ErrClosed
}
defer func() {
file.writer = nil
}()
err := file.writer.Close()
if err != nil {
return err
}
if file.writeFailed {
return nil
}
if file.synchronousReplication {
var errPtr atomic.Pointer[error]
var waitGroup sync.WaitGroup
for _, follower := range file.followers {
follower := follower
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
defer func() {
if v := recover(); v != nil {
file.logger.Error(stacktrace.New(fmt.Errorf("panic: %v", v)).Error())
}
}()
leaderFile, err := file.leader.WithContext(file.ctx).Open(file.name)
if err != nil {
errPtr.CompareAndSwap(nil, &err)
return
}
defer leaderFile.Close()
writer, err := follower.WithContext(file.ctx).OpenWriter(file.name, file.perm)
if err != nil {
errPtr.CompareAndSwap(nil, &err)
return
}
defer writer.Close()
_, err = io.Copy(writer, leaderFile)
if err != nil {
errPtr.CompareAndSwap(nil, &err)
return
}
err = writer.Close()
if err != nil {
errPtr.CompareAndSwap(nil, &err)
return
}
}()
}
waitGroup.Wait()
if ptr := errPtr.Load(); ptr != nil {
return *ptr
}
} else {
for _, follower := range file.followers {
follower := follower
file.baseCtxWaitGroup.Add(1)
go func() {
defer file.baseCtxWaitGroup.Done()
defer func() {
if v := recover(); v != nil {
file.logger.Error(stacktrace.New(fmt.Errorf("panic: %v", v)).Error())
}
}()
gracePeriodCtx, gracePeriodCancel := context.WithCancel(context.Background())
defer gracePeriodCancel()
go func() {
timer := time.NewTimer(-1)
defer timer.Stop()
for {
select {
case <-file.baseCtx.Done():
timer.Reset(time.Hour)
case <-timer.C:
gracePeriodCancel()
return
case <-gracePeriodCtx.Done():
return
}
}
}()
leaderFile, err := file.leader.WithContext(gracePeriodCtx).Open(file.name)
if err != nil {
file.logger.Error(err.Error())
return
}
defer leaderFile.Close()
writer, err := follower.WithContext(gracePeriodCtx).OpenWriter(file.name, file.perm)
if err != nil {
file.logger.Error(err.Error())
return
}
defer writer.Close()
_, err = io.Copy(writer, leaderFile)
if err != nil {
file.logger.Error(err.Error())
return
}
err = writer.Close()
if err != nil {
file.logger.Error(err.Error())
return
}
}()
}
}
return nil
}
// ReadDir implements the ReadDir FS operation for ReplicatedFS.
func (fsys *ReplicatedFS) ReadDir(name string) ([]fs.DirEntry, error) {
return fsys.Leader.WithContext(fsys.ctx).ReadDir(name)
}
// Mkdir implements the Mkdir FS operation for ReplicatedFS.
func (fsys *ReplicatedFS) Mkdir(name string, perm fs.FileMode) error {
err := fsys.Leader.WithContext(fsys.ctx).Mkdir(name, perm)
if err != nil {
return err
}
if fsys.SynchronousReplication {
var errPtr atomic.Pointer[error]
var waitGroup sync.WaitGroup
for _, follower := range fsys.Followers {
follower := follower
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
defer func() {
if v := recover(); v != nil {
fsys.Logger.Error(stacktrace.New(fmt.Errorf("panic: %v", v)).Error())
}
}()
err := follower.WithContext(fsys.ctx).Mkdir(name, perm)
if err != nil {
errPtr.CompareAndSwap(nil, &err)
return
}
}()
}
waitGroup.Wait()
if ptr := errPtr.Load(); ptr != nil {
return *ptr
}
} else {
for _, follower := range fsys.Followers {
follower := follower
fsys.baseCtxWaitGroup.Add(1)
go func() {
defer fsys.baseCtxWaitGroup.Done()
defer func() {
if v := recover(); v != nil {
fsys.Logger.Error(stacktrace.New(fmt.Errorf("panic: %v", v)).Error())
}
}()
gracePeriodCtx, gracePeriodCancel := context.WithCancel(context.Background())
defer gracePeriodCancel()
go func() {
timer := time.NewTimer(0)
<-timer.C
defer timer.Stop()
for {
select {
case <-fsys.baseCtx.Done():
timer.Reset(time.Hour)
case <-timer.C:
gracePeriodCancel()
return
case <-gracePeriodCtx.Done():
return
}
}
}()
err := follower.WithContext(gracePeriodCtx).Mkdir(name, perm)
if err != nil {
fsys.Logger.Error(err.Error())
return
}
}()
}
}
return nil
}
// MkdirAll implements the MkdirAll FS operation for ReplicatedFS.
func (fsys *ReplicatedFS) MkdirAll(name string, perm fs.FileMode) error {
err := fsys.Leader.WithContext(fsys.ctx).MkdirAll(name, perm)
if err != nil {
return err
}
if fsys.SynchronousReplication {
var errPtr atomic.Pointer[error]
var waitGroup sync.WaitGroup
for _, follower := range fsys.Followers {
follower := follower
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
defer func() {
if v := recover(); v != nil {
fsys.Logger.Error(stacktrace.New(fmt.Errorf("panic: %v", v)).Error())
}
}()
err := follower.WithContext(fsys.ctx).MkdirAll(name, perm)
if err != nil {
errPtr.CompareAndSwap(nil, &err)
return
}
}()
}
waitGroup.Wait()
if ptr := errPtr.Load(); ptr != nil {
return *ptr
}
} else {
for _, follower := range fsys.Followers {
follower := follower
fsys.baseCtxWaitGroup.Add(1)
go func() {
defer fsys.baseCtxWaitGroup.Done()
defer func() {
if v := recover(); v != nil {
fsys.Logger.Error(stacktrace.New(fmt.Errorf("panic: %v", v)).Error())
}
}()
gracePeriodCtx, gracePeriodCancel := context.WithCancel(context.Background())
defer gracePeriodCancel()
go func() {
timer := time.NewTimer(0)
<-timer.C
defer timer.Stop()
for {
select {
case <-fsys.baseCtx.Done():
timer.Reset(time.Hour)
case <-timer.C:
gracePeriodCancel()
return
case <-gracePeriodCtx.Done():
return
}
}
}()
err := follower.WithContext(gracePeriodCtx).Mkdir(name, perm)
if err != nil {
fsys.Logger.Error(err.Error())
return
}
}()
}
}
return nil
}
// Remove implements the Remove FS operation for ReplicatedFS.
func (fsys *ReplicatedFS) Remove(name string) error {
err := fsys.Leader.WithContext(fsys.ctx).Remove(name)
if err != nil {
return err
}
if fsys.SynchronousReplication {
var errPtr atomic.Pointer[error]
var waitGroup sync.WaitGroup
for _, follower := range fsys.Followers {
follower := follower
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
defer func() {
if v := recover(); v != nil {
fsys.Logger.Error(stacktrace.New(fmt.Errorf("panic: %v", v)).Error())
}
}()
err := follower.WithContext(fsys.ctx).Remove(name)
if err != nil {
errPtr.CompareAndSwap(nil, &err)
return
}
}()
}
waitGroup.Wait()
if ptr := errPtr.Load(); ptr != nil {
return *ptr
}
} else {
for _, follower := range fsys.Followers {
follower := follower
fsys.baseCtxWaitGroup.Add(1)
go func() {
defer fsys.baseCtxWaitGroup.Done()
defer func() {
if v := recover(); v != nil {
fsys.Logger.Error(stacktrace.New(fmt.Errorf("panic: %v", v)).Error())
}
}()
gracePeriodCtx, gracePeriodCancel := context.WithCancel(context.Background())
defer gracePeriodCancel()
go func() {
timer := time.NewTimer(0)
<-timer.C
defer timer.Stop()
for {
select {
case <-fsys.baseCtx.Done():
timer.Reset(time.Hour)
case <-timer.C:
gracePeriodCancel()
return
case <-gracePeriodCtx.Done():
return
}
}
}()
err := follower.WithContext(gracePeriodCtx).Remove(name)
if err != nil {
fsys.Logger.Error(err.Error())
return
}
}()
}
}
return nil
}
// RemoveAll implements the RemoveAll FS operation for ReplicatedFS.
func (fsys *ReplicatedFS) RemoveAll(name string) error {
err := fsys.Leader.WithContext(fsys.ctx).RemoveAll(name)
if err != nil {
return err
}
if fsys.SynchronousReplication {
var errPtr atomic.Pointer[error]
var waitGroup sync.WaitGroup
for _, follower := range fsys.Followers {
follower := follower
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
defer func() {
if v := recover(); v != nil {
fsys.Logger.Error(stacktrace.New(fmt.Errorf("panic: %v", v)).Error())
}
}()
err := follower.WithContext(fsys.ctx).RemoveAll(name)
if err != nil {
errPtr.CompareAndSwap(nil, &err)
return
}
}()
}
waitGroup.Wait()
if ptr := errPtr.Load(); ptr != nil {
return *ptr
}
} else {
for _, follower := range fsys.Followers {
follower := follower
fsys.baseCtxWaitGroup.Add(1)
go func() {
defer fsys.baseCtxWaitGroup.Done()
defer func() {
if v := recover(); v != nil {
fsys.Logger.Error(stacktrace.New(fmt.Errorf("panic: %v", v)).Error())
}
}()
gracePeriodCtx, gracePeriodCancel := context.WithCancel(context.Background())
defer gracePeriodCancel()
go func() {
timer := time.NewTimer(0)
<-timer.C
defer timer.Stop()
for {
select {
case <-fsys.baseCtx.Done():
timer.Reset(time.Hour)
case <-timer.C:
gracePeriodCancel()
return
case <-gracePeriodCtx.Done():
return
}
}
}()
err := follower.WithContext(gracePeriodCtx).RemoveAll(name)
if err != nil {
fsys.Logger.Error(err.Error())
return
}
}()
}
}
return nil
}
// Rename implements the Rename FS operation for ReplicatedFS.
func (fsys *ReplicatedFS) Rename(oldName, newName string) error {
err := fsys.Leader.WithContext(fsys.ctx).Rename(oldName, newName)
if err != nil {
return err
}
if fsys.SynchronousReplication {
var errPtr atomic.Pointer[error]
var waitGroup sync.WaitGroup
for _, follower := range fsys.Followers {
follower := follower
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
defer func() {
if v := recover(); v != nil {
fsys.Logger.Error(stacktrace.New(fmt.Errorf("panic: %v", v)).Error())
}
}()
err = follower.WithContext(fsys.ctx).Rename(oldName, newName)
if err != nil {
errPtr.CompareAndSwap(nil, &err)
return
}
}()
}
waitGroup.Wait()
if ptr := errPtr.Load(); ptr != nil {
return *ptr
}
} else {
for _, follower := range fsys.Followers {
follower := follower
fsys.baseCtxWaitGroup.Add(1)
go func() {
defer fsys.baseCtxWaitGroup.Done()
defer func() {
if v := recover(); v != nil {
fsys.Logger.Error(stacktrace.New(fmt.Errorf("panic: %v", v)).Error())
}
}()
gracePeriodCtx, gracePeriodCancel := context.WithCancel(context.Background())
defer gracePeriodCancel()
go func() {
timer := time.NewTimer(0)
<-timer.C
defer timer.Stop()
for {
select {
case <-fsys.baseCtx.Done():
timer.Reset(time.Hour)
case <-timer.C:
gracePeriodCancel()
return
case <-gracePeriodCtx.Done():
return
}
}
}()
err := follower.WithContext(gracePeriodCtx).Rename(oldName, newName)
if err != nil {
fsys.Logger.Error(err.Error())
return
}
}()
}
}
return nil
}
// Copy implements the Copy FS operation for ReplicatedFS.
func (fsys *ReplicatedFS) Copy(srcName, destName string) error {
err := fsys.Leader.WithContext(fsys.ctx).Copy(srcName, destName)
if err != nil {
return err
}
if fsys.SynchronousReplication {
var errPtr atomic.Pointer[error]
var waitGroup sync.WaitGroup
for _, follower := range fsys.Followers {
follower := follower
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
defer func() {
if v := recover(); v != nil {
fsys.Logger.Error(stacktrace.New(fmt.Errorf("panic: %v", v)).Error())
}
}()
err = follower.WithContext(fsys.ctx).Copy(srcName, destName)
if err != nil {
errPtr.CompareAndSwap(nil, &err)
return
}
}()
}
waitGroup.Wait()
if ptr := errPtr.Load(); ptr != nil {
return *ptr
}
} else {
for _, follower := range fsys.Followers {
follower := follower
fsys.baseCtxWaitGroup.Add(1)
go func() {
defer fsys.baseCtxWaitGroup.Done()
defer func() {
if v := recover(); v != nil {
fsys.Logger.Error(stacktrace.New(fmt.Errorf("panic: %v", v)).Error())
}
}()
gracePeriodCtx, gracePeriodCancel := context.WithCancel(context.Background())
defer gracePeriodCancel()
go func() {
timer := time.NewTimer(0)
<-timer.C
defer timer.Stop()
for {
select {
case <-fsys.baseCtx.Done():
timer.Reset(time.Hour)
case <-timer.C:
gracePeriodCancel()
return
case <-gracePeriodCtx.Done():
return
}
}
}()
err := follower.WithContext(gracePeriodCtx).Rename(srcName, destName)
if err != nil {
fsys.Logger.Error(err.Error())
return
}
}()
}
}
return nil
}
// Close initiates the shutdown of any background jobs currently synchronizing
// to the follower FSes and returns when all background jobs have completed.
func (fsys *ReplicatedFS) Close() error {
fsys.baseCtxCancel()
defer fsys.baseCtxWaitGroup.Wait()
return nil
}