This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 188
/
strategy_inactive.go
80 lines (65 loc) · 2.18 KB
/
strategy_inactive.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
// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package purger
import (
"fmt"
"strings"
"github.com/pingcap/errors"
"github.com/siddontang/go/sync2"
"github.com/pingcap/dm/pkg/streamer"
)
// inactiveArgs represents args needed by inactiveStrategy
type inactiveArgs struct {
relayBaseDir string
uuids []string
activeRelayLog *streamer.RelayLogInfo // earliest active relay log info
}
func (ia *inactiveArgs) SetActiveRelayLog(active *streamer.RelayLogInfo) {
ia.activeRelayLog = active
}
func (ia *inactiveArgs) String() string {
return fmt.Sprintf("(RelayBaseDir: %s, UUIDs: %s, ActiveRelayLog: %s)",
ia.relayBaseDir, strings.Join(ia.uuids, ";"), ia.activeRelayLog)
}
// inactiveStrategy represents a relay purge strategy which purge all inactive relay log files
// definition of inactive relay log files:
// * not writing by relay unit
// * not reading by sync unit and will not be read by any running tasks
// TODO zxc: judge tasks are running dumper / loader
type inactiveStrategy struct {
purging sync2.AtomicInt32
}
func newInactiveStrategy() PurgeStrategy {
return &inactiveStrategy{}
}
func (s *inactiveStrategy) Check(args interface{}) (bool, error) {
// do not support purge in the background
return false, nil
}
func (s *inactiveStrategy) Do(args interface{}) error {
if !s.purging.CompareAndSwap(0, 1) {
return ErrSelfPurging
}
defer s.purging.Set(0)
ia, ok := args.(*inactiveArgs)
if !ok {
return errors.NotValidf("args (%T) %+v", args, args)
}
return errors.Trace(purgeRelayFilesBeforeFile(ia.relayBaseDir, ia.uuids, ia.activeRelayLog))
}
func (s *inactiveStrategy) Purging() bool {
return s.purging.Get() > 0
}
func (s *inactiveStrategy) Type() strategyType {
return strategyInactive
}