Skip to content

Commit

Permalink
Fix memory leak bug in bos
Browse files Browse the repository at this point in the history
  • Loading branch information
duanliguo committed Dec 16, 2021
1 parent 863c651 commit 33742a4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 25 deletions.
2 changes: 1 addition & 1 deletion bce/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

// Constants and default values for the package bce
const (
SDK_VERSION = "0.9.100"
SDK_VERSION = "0.9.101"
URI_PREFIX = "/" // now support uri without prefix "v1" so just set root path
DEFAULT_DOMAIN = "baidubce.com"
DEFAULT_PROTOCOL = "http"
Expand Down
12 changes: 10 additions & 2 deletions doc/BBC.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ rebuildArgs := &RebuildInstanceArgs{
RaidId: "your_raid_id",
// 系统盘根分区大小,默认为20G,取值范围为20-100。此参数在isPreserveData为true时不生效
SysRootSize: 20,
// 指定系统盘文件系统,当前合法值:xfs,ext4
RootPartitionType: "your-choose-rootPartitionType",
// 指定数据盘文件系统,当前合法值:xfs,ext4
DataPartitionType: "your-choose-dataPartitionType",
}
// 设置你要操作的instanceId
instanceId := "your-choose-instance-id"
Expand All @@ -394,7 +398,7 @@ if err := bbcClient.RebuildInstance(instanceId, isPreserveData, rebuildArgs); er
> **注意:**
>IsPreserveData表示是否保留数据:
>- 当IsPreserveData设置为 false 时,RaidId 和 SysRootSize 是必填参数
>- 当IsPreserveData设置为 true 时,RaidId 和 SysRootSize 参数不生效
>- 当IsPreserveData设置为 true 时,RaidId、SysRootSizeDataPartitionType 参数不生效
### 批量重装实例
使用以下代码可以使用镜像批量重建指定BBC实例:
Expand All @@ -412,6 +416,10 @@ rebuildArgs := &BatchRebuildInstanceArgs{
RaidId: "your_raid_id",
// 系统盘根分区大小,默认为20G,取值范围为20-100。此参数在isPreserveData为true时不生效
SysRootSize: 20,
// 指定系统盘文件系统,当前合法值:xfs,ext4
RootPartitionType: "your-choose-rootPartitionType",
// 指定数据盘文件系统,当前合法值:xfs,ext4
DataPartitionType: "your-choose-dataPartitionType",
}
if res, err := bbcClient.BatchRebuildInstance(rebuildArgs); err != nil {
fmt.Println("batch rebuild instance failed: ", err)
Expand All @@ -422,7 +430,7 @@ if res, err := bbcClient.BatchRebuildInstance(rebuildArgs); err != nil {
> **注意:**
>IsPreserveData表示是否保留数据:
>- 当IsPreserveData设置为 false 时,RaidId 和 SysRootSize 是必填参数
>- 当IsPreserveData设置为 true 时,RaidId 和 SysRootSize 参数不生效
>- 当IsPreserveData设置为 true 时,RaidId、SysRootSizeDataPartitionType 参数不生效
### 实例续费

Expand Down
26 changes: 15 additions & 11 deletions services/bbc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,24 +187,28 @@ func TestModifyInstanceDesc(t *testing.T) {

func TestRebuildInstance(t *testing.T) {
rebuildArgs := &RebuildInstanceArgs{
ImageId: BBC_TestImageId,
AdminPass: BBC_TestAdminPass,
IsPreserveData: true,
RaidId: BBC_TestRaidId,
SysRootSize: 20,
ImageId: BBC_TestImageId,
AdminPass: BBC_TestAdminPass,
IsPreserveData: true,
RaidId: BBC_TestRaidId,
SysRootSize: 20,
RootPartitionType: "xfs",
DataPartitionType: "xfs",
}
err := BBC_CLIENT.RebuildInstance(BBC_TestBbcId, true, rebuildArgs)
ExpectEqual(t.Errorf, err, nil)
}

func TestBatchRebuildInstances(t *testing.T) {
rebuildArgs := &RebuildBatchInstanceArgs{
ImageId: "ImageId",
AdminPass: "123qaz!@#",
InstanceIds: []string{"BBC_TestBbcId"},
IsPreserveData: true,
RaidId: BBC_TestRaidId,
SysRootSize: 20,
ImageId: "ImageId",
AdminPass: "123qaz!@#",
InstanceIds: []string{"BBC_TestBbcId"},
IsPreserveData: true,
RaidId: BBC_TestRaidId,
SysRootSize: 20,
RootPartitionType: "xfs",
DataPartitionType: "xfs",
}
result, err := BBC_CLIENT.BatchRebuildInstances(rebuildArgs)
fmt.Println(result)
Expand Down
26 changes: 15 additions & 11 deletions services/bbc/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,20 +248,24 @@ type ModifyInstanceHostnameArgs struct {
}

type RebuildInstanceArgs struct {
ImageId string `json:"imageId"`
AdminPass string `json:"adminPass"`
IsPreserveData bool `json:"isPreserveData"`
RaidId string `json:"raidId,omitempty"`
SysRootSize int `json:"sysRootSize,omitempty"`
ImageId string `json:"imageId"`
AdminPass string `json:"adminPass"`
IsPreserveData bool `json:"isPreserveData"`
RaidId string `json:"raidId,omitempty"`
SysRootSize int `json:"sysRootSize,omitempty"`
RootPartitionType string `json:"rootPartitionType,omitempty"`
DataPartitionType string `json:"dataPartitionType,omitempty"`
}

type RebuildBatchInstanceArgs struct {
InstanceIds []string `json:"instanceIds"`
ImageId string `json:"imageId"`
AdminPass string `json:"adminPass"`
IsPreserveData bool `json:"isPreserveData"`
RaidId string `json:"raidId,omitempty"`
SysRootSize int `json:"sysRootSize,omitempty"`
InstanceIds []string `json:"instanceIds"`
ImageId string `json:"imageId"`
AdminPass string `json:"adminPass"`
IsPreserveData bool `json:"isPreserveData"`
RaidId string `json:"raidId,omitempty"`
SysRootSize int `json:"sysRootSize,omitempty"`
RootPartitionType string `json:"rootPartitionType,omitempty"`
DataPartitionType string `json:"dataPartitionType,omitempty"`
}

type BatchRebuildResponse struct {
Expand Down
1 change: 1 addition & 0 deletions services/bos/api/multipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func InitiateMultipartUpload(cli bce.Client, bucket, object, contentType string,
if err := resp.ParseJsonBody(result); err != nil {
return nil, err
}
defer func() { resp.Body().Close() }()
return result, nil
}

Expand Down
1 change: 1 addition & 0 deletions services/bos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,7 @@ func (c *Client) parallelPartUpload(bucket string, object string, filename strin
if err != nil {
return nil, err
}
defer file.Close()
// 分块大小按MULTIPART_ALIGN=1MB对齐
partSize := (c.MultipartSize +
MULTIPART_ALIGN - 1) / MULTIPART_ALIGN * MULTIPART_ALIGN
Expand Down

0 comments on commit 33742a4

Please sign in to comment.