Merge pull request #61 from sgotti/datamanager_maintenance_mode
datamanager: implement maintenance mode
This commit is contained in:
commit
af4aa58903
@ -87,6 +87,7 @@ type DataManagerConfig struct {
|
|||||||
// MinCheckpointWalsNum is the minimum number of wals required before doing a checkpoint
|
// MinCheckpointWalsNum is the minimum number of wals required before doing a checkpoint
|
||||||
MinCheckpointWalsNum int
|
MinCheckpointWalsNum int
|
||||||
MaxDataFileSize int64
|
MaxDataFileSize int64
|
||||||
|
MaintenanceMode bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type DataManager struct {
|
type DataManager struct {
|
||||||
@ -100,6 +101,7 @@ type DataManager struct {
|
|||||||
checkpointInterval time.Duration
|
checkpointInterval time.Duration
|
||||||
minCheckpointWalsNum int
|
minCheckpointWalsNum int
|
||||||
maxDataFileSize int64
|
maxDataFileSize int64
|
||||||
|
maintenanceMode bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDataManager(ctx context.Context, logger *zap.Logger, conf *DataManagerConfig) (*DataManager, error) {
|
func NewDataManager(ctx context.Context, logger *zap.Logger, conf *DataManagerConfig) (*DataManager, error) {
|
||||||
@ -133,6 +135,7 @@ func NewDataManager(ctx context.Context, logger *zap.Logger, conf *DataManagerCo
|
|||||||
checkpointInterval: conf.CheckpointInterval,
|
checkpointInterval: conf.CheckpointInterval,
|
||||||
minCheckpointWalsNum: conf.MinCheckpointWalsNum,
|
minCheckpointWalsNum: conf.MinCheckpointWalsNum,
|
||||||
maxDataFileSize: conf.MaxDataFileSize,
|
maxDataFileSize: conf.MaxDataFileSize,
|
||||||
|
maintenanceMode: conf.MaintenanceMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
// add trailing slash the basepath
|
// add trailing slash the basepath
|
||||||
@ -171,6 +174,12 @@ func etcdWalKey(walSeq string) string {
|
|||||||
return path.Join(etcdWalsDir, walSeq)
|
return path.Join(etcdWalsDir, walSeq)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetMaintenanceMode sets the datamanager in maintenance mode. This method must
|
||||||
|
// be called before invoking the Run method
|
||||||
|
func (d *DataManager) SetMaintenanceMode(maintenanceMode bool) {
|
||||||
|
d.maintenanceMode = maintenanceMode
|
||||||
|
}
|
||||||
|
|
||||||
// deleteEtcd deletes all etcd data excluding keys used for locking
|
// deleteEtcd deletes all etcd data excluding keys used for locking
|
||||||
func (d *DataManager) deleteEtcd(ctx context.Context) error {
|
func (d *DataManager) deleteEtcd(ctx context.Context) error {
|
||||||
prefixes := []string{
|
prefixes := []string{
|
||||||
@ -192,6 +201,7 @@ func (d *DataManager) deleteEtcd(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *DataManager) Run(ctx context.Context, readyCh chan struct{}) error {
|
func (d *DataManager) Run(ctx context.Context, readyCh chan struct{}) error {
|
||||||
|
if !d.maintenanceMode {
|
||||||
for {
|
for {
|
||||||
err := d.InitEtcd(ctx, nil)
|
err := d.InitEtcd(ctx, nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -210,8 +220,13 @@ func (d *DataManager) Run(ctx context.Context, readyCh chan struct{}) error {
|
|||||||
go d.compactChangeGroupsLoop(ctx)
|
go d.compactChangeGroupsLoop(ctx)
|
||||||
go d.etcdPingerLoop(ctx)
|
go d.etcdPingerLoop(ctx)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
d.log.Infof("datamanager starting in maintenance mode")
|
||||||
|
readyCh <- struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
d.log.Infof("walmanager exiting")
|
d.log.Infof("datamanager exiting")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user