mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-09 04:17:51 +00:00
load schema
This commit is contained in:
parent
9d24fb07b7
commit
42b465b80c
3 changed files with 52 additions and 5 deletions
|
|
@ -46,6 +46,14 @@ func newRestoreCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command
|
|||
}
|
||||
flags := restoreCmd.Flags()
|
||||
flags.StringVarP(&c.Host, "host", "", "localhost:10101", "host:port of Pilosa.")
|
||||
flags.StringVarP(&c.Path, "source", "s", "", "pilosa backup file")
|
||||
ctl.SetTLSConfig(
|
||||
flags, "",
|
||||
&c.TLS.CertificatePath,
|
||||
&c.TLS.CertificateKeyPath,
|
||||
&c.TLS.CACertPath,
|
||||
&c.TLS.SkipVerify,
|
||||
&c.TLS.EnableClientVerification)
|
||||
|
||||
return restoreCmd
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,23 +18,30 @@ import (
|
|||
"archive/tar"
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
gohttp "net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/pilosa/pilosa/v2"
|
||||
"github.com/pilosa/pilosa/v2/http"
|
||||
"github.com/pilosa/pilosa/v2/server"
|
||||
"github.com/pilosa/pilosa/v2/topology"
|
||||
"github.com/pilosa/pilosa/v2/vprint"
|
||||
)
|
||||
|
||||
// RestoreCommand represents a command for restoring a backup to
|
||||
type RestoreCommand struct {
|
||||
// Filepath to the backup file.
|
||||
Path string
|
||||
Host string
|
||||
client *http.InternalClient
|
||||
Path string
|
||||
Host string
|
||||
// Reusable client.
|
||||
client pilosa.InternalClient
|
||||
|
||||
// Standard input/output
|
||||
*pilosa.CmdIO
|
||||
TLS server.TLSConfig
|
||||
}
|
||||
|
||||
// NewRestoreCommand returns a new instance of RestoreCommand.
|
||||
|
|
@ -79,6 +86,13 @@ func readSchema(path string) string {
|
|||
|
||||
// Run executes the restore.
|
||||
func (cmd *RestoreCommand) Run(ctx context.Context) error {
|
||||
// Create a client to the server.
|
||||
client, err := commandClient(cmd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("creating client: %w", err)
|
||||
}
|
||||
cmd.client = client
|
||||
|
||||
f, err := os.Open(cmd.Path)
|
||||
if err != nil {
|
||||
return (err)
|
||||
|
|
@ -112,7 +126,22 @@ func (cmd *RestoreCommand) Run(ctx context.Context) error {
|
|||
//TODO (twg) load row attributes keys
|
||||
//TODO (twg) load col attributes keys
|
||||
//TODO (twg) load idalloc
|
||||
nodes, err := cmd.client.Nodes(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var primary *topology.Node
|
||||
for _, node := range nodes {
|
||||
if node.IsPrimary {
|
||||
primary = node
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
c := &gohttp.Client{}
|
||||
if primary == nil {
|
||||
return errors.New("no primary")
|
||||
}
|
||||
for {
|
||||
header, err := tarReader.Next()
|
||||
if err == io.EOF {
|
||||
|
|
@ -123,6 +152,14 @@ func (cmd *RestoreCommand) Run(ctx context.Context) error {
|
|||
switch record[0] {
|
||||
case "schema":
|
||||
vprint.VV("Load Schema")
|
||||
url := primary.URI.Path("/schema")
|
||||
vprint.VV("SCHEMA %v", url)
|
||||
//schemaBytes, err := ioutil.ReadAll(tarReader)
|
||||
_, err = c.Post(url, "application/json", tarReader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case "idalloc":
|
||||
vprint.VV("Load ids")
|
||||
default:
|
||||
|
|
@ -163,3 +200,6 @@ func (cmd *RestoreCommand) Run(ctx context.Context) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
func (cmd *RestoreCommand) TLSHost() string { return cmd.Host }
|
||||
|
||||
func (cmd *RestoreCommand) TLSConfiguration() server.TLSConfig { return cmd.TLS }
|
||||
|
|
|
|||
|
|
@ -199,7 +199,6 @@ func (c *InternalClient) Schema(ctx context.Context) ([]*pilosa.IndexInfo, error
|
|||
}
|
||||
return rsp.Indexes, nil
|
||||
}
|
||||
|
||||
func (c *InternalClient) PostSchema(ctx context.Context, uri *pnet.URI, s *pilosa.Schema, remote bool) error {
|
||||
u := uri.Path(fmt.Sprintf("/schema?remote=%v", remote))
|
||||
buf, err := json.Marshal(s)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue