Skip to content

Commit

Permalink
meta: allow setting heartbeat to 0 (#3471)
Browse files Browse the repository at this point in the history
  • Loading branch information
SandyXSD authored Apr 12, 2023
1 parent 25f77e9 commit ac3f337
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions pkg/meta/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,11 @@ func (m *baseMeta) NewSession() error {
}

func (m *baseMeta) expireTime() int64 {
return time.Now().Add(5 * m.conf.Heartbeat).Unix()
if m.conf.Heartbeat > 0 {
return time.Now().Add(m.conf.Heartbeat * 5).Unix()
} else {
return time.Now().Add(time.Hour * 24 * 365).Unix()
}
}

func (m *baseMeta) OnReload(fn func(f *Format)) {
Expand All @@ -493,13 +497,17 @@ func (m *baseMeta) OnReload(fn func(f *Format)) {

func (m *baseMeta) refresh() {
for {
utils.SleepWithJitter(m.conf.Heartbeat)
if m.conf.Heartbeat > 0 {
utils.SleepWithJitter(m.conf.Heartbeat)
} else { // use default value
utils.SleepWithJitter(time.Second * 12)
}
m.sesMu.Lock()
if m.umounting {
m.sesMu.Unlock()
return
}
if !m.conf.ReadOnly {
if !m.conf.ReadOnly && m.conf.Heartbeat > 0 {
if err := m.en.doRefreshSession(); err != nil {
logger.Errorf("Refresh session %d: %s", m.sid, err)
}
Expand Down Expand Up @@ -534,7 +542,7 @@ func (m *baseMeta) refresh() {
}
m.loadQuotas()

if m.conf.ReadOnly || m.conf.NoBGJob {
if m.conf.ReadOnly || m.conf.NoBGJob || m.conf.Heartbeat == 0 {
continue
}
if ok, err := m.en.setIfSmall("lastCleanupSessions", time.Now().Unix(), int64((m.conf.Heartbeat * 9 / 10).Seconds())); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/meta/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c *Config) SelfCheck() {
if c.MaxDeletes == 0 {
logger.Warnf("Deleting object will be disabled since max-deletes is 0")
}
if c.Heartbeat < time.Second {
if c.Heartbeat != 0 && c.Heartbeat < time.Second {
logger.Warnf("heartbeat should not be less than 1 second")
c.Heartbeat = time.Second
}
Expand Down

0 comments on commit ac3f337

Please sign in to comment.