Skip to content

Commit 9430af0

Browse files
wu-hanqingWine93
authored andcommitted
Feature(format): support fomat with blocksize and chunksize.
Signed-off-by: Hanqing Wu <[email protected]>
1 parent 2940780 commit 9430af0

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

internal/configure/format.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ import (
3232

3333
const (
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+
96116
func 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 }
137166
func (fc *FormatConfig) GetDevice() string { return fc.Device }
138167
func (fc *FormatConfig) GetMountPoint() string { return fc.MountPoint }
139168
func (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 }

internal/errno/errno.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ var (
333333
ERR_MOUNT_POINT_REQUIRE_ABSOLUTE_PATH = EC(341002, "mount point must be an absolute path")
334334
ERR_FORMAT_PERCENT_REQUIRES_INTERGET = EC(341003, "format percentage requires an integer")
335335
ERR_FORMAT_PERCENT_MUST_BE_BETWEEN_1_AND_100 = EC(341004, "format percentage must be between 1 and 100")
336+
ERR_INVALID_BLOCK_SIZE = EC(341005, "invalid block size, support 512,4096")
336337

337338
// 350: configure (client.yaml: parse failed)
338339
ERR_PARSE_CLIENT_CONFIGURE_FAILED = EC(350000, "parse client configure failed")

internal/task/scripts/shell/format.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ percent=$2
99
chunkfile_size=$3
1010
chunkfile_pool_dir=$4
1111
chunkfile_pool_meta_path=$5
12+
chunkfile_block_size=$6
1213

1314
mkdir -p $chunkfile_pool_dir
1415
$binary \
1516
-allocatePercent=$percent \
1617
-fileSize=$chunkfile_size \
1718
-filePoolDir=$chunkfile_pool_dir \
1819
-filePoolMetaPath=$chunkfile_pool_meta_path \
19-
-fileSystemPath=$chunkfile_pool_dir
20+
-fileSystemPath=$chunkfile_pool_dir \
21+
-blockSize=$chunkfile_block_size \
22+
-undefok blockSize

internal/task/task/bs/format.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ func NewFormatChunkfilePoolTask(curveadm *cli.CurveAdm, fc *configure.FormatConf
178178
device := fc.GetDevice()
179179
mountPoint := fc.GetMountPoint()
180180
usagePercent := fc.GetFormatPercent()
181+
blockSize := fc.GetBlockSize()
182+
chunkSize := fc.GetChunkSize()
181183
subname := fmt.Sprintf("host=%s device=%s mountPoint=%s usage=%d%%",
182184
fc.GetHost(), device, mountPoint, usagePercent)
183185
t := task.NewTask("Start Format Chunkfile Pool", subname, hc.GetSSHConfig())
@@ -190,8 +192,8 @@ func NewFormatChunkfilePoolTask(curveadm *cli.CurveAdm, fc *configure.FormatConf
190192
chunkfilePoolRootDir := layout.ChunkfilePoolRootDir
191193
formatScript := scripts.FORMAT
192194
formatScriptPath := fmt.Sprintf("%s/format.sh", layout.ToolsBinDir)
193-
formatCommand := fmt.Sprintf("%s %s %d %d %s %s", formatScriptPath, layout.FormatBinaryPath,
194-
usagePercent, DEFAULT_CHUNKFILE_SIZE, layout.ChunkfilePoolDir, layout.ChunkfilePoolMetaPath)
195+
formatCommand := fmt.Sprintf("%s %s %d %d %s %s %d", formatScriptPath, layout.FormatBinaryPath,
196+
usagePercent, chunkSize, layout.ChunkfilePoolDir, layout.ChunkfilePoolMetaPath, blockSize)
195197

196198
// 1: skip if formating container exist
197199
t.AddStep(&step.ListContainers{

0 commit comments

Comments
 (0)