github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/pkg/config/db.go (about) 1 // Copyright 2021 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package config 15 16 import "github.com/pingcap/tiflow/pkg/errors" 17 18 // DBConfig represents db sorter config. 19 type DBConfig struct { 20 // Count is the number of db count. 21 // 22 // The default value is 8. 23 Count int `toml:"count" json:"count"` 24 // MaxOpenFiles is the maximum number of open FD by db sorter. 25 // 26 // The default value is 10000. 27 MaxOpenFiles int `toml:"max-open-files" json:"max-open-files"` 28 // BlockSize the block size of db sorter. 29 // 30 // The default value is 65536, 64KB. 31 BlockSize int `toml:"block-size" json:"block-size"` 32 // WriterBufferSize is the size of memory table of db. 33 // 34 // The default value is 8388608, 8MB. 35 WriterBufferSize int `toml:"writer-buffer-size" json:"writer-buffer-size"` 36 // Compression is the compression algorithm that is used by db. 37 // Valid values are "none" or "snappy". 38 // 39 // The default value is "snappy". 40 Compression string `toml:"compression" json:"compression"` 41 // WriteL0PauseTrigger defines number of db sst file at level-0 that will 42 // pause write. 43 // 44 // The default value is 1<<31 - 1. 45 WriteL0PauseTrigger int `toml:"write-l0-pause-trigger" json:"write-l0-pause-trigger"` 46 47 // CompactionL0Trigger defines number of db sst file at level-0 that will 48 // trigger compaction. 49 // 50 // The default value is 16, which is based on a performance test on 4K tables. 51 CompactionL0Trigger int `toml:"compaction-l0-trigger" json:"compaction-l0-trigger"` 52 } 53 54 // ValidateAndAdjust validates and adjusts the db configuration 55 func (c *DBConfig) ValidateAndAdjust() error { 56 if c.Compression != "none" && c.Compression != "snappy" { 57 return errors.ErrIllegalSorterParameter.GenWithStackByArgs( 58 "sorter.leveldb.compression must be \"none\" or \"snappy\"") 59 } 60 61 return nil 62 }