@@ -32,6 +32,12 @@ import (
3232
3333const (
3434 DEFAULT_CONTAINER_IMAGE = "opencurvedocker/curvebs:v1.2"
35+ DEFAULT_BLOCK_SIZE = 4096
36+ DEFAULT_CHUNK_SIZE = 16 * 1024 * 1024
37+ )
38+
39+ var (
40+ VALID_BLOCK_SIZE = [2 ]int {512 , 4096 }
3541)
3642
3743/*
@@ -51,12 +57,16 @@ type (
5157 Device string
5258 MountPoint string
5359 FormtPercent int
60+ BlockSize int
61+ ChunkSize int
5462 }
5563
5664 Format struct {
5765 ContainerImage string `mapstructure:"container_image"`
5866 Hosts []string `mapstructure:"host"`
5967 Disks []string `mapstructure:"disk"`
68+ BlockSize int `mapstructure:"block_size"`
69+ ChunkSize int `mapstructure:"chunk_size"`
6070 }
6171)
6272
@@ -93,6 +103,16 @@ func newFormatConfig(containerImage, host, disk string) (*FormatConfig, error) {
93103 }, nil
94104}
95105
106+ func isValidBlockSize (blocksize int ) bool {
107+ for _ , bs := range VALID_BLOCK_SIZE {
108+ if bs == blocksize {
109+ return true
110+ }
111+ }
112+
113+ return false
114+ }
115+
96116func ParseFormat (filename string ) ([]* FormatConfig , error ) {
97117 if ! utils .PathExist (filename ) {
98118 return nil , errno .ERR_FORMAT_CONFIGURE_FILE_NOT_EXIST .
@@ -107,7 +127,10 @@ func ParseFormat(filename string) ([]*FormatConfig, error) {
107127 return nil , errno .ERR_PARSE_FORMAT_CONFIGURE_FAILED .E (err )
108128 }
109129
110- format := & Format {}
130+ format := & Format {
131+ BlockSize : DEFAULT_BLOCK_SIZE ,
132+ ChunkSize : DEFAULT_CHUNK_SIZE ,
133+ }
111134 err = parser .Unmarshal (format )
112135 if err != nil {
113136 return nil , errno .ERR_PARSE_FORMAT_CONFIGURE_FAILED .E (err )
@@ -118,13 +141,19 @@ func ParseFormat(filename string) ([]*FormatConfig, error) {
118141 containerImage = format .ContainerImage
119142 }
120143
144+ if ! isValidBlockSize (format .BlockSize ) {
145+ return nil , errno .ERR_INVALID_BLOCK_SIZE .F ("block_size: %d" , format .BlockSize )
146+ }
147+
121148 fcs := []* FormatConfig {}
122149 for _ , host := range format .Hosts {
123150 for _ , disk := range format .Disks {
124151 fc , err := newFormatConfig (containerImage , host , disk )
125152 if err != nil {
126153 return nil , err
127154 }
155+ fc .BlockSize = format .BlockSize
156+ fc .ChunkSize = format .ChunkSize
128157 fcs = append (fcs , fc )
129158 }
130159 }
@@ -137,3 +166,5 @@ func (fc *FormatConfig) GetHost() string { return fc.Host }
137166func (fc * FormatConfig ) GetDevice () string { return fc .Device }
138167func (fc * FormatConfig ) GetMountPoint () string { return fc .MountPoint }
139168func (fc * FormatConfig ) GetFormatPercent () int { return fc .FormtPercent }
169+ func (fc * FormatConfig ) GetBlockSize () int { return fc .BlockSize }
170+ func (fc * FormatConfig ) GetChunkSize () int { return fc .ChunkSize }
0 commit comments