Run backup post hooks inside ItemBlock synchronously
Run backup post hooks inside ItemBlock synchronously as the ItemBlocks are handled asynchronously Fixes #8516 Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com>pull/8694/head
parent
c0c4407657
commit
7aa8040c09
|
@ -0,0 +1 @@
|
|||
Run backup post hooks inside ItemBlock synchronously
|
|
@ -70,7 +70,6 @@ type HookTracker struct {
|
|||
hookExecutedCnt int
|
||||
// hookErrs records hook execution errors if any.
|
||||
hookErrs []HookErrInfo
|
||||
AsyncItemBlocks *sync.WaitGroup
|
||||
}
|
||||
|
||||
// NewHookTracker creates a hookTracker instance.
|
||||
|
@ -78,7 +77,6 @@ func NewHookTracker() *HookTracker {
|
|||
return &HookTracker{
|
||||
lock: &sync.RWMutex{},
|
||||
tracker: make(map[hookKey]hookStatus),
|
||||
AsyncItemBlocks: &sync.WaitGroup{},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,8 +141,6 @@ func (ht *HookTracker) Record(podNamespace, podName, container, source, hookName
|
|||
|
||||
// Stat returns the number of attempted hooks and failed hooks
|
||||
func (ht *HookTracker) Stat() (hookAttemptedCnt int, hookFailedCnt int) {
|
||||
ht.AsyncItemBlocks.Wait()
|
||||
|
||||
ht.lock.RLock()
|
||||
defer ht.lock.RUnlock()
|
||||
|
||||
|
|
|
@ -759,8 +759,7 @@ func (kb *kubernetesBackupper) backupItemBlock(itemBlock *BackupItemBlock) []sch
|
|||
|
||||
if len(postHookPods) > 0 {
|
||||
itemBlock.Log.Debug("Executing post hooks")
|
||||
itemBlock.itemBackupper.hookTracker.AsyncItemBlocks.Add(1)
|
||||
go kb.handleItemBlockPostHooks(itemBlock, postHookPods)
|
||||
kb.handleItemBlockPostHooks(itemBlock, postHookPods)
|
||||
}
|
||||
|
||||
return grList
|
||||
|
@ -798,7 +797,6 @@ func (kb *kubernetesBackupper) handleItemBlockPreHooks(itemBlock *BackupItemBloc
|
|||
// The hooks cannot execute until the PVBs to be processed
|
||||
func (kb *kubernetesBackupper) handleItemBlockPostHooks(itemBlock *BackupItemBlock, hookPods []itemblock.ItemBlockItem) {
|
||||
log := itemBlock.Log
|
||||
defer itemBlock.itemBackupper.hookTracker.AsyncItemBlocks.Done()
|
||||
|
||||
// the post hooks will not execute until all PVBs of the item block pods are processed
|
||||
if err := kb.waitUntilPVBsProcessed(kb.podVolumeContext, log, itemBlock, hookPods); err != nil {
|
||||
|
|
|
@ -3995,17 +3995,7 @@ func TestBackupWithHooks(t *testing.T) {
|
|||
require.NoError(t, h.backupper.Backup(h.log, req, backupFile, nil, tc.actions, nil))
|
||||
|
||||
if tc.wantHookExecutionLog != nil {
|
||||
// as the post hook execution in async way, check the existence rather than the exact order
|
||||
assert.Equal(t, len(tc.wantHookExecutionLog), len(podCommandExecutor.HookExecutionLog))
|
||||
m := map[string]struct{}{}
|
||||
for _, entry := range podCommandExecutor.HookExecutionLog {
|
||||
m[entry.String()] = struct{}{}
|
||||
}
|
||||
|
||||
for _, entry := range tc.wantHookExecutionLog {
|
||||
_, exist := m[entry.String()]
|
||||
assert.True(t, exist)
|
||||
}
|
||||
assert.Equal(t, tc.wantHookExecutionLog, podCommandExecutor.HookExecutionLog)
|
||||
}
|
||||
assertTarballContents(t, backupFile, append(tc.wantBackedUp, "metadata/version")...)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue