Skip to content

Commit

Permalink
nydusify: modify compact interface
Browse files Browse the repository at this point in the history
This patch modifies the compact interface to meet the change in
nydus-image.

Signed-off-by: Yifan Zhao <[email protected]>
  • Loading branch information
SToPire authored and imeoer committed Oct 15, 2024
1 parent 1ccc603 commit 7c49849
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
13 changes: 11 additions & 2 deletions contrib/nydusify/pkg/build/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ type CompactOption struct {
BackendType string
BackendConfigPath string
OutputJSONPath string
CompactConfigPath string

MinUsedRatio string
CompactBlobSize string
MaxCompactSize string
LayersToCompact string
BlobsDir string
}

type GenerateOption struct {
Expand Down Expand Up @@ -82,7 +87,11 @@ func (builder *Builder) Compact(option CompactOption) error {
args := []string{
"compact",
"--bootstrap", option.BootstrapPath,
"--config", option.CompactConfigPath,
"--blob-dir", option.BlobsDir,
"--min-used-ratio", option.MinUsedRatio,
"--compact-blob-size", option.CompactBlobSize,
"--max-compact-size", option.MaxCompactSize,
"--layers-to-compact", option.LayersToCompact,
"--backend-type", option.BackendType,
"--backend-config-file", option.BackendConfigPath,
"--log-level", "info",
Expand Down
29 changes: 14 additions & 15 deletions contrib/nydusify/pkg/compactor/compactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import (
)

var defaultCompactConfig = &CompactConfig{
MinUsedRatio: 5,
CompactBlobSize: 10485760,
MaxCompactSize: 104857600,
LayersToCompact: 32,
MinUsedRatio: "5",
CompactBlobSize: "10485760",
MaxCompactSize: "104857600",
LayersToCompact: "32",
}

type CompactConfig struct {
MinUsedRatio int `json:"min_used_ratio"`
CompactBlobSize int `json:"compact_blob_size"`
MaxCompactSize int `json:"max_compact_size"`
LayersToCompact int `json:"layers_to_compact"`
BlobsDir string `json:"blobs_dir,omitempty"`
MinUsedRatio string
CompactBlobSize string
MaxCompactSize string
LayersToCompact string
BlobsDir string
}

func (cfg *CompactConfig) Dumps(filePath string) error {
Expand Down Expand Up @@ -81,11 +81,6 @@ func (compactor *Compactor) Compact(bootstrapPath, chunkDict, backendType, backe
if err := os.Remove(targetBootstrap); err != nil && !os.IsNotExist(err) {
return "", errors.Wrap(err, "failed to delete old bootstrap file")
}
// prepare config file
configFilePath := filepath.Join(compactor.workdir, "compact.json")
if err := compactor.cfg.Dumps(configFilePath); err != nil {
return "", errors.Wrap(err, "compact err")
}
outputJSONPath := filepath.Join(compactor.workdir, "compact-result.json")
if err := os.Remove(outputJSONPath); err != nil && !os.IsNotExist(err) {
return "", errors.Wrap(err, "failed to delete old output-json file")
Expand All @@ -97,7 +92,11 @@ func (compactor *Compactor) Compact(bootstrapPath, chunkDict, backendType, backe
BackendType: backendType,
BackendConfigPath: backendConfigFile,
OutputJSONPath: outputJSONPath,
CompactConfigPath: configFilePath,
MinUsedRatio: compactor.cfg.MinUsedRatio,
CompactBlobSize: compactor.cfg.CompactBlobSize,
MaxCompactSize: compactor.cfg.MaxCompactSize,
LayersToCompact: compactor.cfg.LayersToCompact,
BlobsDir: compactor.cfg.BlobsDir,
})
if err != nil {
return "", errors.Wrap(err, "failed to run compact command")
Expand Down
6 changes: 3 additions & 3 deletions src/bin/nydus-image/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,17 +699,17 @@ fn prepare_cmd_args(bti_string: &'static str) -> App {
.arg(
Arg::new("min-used-ratio")
.long("min-used-ratio")
.help("Lower bound of used ratio for blobs to be kept")
.help("Lower bound of used ratio for blobs to be kept, possible values: 0-99, 0 means disable")
)
.arg(
Arg::new("compact-blob-size")
.long("compact-blob-size")
.help("Upper bound of blob size for blobs to be compacted")
.help("Upper bound of blob size for blobs to be compacted, in bytes")
)
.arg(
Arg::new("max-compact-size")
.long("max-compact-size")
.help("Upper bound of compacted blob size")
.help("Upper bound of compacted blob size, in bytes")
)
.arg(
Arg::new("layers-to-compact")
Expand Down

0 comments on commit 7c49849

Please sign in to comment.