豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit d4574ad

Browse files
committed
locks: remove redundant beatPaths parameter
Now that Paths lives in beat.Info, there is no need to pass it as a separate argument alongside Info.
1 parent 184a91b commit d4574ad

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

libbeat/cmd/instance/beat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ func (b *Beat) launch(settings Settings, bt beat.Creator) error {
430430
// Try to acquire exclusive lock on data path to prevent another beat instance
431431
// sharing same data path. This is disabled under elastic-agent.
432432
if !management.UnderAgent() {
433-
bl := locks.New(b.Info, b.Info.Paths)
433+
bl := locks.New(b.Info)
434434
err := bl.Lock()
435435
if err != nil {
436436
return err

libbeat/cmd/instance/locks/lock.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ type Locker struct {
4242
var ErrAlreadyLocked = fmt.Errorf("data path already locked by another beat. Please make sure that multiple beats are not sharing the same data path (path.data)")
4343

4444
// New returns a new file locker
45-
func New(beatInfo beat.Info, beatPaths *paths.Path) *Locker {
46-
return NewWithRetry(beatInfo, beatPaths, 4, time.Millisecond*400)
45+
func New(beatInfo beat.Info) *Locker {
46+
return NewWithRetry(beatInfo, 4, time.Millisecond*400)
4747
}
4848

4949
// NewWithRetry returns a new file locker with the given settings
50-
func NewWithRetry(beatInfo beat.Info, beatPaths *paths.Path, retryCount int, retrySleep time.Duration) *Locker {
51-
lockfilePath := beatPaths.Resolve(paths.Data, beatInfo.Beat+".lock")
50+
func NewWithRetry(beatInfo beat.Info, retryCount int, retrySleep time.Duration) *Locker {
51+
lockfilePath := beatInfo.Paths.Resolve(paths.Data, beatInfo.Beat+".lock")
5252
return &Locker{
5353
fileLock: flock.New(lockfilePath),
5454
retryCount: retryCount,

libbeat/cmd/instance/locks/lock_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,20 @@ func TestLocker(t *testing.T) {
6565

6666
logger := logptest.NewTestingLogger(t, "")
6767

68-
b1 := beat.Info{Logger: logger}
68+
b1 := beat.Info{Logger: logger, Paths: tmpPaths}
6969
b1.Beat = beatName
7070

71-
b2 := beat.Info{Logger: logger}
71+
b2 := beat.Info{Logger: logger, Paths: tmpPaths}
7272
b2.Beat = beatName
7373

7474
// Try to get a lock for the first beat. Expect it to succeed.
75-
bl1 := New(b1, tmpPaths)
75+
bl1 := New(b1)
7676
err = bl1.Lock()
7777
require.NoError(t, err)
7878

7979
// Try to get a lock for the second beat. Expect it to fail because the
8080
// first beat already has the lock.
81-
bl2 := New(b2, tmpPaths)
81+
bl2 := New(b2)
8282
err = bl2.Lock()
8383
require.Error(t, err)
8484
}
@@ -92,15 +92,15 @@ func TestUnlock(t *testing.T) {
9292
err := tmpPaths.InitPaths(tmpPaths)
9393
require.NoError(t, err, "error initializaing paths")
9494

95-
b1 := beat.Info{Logger: logger}
95+
b1 := beat.Info{Logger: logger, Paths: tmpPaths}
9696
b1.Beat = beatName
9797

98-
b2 := beat.Info{}
98+
b2 := beat.Info{Paths: tmpPaths}
9999
b2.Beat = beatName
100-
bl2 := New(b2, tmpPaths)
100+
bl2 := New(b2)
101101

102102
// Try to get a lock for the first beat. Expect it to succeed.
103-
bl1 := New(b1, tmpPaths)
103+
bl1 := New(b1)
104104
err = bl1.Lock()
105105
require.NoError(t, err)
106106

@@ -122,15 +122,15 @@ func TestUnlockWithRemainingFile(t *testing.T) {
122122
err := tmpPaths.InitPaths(tmpPaths)
123123
require.NoError(t, err, "error initializaing paths")
124124

125-
b1 := beat.Info{Logger: logger}
125+
b1 := beat.Info{Logger: logger, Paths: tmpPaths}
126126
b1.Beat = beatName
127127

128-
b2 := beat.Info{}
128+
b2 := beat.Info{Paths: tmpPaths}
129129
b2.Beat = beatName
130-
bl2 := New(b2, tmpPaths)
130+
bl2 := New(b2)
131131

132132
// Try to get a lock for the first beat. Expect it to succeed.
133-
bl1 := New(b1, tmpPaths)
133+
bl1 := New(b1)
134134
err = bl1.Lock()
135135
require.NoError(t, err)
136136

0 commit comments

Comments
 (0)