@@ -15,7 +15,6 @@ import (
15
15
"log"
16
16
"math/rand"
17
17
"net"
18
- "net/http"
19
18
"os"
20
19
"os/signal"
21
20
"path/filepath"
@@ -26,16 +25,13 @@ import (
26
25
"syscall"
27
26
"time"
28
27
29
- "github.com/featurebasedb/featurebase/v3/dax"
30
28
"golang.org/x/sync/errgroup"
31
29
32
30
pilosa "github.com/featurebasedb/featurebase/v3"
33
31
"github.com/featurebasedb/featurebase/v3/authn"
34
32
"github.com/featurebasedb/featurebase/v3/authz"
35
33
"github.com/featurebasedb/featurebase/v3/batch"
36
34
"github.com/featurebasedb/featurebase/v3/boltdb"
37
- "github.com/featurebasedb/featurebase/v3/dax/computer"
38
- "github.com/featurebasedb/featurebase/v3/dax/computer/alpha"
39
35
"github.com/featurebasedb/featurebase/v3/encoding/proto"
40
36
petcd "github.com/featurebasedb/featurebase/v3/etcd"
41
37
"github.com/featurebasedb/featurebase/v3/gcnotify"
@@ -79,12 +75,7 @@ type Command struct {
79
75
logger loggerLogger
80
76
queryLogger loggerLogger
81
77
82
- mds pilosa.MDS
83
- writeLogger pilosa.WriteLogger
84
- snapshotter pilosa.Snapshotter
85
-
86
78
Handler pilosa.HandlerI
87
- httpHandler http.Handler
88
79
grpcServer * grpcServer
89
80
grpcLn net.Listener
90
81
API * pilosa.API
@@ -95,10 +86,6 @@ type Command struct {
95
86
96
87
serverOptions []pilosa.ServerOption
97
88
auth * authn.Auth
98
-
99
- // isComputeNode is set to true if this node is running as a DAX compute
100
- // node.
101
- isComputeNode bool
102
89
}
103
90
104
91
type CommandOption func (c * Command ) error
@@ -124,50 +111,13 @@ func OptCommandConfig(config *Config) CommandOption {
124
111
c .Config .Etcd = config .Etcd
125
112
c .Config .Auth = config .Auth
126
113
c .Config .TLS = config .TLS
127
- c .Config .MDSAddress = config .MDSAddress
128
- c .Config .WriteLogger = config .WriteLogger
129
114
return nil
130
115
}
131
116
c .Config = config
132
117
return nil
133
118
}
134
119
}
135
120
136
- // OptCommandSetConfig was added because OptCommandConfig only sets a small
137
- // sub-set of the config options (it doesn't seem to be used for anything but
138
- // tests). We need a functional option which sets the full Config.
139
- func OptCommandSetConfig (config * Config ) CommandOption {
140
- return func (c * Command ) error {
141
- defer c .Config .MustValidate ()
142
- c .Config = config
143
- return nil
144
- }
145
- }
146
-
147
- // OptCommandInjections injects the interface implementations.
148
- func OptCommandInjections (inj Injections ) CommandOption {
149
- return func (c * Command ) error {
150
- if inj .MDS != nil {
151
- c .mds = inj .MDS
152
- }
153
- if inj .WriteLogger != nil {
154
- c .writeLogger = inj .WriteLogger
155
- }
156
- if inj .Snapshotter != nil {
157
- c .snapshotter = inj .Snapshotter
158
- }
159
- c .isComputeNode = inj .IsComputeNode
160
- return nil
161
- }
162
- }
163
-
164
- type Injections struct {
165
- MDS pilosa.MDS
166
- WriteLogger pilosa.WriteLogger
167
- Snapshotter pilosa.Snapshotter
168
- IsComputeNode bool
169
- }
170
-
171
121
// NewCommand returns a new instance of Main.
172
122
func NewCommand (stdin io.Reader , stdout , stderr io.Writer , opts ... CommandOption ) * Command {
173
123
c := & Command {
@@ -265,70 +215,12 @@ func (m *Command) setupResourceLimits() error {
265
215
return setupResourceLimitsErr
266
216
}
267
217
268
- // StartNoServe starts the pilosa server, but doesn't serve on the http handler.
269
- func (m * Command ) StartNoServe () (err error ) {
270
- // Seed random number generator
271
- rand .Seed (time .Now ().UTC ().UnixNano ())
272
-
273
- // setupServer
274
- err = m .setupServer ()
275
- if err != nil {
276
- return errors .Wrap (err , "setting up server" )
277
- }
278
- err = m .setupResourceLimits ()
279
- if err != nil {
280
- return errors .Wrap (err , "setting resource limits" )
281
- }
282
-
283
- // Initialize server.
284
- if err = m .Server .Open (); err != nil {
285
- return errors .Wrap (err , "opening server" )
286
- }
287
-
288
- return nil
289
- }
290
-
291
- // Register registers the node with the MDS service using whatever MDS
292
- // implementation was injected during setup.
293
- func (m * Command ) Register () (err error ) {
294
- if m .mds == nil {
295
- return errors .New ("no MDS implementation with which to register" )
296
- }
297
-
298
- node := & dax.Node {
299
- Address : dax .Address (m .Config .Advertise ),
300
- RoleTypes : []dax.RoleType {
301
- dax .RoleTypeCompute ,
302
- dax .RoleTypeTranslate ,
303
- },
304
- }
305
- return m .mds .RegisterNode (context .Background (), node )
306
- }
307
-
308
- // CheckIn is called periodically to check in with the MDS service using
309
- // whatever MDS implementation was injected during setup.
310
- func (m * Command ) CheckIn () (err error ) {
311
- if m .mds == nil {
312
- return errors .New ("no MDS implementation with which to check-in" )
313
- }
314
-
315
- node := & dax.Node {
316
- Address : dax .Address (m .Config .Advertise ),
317
- RoleTypes : []dax.RoleType {
318
- dax .RoleTypeCompute ,
319
- dax .RoleTypeTranslate ,
320
- },
321
- }
322
- return m .mds .CheckInNode (context .Background (), node )
323
- }
324
-
325
218
// Start starts the pilosa server - it returns once the server is running.
326
219
func (m * Command ) Start () (err error ) {
327
220
// Seed random number generator
328
221
rand .Seed (time .Now ().UTC ().UnixNano ())
329
-
330
- // setupServer
331
- err = m .setupServer ()
222
+ // SetupServer
223
+ err = m .SetupServer ()
332
224
if err != nil {
333
225
return errors .Wrap (err , "setting up server" )
334
226
}
@@ -366,8 +258,8 @@ func (m *Command) UpAndDown() (err error) {
366
258
// Seed random number generator
367
259
rand .Seed (time .Now ().UTC ().UnixNano ())
368
260
369
- // setupServer
370
- err = m .setupServer ()
261
+ // SetupServer
262
+ err = m .SetupServer ()
371
263
if err != nil {
372
264
return errors .Wrap (err , "setting up server" )
373
265
}
@@ -408,8 +300,8 @@ func (m *Command) Wait() error {
408
300
}
409
301
}
410
302
411
- // setupServer uses the cluster configuration to set up this server.
412
- func (m * Command ) setupServer () error {
303
+ // SetupServer uses the cluster configuration to set up this server.
304
+ func (m * Command ) SetupServer () error {
413
305
runtime .SetBlockProfileRate (m .Config .Profile .BlockRate )
414
306
runtime .SetMutexProfileFraction (m .Config .Profile .MutexFraction )
415
307
@@ -476,13 +368,9 @@ func (m *Command) setupServer() error {
476
368
return errors .Wrap (err , "new stats client" )
477
369
}
478
370
479
- if m .Config .Listener == nil {
480
- m .ln , err = getListener (* uri , m .tlsConfig )
481
- if err != nil {
482
- return errors .Wrap (err , "getting listener" )
483
- }
484
- } else {
485
- m .ln = m .Config .Listener
371
+ m .ln , err = getListener (* uri , m .tlsConfig )
372
+ if err != nil {
373
+ return errors .Wrap (err , "getting listener" )
486
374
}
487
375
488
376
// If port is 0, get auto-allocated port from listener
@@ -551,21 +439,6 @@ func (m *Command) setupServer() error {
551
439
m .Config .Etcd .Dir = filepath .Join (path , pilosa .DiscoDir )
552
440
}
553
441
554
- // WriteLogger setup.
555
- var wlw computer.WriteLogWriter = computer .NewNopWriteLogWriter ()
556
- var wlr computer.WriteLogReader = computer .NewNopWriteLogReader ()
557
- if m .writeLogger != nil {
558
- alphaWriteLog := alpha .NewAlphaWriteLog (m .writeLogger )
559
- wlr = alphaWriteLog
560
- wlw = alphaWriteLog
561
- }
562
-
563
- // Snapshotter setup.
564
- var snap computer.SnapshotReadWriter = computer .NewNopSnapshotReadWriter ()
565
- if m .snapshotter != nil {
566
- snap = alpha .NewAlphaSnapshot (m .snapshotter )
567
- }
568
-
569
442
m .Config .Etcd .Id = m .Config .Name // TODO(twg) rethink this
570
443
e := petcd .NewEtcd (m .Config .Etcd , m .logger , m .Config .Cluster .ReplicaN , version )
571
444
@@ -604,9 +477,6 @@ func (m *Command) setupServer() error {
604
477
pilosa .OptServerPartitionAssigner (m .Config .Cluster .PartitionToNodeAssignment ),
605
478
pilosa .OptServerDisCo (e , e , e , e ),
606
479
pilosa .OptServerExecutionPlannerFn (executionPlannerFn ),
607
- pilosa .OptServerWriteLogReader (wlr ),
608
- pilosa .OptServerWriteLogWriter (wlw ),
609
- pilosa .OptServerSnapshotReadWriter (snap ),
610
480
}
611
481
612
482
if m .Config .LookupDBDSN != "" {
@@ -622,18 +492,14 @@ func (m *Command) setupServer() error {
622
492
}
623
493
624
494
m .Server , err = pilosa .NewServer (serverOptions ... )
495
+
625
496
if err != nil {
626
497
return errors .Wrap (err , "new server" )
627
498
}
628
499
629
500
m .API , err = pilosa .NewAPI (
630
501
pilosa .OptAPIServer (m .Server ),
631
502
pilosa .OptAPIImportWorkerPoolSize (m .Config .ImportWorkerPoolSize ),
632
- pilosa .OptAPIWriteLogReader (wlr ),
633
- pilosa .OptAPIWriteLogWriter (wlw ),
634
- pilosa .OptAPISnapshotter (snap ),
635
- pilosa .OptAPIDirectiveWorkerPoolSize (m .Config .DirectiveWorkerPoolSize ),
636
- pilosa .OptAPIIsComputeNode (m .isComputeNode ),
637
503
)
638
504
if err != nil {
639
505
return errors .Wrap (err , "new api" )
@@ -693,7 +559,7 @@ func (m *Command) setupServer() error {
693
559
return errors .Wrap (err , "getting grpcServer" )
694
560
}
695
561
696
- hndlr , err : = pilosa .NewHandler (
562
+ m . Handler , err = pilosa .NewHandler (
697
563
pilosa .OptHandlerAllowedOrigins (m .Config .Handler .AllowedOrigins ),
698
564
pilosa .OptHandlerAPI (m .API ),
699
565
pilosa .OptHandlerLogger (m .logger ),
@@ -708,21 +574,7 @@ func (m *Command) setupServer() error {
708
574
pilosa .OptHandlerRoaringSerializer (proto .RoaringSerializer ),
709
575
pilosa .OptHandlerSQLEnabled (m .Config .SQL .EndpointEnabled ),
710
576
)
711
- if err != nil {
712
- return errors .Wrap (err , "new handler" )
713
- }
714
-
715
- m .httpHandler = hndlr
716
- m .Handler = hndlr
717
-
718
- return nil
719
- }
720
-
721
- // HTTPHandler was added for the case where we want to get the full
722
- // http.Handler, and not just those methods which satisfy the pilosa.HandlerI
723
- // interface.
724
- func (m * Command ) HTTPHandler () http.Handler {
725
- return m .httpHandler
577
+ return errors .Wrap (err , "new handler" )
726
578
}
727
579
728
580
// setupLogger sets up the logger based on the configuration.
0 commit comments