mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Previously, multiple frames with different prefixes were used to separate different data layouts. This included separating standard row/column layouts from inverted column/row layouts as well as storing aggregate information for timestamp data. Unfortunately, this caused frame meta data to be copied between multiple frames and it made it difficult to keep these frames in sync. This commit separates these different physical layouts into `Views`. A `Frame` now has one or more views which represent each layout. Fragments have been moved from under the `Frame` to be contained within the `View`. There are two primary views: - `standard` - `inverse` If a frame has a time quantum, then views are generated for these each of the standard/inverse views. For example a time quantum of `YMDH` for the date `2000-01-02T00:00:00Z` would create the following views: - `standard_2000` - `inverse_2000` - `standard_200001` - `inverse_200001` - `standard_20000102` - `inverse_20000102` From the user's perspective, nothing should change in PQL. Different PQL statements will handle the appropriate view automatically. For example, `Bitmap()` and `Profile()` will fetch using the `standard` view or the `inverse` view, respectively. The `Range()` statement will lookup the appropriate time-based views automatically.
69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
package ctl
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/pilosa/pilosa"
|
|
)
|
|
|
|
// BackupCommand represents a command for backing up a view.
|
|
type BackupCommand struct {
|
|
// Destination host and port.
|
|
Host string
|
|
|
|
// Name of the database, frame, view to backup.
|
|
Database string
|
|
Frame string
|
|
View string
|
|
|
|
// Output file to write to.
|
|
Path string
|
|
|
|
// Standard input/output
|
|
*pilosa.CmdIO
|
|
}
|
|
|
|
// NewBackupCommand returns a new instance of BackupCommand.
|
|
func NewBackupCommand(stdin io.Reader, stdout, stderr io.Writer) *BackupCommand {
|
|
return &BackupCommand{
|
|
CmdIO: pilosa.NewCmdIO(stdin, stdout, stderr),
|
|
}
|
|
}
|
|
|
|
// Run executes the backup.
|
|
func (cmd *BackupCommand) Run(ctx context.Context) error {
|
|
// Validate arguments.
|
|
if cmd.Path == "" {
|
|
return errors.New("output file required")
|
|
}
|
|
|
|
// Create a client to the server.
|
|
client, err := pilosa.NewClient(cmd.Host)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Open output file.
|
|
f, err := os.Create(cmd.Path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer f.Close()
|
|
|
|
// Begin streaming backup.
|
|
if err := client.BackupTo(ctx, f, cmd.Database, cmd.Frame, cmd.View); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Sync & close file to ensure durability.
|
|
if err := f.Sync(); err != nil {
|
|
return err
|
|
} else if err = f.Close(); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|