compact

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cli.Command{
	Name:      "compact",
	Usage:     "Create a compacted copy of the database",
	ArgsUsage: "<source db file> <destination db file>",
	Flags: []cli.Flag{
		&cli.IntFlag{
			Usage:   "Page size for the new database. Defaults to OS page size",
			Name:    "page-size",
			EnvVars: []string{"PAGE_SIZE"},
			Value:   os.Getpagesize(),
		},
		&cli.StringFlag{
			Usage:   "Type of the freelist for the new database: array | map",
			Name:    "freelist-type",
			EnvVars: []string{"FREELIST_TYPE"},
			Value:   "array",
		},
		&cli.DurationFlag{
			Usage:   "timeout for opening source database",
			Name:    "open-timeout",
			Value:   500 * time.Millisecond,
			EnvVars: []string{"OPEN_TIMEOUT"},
		},
	},

	Action: func(c *cli.Context) error {
		if c.NArg() != 2 {
			return fmt.Errorf("source and destination file names must be provided")
		}

		sourceFile := c.Args().Get(0)
		destinationFile := c.Args().Get(1)

		s, err := bbolt.Open(sourceFile, 0700, &bbolt.Options{Timeout: c.Duration("open-timeout"), ReadOnly: true})
		if err != nil {
			return fmt.Errorf("while opening source db: %w", err)
		}

		defer s.Close()

		flt, err := freelistType(c.String("freelist-type"))
		if err != nil {
			return err
		}

		d, err := bbolt.Open(destinationFile, 0700, &bbolt.Options{Timeout: c.Duration("open-timeout"), NoSync: true, PageSize: c.Int("page-size"), FreelistType: flt})
		if err != nil {
			return fmt.Errorf("while opening destination db: %w", err)
		}

		err = bbolt.Compact(d, s, 100000000)

		if err != nil {
			return fmt.Errorf("while compacting db: %w", err)
		}

		return nil

	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL