datamanager: add deleteEtcd method

This commit is contained in:
Simone Gotti 2019-07-17 17:09:36 +02:00
parent 21964f90fd
commit 8fbb9fdcbe
1 changed files with 22 additions and 3 deletions

View File

@ -57,10 +57,9 @@ var (
etcdWalsDataKey = path.Join(etcdWalBaseDir, "walsdata") etcdWalsDataKey = path.Join(etcdWalBaseDir, "walsdata")
etcdWalSeqKey = path.Join(etcdWalBaseDir, "walseq") etcdWalSeqKey = path.Join(etcdWalBaseDir, "walseq")
etcdLastCommittedStorageWalSeqKey = path.Join(etcdWalBaseDir, "lastcommittedstoragewalseq") etcdLastCommittedStorageWalSeqKey = path.Join(etcdWalBaseDir, "lastcommittedstoragewalseq")
etcdCheckpointSeqKey = path.Join(etcdWalBaseDir, "checkpointseq")
etcdCheckpointSeqKey = path.Join(etcdWalBaseDir, "checkpointseq") etcdInitEtcdLockKey = path.Join(etcdWalBaseDir, "initetcd")
etcdInitEtcdLockKey = path.Join(etcdWalBaseDir, "initetcd")
etcdSyncLockKey = path.Join(etcdWalBaseDir, "synclock") etcdSyncLockKey = path.Join(etcdWalBaseDir, "synclock")
etcdCompactChangeGroupsLockKey = path.Join(etcdWalBaseDir, "compactchangegroupslock") etcdCompactChangeGroupsLockKey = path.Join(etcdWalBaseDir, "compactchangegroupslock")
etcdCheckpointLockKey = path.Join(etcdWalBaseDir, "checkpointlock") etcdCheckpointLockKey = path.Join(etcdWalBaseDir, "checkpointlock")
@ -172,6 +171,26 @@ func etcdWalKey(walSeq string) string {
return path.Join(etcdWalsDir, walSeq) return path.Join(etcdWalsDir, walSeq)
} }
// deleteEtcd deletes all etcd data excluding keys used for locking
func (d *DataManager) deleteEtcd(ctx context.Context) error {
prefixes := []string{
etcdWalsDir + "/",
etcdWalsDataKey,
etcdWalSeqKey,
etcdLastCommittedStorageWalSeqKey,
etcdCheckpointSeqKey,
etcdChangeGroupsDir + "/",
etcdChangeGroupMinRevisionKey,
}
for _, prefix := range prefixes {
if err := d.e.DeletePrefix(ctx, prefix); err != nil {
return err
}
}
return nil
}
func (d *DataManager) Run(ctx context.Context, readyCh chan struct{}) error { func (d *DataManager) Run(ctx context.Context, readyCh chan struct{}) error {
for { for {
err := d.InitEtcd(ctx) err := d.InitEtcd(ctx)