mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
all: consistently use fs.MustClose() for closing lock files
This commit is contained in:
parent
2a3b19e1d2
commit
df619bdff0
7 changed files with 8 additions and 80 deletions
|
@ -426,9 +426,8 @@ func (tb *Table) MustClose() {
|
|||
}
|
||||
|
||||
// Release flockF
|
||||
if err := tb.flockF.Close(); err != nil {
|
||||
logger.Panicf("FATAL:cannot close %q: %s", tb.flockF.Name(), err)
|
||||
}
|
||||
fs.MustClose(tb.flockF)
|
||||
tb.flockF = nil
|
||||
}
|
||||
|
||||
// Path returns the path to tb on the filesystem.
|
||||
|
|
|
@ -39,28 +39,6 @@ func TestTableOpenClose(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestTableOpenMultipleTimes(t *testing.T) {
|
||||
const path = "TestTableOpenMultipleTimes"
|
||||
defer func() {
|
||||
_ = os.RemoveAll(path)
|
||||
}()
|
||||
|
||||
var isReadOnly uint32
|
||||
tb1, err := OpenTable(path, nil, nil, &isReadOnly)
|
||||
if err != nil {
|
||||
t.Fatalf("cannot open table: %s", err)
|
||||
}
|
||||
defer tb1.MustClose()
|
||||
|
||||
for i := 0; i < 4; i++ {
|
||||
tb2, err := OpenTable(path, nil, nil, &isReadOnly)
|
||||
if err == nil {
|
||||
tb2.MustClose()
|
||||
t.Fatalf("expecting non-nil error when opening already opened table")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTableAddItemsSerial(t *testing.T) {
|
||||
r := rand.New(rand.NewSource(1))
|
||||
const path = "TestTableAddItemsSerial"
|
||||
|
|
|
@ -174,7 +174,7 @@ func tryOpeningQueue(path, name string, chunkFileSize, maxBlockSize, maxPendingB
|
|||
mustCloseFlockF := true
|
||||
defer func() {
|
||||
if mustCloseFlockF {
|
||||
_ = q.flockF.Close()
|
||||
fs.MustClose(q.flockF)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -332,9 +332,7 @@ func (q *queue) MustClose() {
|
|||
}
|
||||
|
||||
// Close flockF
|
||||
if err := q.flockF.Close(); err != nil {
|
||||
logger.Panicf("FATAL: cannot close flock file: %s", err)
|
||||
}
|
||||
fs.MustClose(q.flockF)
|
||||
q.flockF = nil
|
||||
}
|
||||
|
||||
|
|
|
@ -799,9 +799,8 @@ func (s *Storage) MustClose() {
|
|||
s.mustSaveNextDayMetricIDs(nextDayMetricIDs)
|
||||
|
||||
// Release lock file.
|
||||
if err := s.flockF.Close(); err != nil {
|
||||
logger.Panicf("FATAL: cannot close lock file %q: %s", s.flockF.Name(), err)
|
||||
}
|
||||
fs.MustClose(s.flockF)
|
||||
s.flockF = nil
|
||||
|
||||
// Stop series limiters.
|
||||
if sl := s.hourlySeriesLimiter; sl != nil {
|
||||
|
|
|
@ -433,26 +433,6 @@ func TestStorageOpenClose(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestStorageOpenMultipleTimes(t *testing.T) {
|
||||
path := "TestStorageOpenMultipleTimes"
|
||||
s1, err := OpenStorage(path, -1, 0, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("cannot open storage the first time: %s", err)
|
||||
}
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
s2, err := OpenStorage(path, -1, 0, 0)
|
||||
if err == nil {
|
||||
s2.MustClose()
|
||||
t.Fatalf("expecting non-nil error when opening already opened storage")
|
||||
}
|
||||
}
|
||||
s1.MustClose()
|
||||
if err := os.RemoveAll(path); err != nil {
|
||||
t.Fatalf("cannot remove %q: %s", path, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStorageRandTimestamps(t *testing.T) {
|
||||
path := "TestStorageRandTimestamps"
|
||||
retentionMsecs := int64(10 * msecsPerMonth)
|
||||
|
|
|
@ -202,9 +202,8 @@ func (tb *table) MustClose() {
|
|||
}
|
||||
|
||||
// Release exclusive lock on the table.
|
||||
if err := tb.flockF.Close(); err != nil {
|
||||
logger.Panicf("FATAL: cannot release lock on %q: %s", tb.flockF.Name(), err)
|
||||
}
|
||||
fs.MustClose(tb.flockF)
|
||||
tb.flockF = nil
|
||||
}
|
||||
|
||||
// flushPendingRows flushes all the pending raw rows, so they become visible to search.
|
||||
|
|
|
@ -36,28 +36,3 @@ func TestTableOpenClose(t *testing.T) {
|
|||
tb.MustClose()
|
||||
}
|
||||
}
|
||||
|
||||
func TestTableOpenMultipleTimes(t *testing.T) {
|
||||
const path = "TestTableOpenMultipleTimes"
|
||||
const retentionMsecs = 123 * msecsPerMonth
|
||||
|
||||
defer func() {
|
||||
_ = os.RemoveAll(path)
|
||||
}()
|
||||
|
||||
strg := newTestStorage()
|
||||
strg.retentionMsecs = retentionMsecs
|
||||
tb1, err := openTable(path, strg)
|
||||
if err != nil {
|
||||
t.Fatalf("cannot open table the first time: %s", err)
|
||||
}
|
||||
defer tb1.MustClose()
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
tb2, err := openTable(path, strg)
|
||||
if err == nil {
|
||||
tb2.MustClose()
|
||||
t.Fatalf("expecting non-nil error when opening already opened table")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue