mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 21:24:05 -08:00
Added ability to create db with NopWal (#519)
Signed-off-by: Vishnunarayan K I <appukuttancr@gmail.com>
This commit is contained in:
parent
db9177de0c
commit
7757fe6f21
|
@ -1,6 +1,7 @@
|
||||||
## master / unreleased
|
## master / unreleased
|
||||||
- [REMOVED] `chunks.NewReader` is removed as it wasn't used anywhere.
|
- [REMOVED] `chunks.NewReader` is removed as it wasn't used anywhere.
|
||||||
- [REMOVED] `FromData` is considered unused so was removed.
|
- [REMOVED] `FromData` is considered unused so was removed.
|
||||||
|
- [FEATURE] Added option WALSegmentSize -1 to disable the WAL.
|
||||||
|
|
||||||
## 0.6.1
|
## 0.6.1
|
||||||
- [BUGFIX] Update `last` after appending a non-overlapping chunk in `chunks.MergeOverlappingChunks`. [#539](https://github.com/prometheus/tsdb/pull/539)
|
- [BUGFIX] Update `last` after appending a non-overlapping chunk in `chunks.MergeOverlappingChunks`. [#539](https://github.com/prometheus/tsdb/pull/539)
|
||||||
|
|
13
db.go
13
db.go
|
@ -54,7 +54,10 @@ var DefaultOptions = &Options{
|
||||||
|
|
||||||
// Options of the DB storage.
|
// Options of the DB storage.
|
||||||
type Options struct {
|
type Options struct {
|
||||||
// Segments (wal files) max size
|
// Segments (wal files) max size.
|
||||||
|
// WALSegmentSize = 0, segment size is default size.
|
||||||
|
// WALSegmentSize > 0, segment size is WALSegmentSize.
|
||||||
|
// WALSegmentSize < 0, wal is disabled.
|
||||||
WALSegmentSize int
|
WALSegmentSize int
|
||||||
|
|
||||||
// Duration of persisted data to keep.
|
// Duration of persisted data to keep.
|
||||||
|
@ -288,14 +291,20 @@ func Open(dir string, l log.Logger, r prometheus.Registerer, opts *Options) (db
|
||||||
}
|
}
|
||||||
db.compactCancel = cancel
|
db.compactCancel = cancel
|
||||||
|
|
||||||
|
var wlog *wal.WAL
|
||||||
segmentSize := wal.DefaultSegmentSize
|
segmentSize := wal.DefaultSegmentSize
|
||||||
|
// Wal is enabled.
|
||||||
|
if opts.WALSegmentSize >= 0 {
|
||||||
|
// Wal is set to a custom size.
|
||||||
if opts.WALSegmentSize > 0 {
|
if opts.WALSegmentSize > 0 {
|
||||||
segmentSize = opts.WALSegmentSize
|
segmentSize = opts.WALSegmentSize
|
||||||
}
|
}
|
||||||
wlog, err := wal.NewSize(l, r, filepath.Join(dir, "wal"), segmentSize)
|
wlog, err = wal.NewSize(l, r, filepath.Join(dir, "wal"), segmentSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
db.head, err = NewHead(r, l, wlog, opts.BlockRanges[0])
|
db.head, err = NewHead(r, l, wlog, opts.BlockRanges[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
46
db_test.go
46
db_test.go
|
@ -746,9 +746,40 @@ func TestWALFlushedOnDBClose(t *testing.T) {
|
||||||
testutil.Equals(t, []string{"labelvalue"}, values)
|
testutil.Equals(t, []string{"labelvalue"}, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWALSegmentSizeOption(t *testing.T) {
|
func TestWALSegmentSizeOptions(t *testing.T) {
|
||||||
|
tests := map[int]func(dbdir string, segmentSize int){
|
||||||
|
// Default Wal Size.
|
||||||
|
0: func(dbDir string, segmentSize int) {
|
||||||
|
files, err := ioutil.ReadDir(filepath.Join(dbDir, "wal"))
|
||||||
|
testutil.Ok(t, err)
|
||||||
|
for _, f := range files[:len(files)-1] {
|
||||||
|
testutil.Equals(t, int64(DefaultOptions.WALSegmentSize), f.Size(), "WAL file size doesn't match WALSegmentSize option, filename: %v", f.Name())
|
||||||
|
}
|
||||||
|
lastFile := files[len(files)-1]
|
||||||
|
testutil.Assert(t, int64(DefaultOptions.WALSegmentSize) > lastFile.Size(), "last WAL file size is not smaller than the WALSegmentSize option, filename: %v", lastFile.Name())
|
||||||
|
},
|
||||||
|
// Custom Wal Size.
|
||||||
|
2 * 32 * 1024: func(dbDir string, segmentSize int) {
|
||||||
|
files, err := ioutil.ReadDir(filepath.Join(dbDir, "wal"))
|
||||||
|
testutil.Assert(t, len(files) > 1, "current WALSegmentSize should result in more than a single WAL file.")
|
||||||
|
testutil.Ok(t, err)
|
||||||
|
for _, f := range files[:len(files)-1] {
|
||||||
|
testutil.Equals(t, int64(segmentSize), f.Size(), "WAL file size doesn't match WALSegmentSize option, filename: %v", f.Name())
|
||||||
|
}
|
||||||
|
lastFile := files[len(files)-1]
|
||||||
|
testutil.Assert(t, int64(segmentSize) > lastFile.Size(), "last WAL file size is not smaller than the WALSegmentSize option, filename: %v", lastFile.Name())
|
||||||
|
},
|
||||||
|
// Wal disabled.
|
||||||
|
-1: func(dbDir string, segmentSize int) {
|
||||||
|
if _, err := os.Stat(filepath.Join(dbDir, "wal")); !os.IsNotExist(err) {
|
||||||
|
t.Fatal("wal directory is present when the wal is disabled")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for segmentSize, testFunc := range tests {
|
||||||
|
t.Run(fmt.Sprintf("WALSegmentSize %d test", segmentSize), func(t *testing.T) {
|
||||||
options := *DefaultOptions
|
options := *DefaultOptions
|
||||||
options.WALSegmentSize = 2 * 32 * 1024
|
options.WALSegmentSize = segmentSize
|
||||||
db, delete := openTestDB(t, &options)
|
db, delete := openTestDB(t, &options)
|
||||||
defer delete()
|
defer delete()
|
||||||
app := db.Appender()
|
app := db.Appender()
|
||||||
|
@ -760,15 +791,8 @@ func TestWALSegmentSizeOption(t *testing.T) {
|
||||||
|
|
||||||
dbDir := db.Dir()
|
dbDir := db.Dir()
|
||||||
db.Close()
|
db.Close()
|
||||||
files, err := ioutil.ReadDir(filepath.Join(dbDir, "wal"))
|
testFunc(dbDir, options.WALSegmentSize)
|
||||||
testutil.Assert(t, len(files) > 1, "current WALSegmentSize should result in more than a single WAL file.")
|
})
|
||||||
testutil.Ok(t, err)
|
|
||||||
for i, f := range files {
|
|
||||||
if len(files)-1 != i {
|
|
||||||
testutil.Equals(t, int64(options.WALSegmentSize), f.Size(), "WAL file size doesn't match WALSegmentSize option, filename: %v", f.Name())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
testutil.Assert(t, int64(options.WALSegmentSize) > f.Size(), "last WAL file size is not smaller than the WALSegmentSize option, filename: %v", f.Name())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue