Fix metastore copy.
parent
3601c3c79f
commit
dc6afbd2e2
56
server.go
56
server.go
|
@ -134,6 +134,14 @@ func (s *Server) shardPath(id uint64) string {
|
|||
return filepath.Join(s.path, "shards", strconv.FormatUint(id, 10))
|
||||
}
|
||||
|
||||
// metaPath returns the path for the metastore.
|
||||
func (s *Server) metaPath() string {
|
||||
if s.path == "" {
|
||||
return ""
|
||||
}
|
||||
return filepath.Join(s.path, "meta")
|
||||
}
|
||||
|
||||
// Open initializes the server from a given path.
|
||||
func (s *Server) Open(path string) error {
|
||||
// Ensure the server isn't already open and there's a path provided.
|
||||
|
@ -143,6 +151,9 @@ func (s *Server) Open(path string) error {
|
|||
return ErrPathRequired
|
||||
}
|
||||
|
||||
// Set the server path.
|
||||
s.path = path
|
||||
|
||||
// Create required directories.
|
||||
if err := os.MkdirAll(path, 0700); err != nil {
|
||||
return err
|
||||
|
@ -152,7 +163,7 @@ func (s *Server) Open(path string) error {
|
|||
}
|
||||
|
||||
// Open metadata store.
|
||||
if err := s.meta.open(filepath.Join(path, "meta")); err != nil {
|
||||
if err := s.meta.open(s.metaPath()); err != nil {
|
||||
return fmt.Errorf("meta: %s", err)
|
||||
}
|
||||
|
||||
|
@ -164,9 +175,6 @@ func (s *Server) Open(path string) error {
|
|||
// TODO: Open shard data stores.
|
||||
// TODO: Associate series ids with shards.
|
||||
|
||||
// Set the server path.
|
||||
s.path = path
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -387,12 +395,43 @@ func (s *Server) Join(u *url.URL, joinURL *url.URL) error {
|
|||
|
||||
// Download the metastore from joining server.
|
||||
joinURL.Path = "/metastore"
|
||||
resp, err = http.Post(joinURL.String(), "application/octet-stream", &buf)
|
||||
resp, err = http.Get(joinURL.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Check response & parse content length.
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("unsuccessful meta copy: status=%d (%s)", resp.StatusCode, joinURL.String())
|
||||
}
|
||||
sz, err := strconv.ParseInt(resp.Header.Get("Content-Length"), 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot parse meta size: %s", err)
|
||||
}
|
||||
|
||||
// Close the metastore.
|
||||
_ = s.meta.close()
|
||||
|
||||
// Overwrite the metastore.
|
||||
f, err := os.Create(s.metaPath())
|
||||
if err != nil {
|
||||
return fmt.Errorf("create meta file: %s", err)
|
||||
}
|
||||
|
||||
// Copy and check size.
|
||||
if _, err := io.CopyN(f, resp.Body, sz); err != nil {
|
||||
_ = f.Close()
|
||||
return fmt.Errorf("copy meta file: %s", err)
|
||||
}
|
||||
_ = f.Close()
|
||||
|
||||
// Reopen metastore.
|
||||
s.meta = &metastore{}
|
||||
if err := s.meta.open(s.metaPath()); err != nil {
|
||||
return fmt.Errorf("reopen meta: %s", err)
|
||||
}
|
||||
|
||||
// Update the ID on the metastore.
|
||||
if err := s.meta.mustUpdate(func(tx *metatx) error {
|
||||
return tx.setID(n.ID)
|
||||
|
@ -400,8 +439,11 @@ func (s *Server) Join(u *url.URL, joinURL *url.URL) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Set the ID on the server.
|
||||
s.id = n.ID
|
||||
// Reload the server.
|
||||
log.Printf("reloading metadata")
|
||||
if err := s.load(); err != nil {
|
||||
return fmt.Errorf("reload: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -8,4 +8,4 @@ echo "inserting data"
|
|||
curl -d '{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2015-01-26T22:01:11.703Z","values": {"value": 100}}]}' -H "Content-Type: application/json" http://localhost:8086/write
|
||||
|
||||
echo "querying data"
|
||||
curl -G http://localhost:8086/query --data-urlencode "db=foo" --data-urlencode "q=SELECT COUNT(value) FROM cpu WHERE time > now() - 1h"
|
||||
curl -G http://localhost:8086/query --data-urlencode "db=foo" --data-urlencode "q=SELECT COUNT(value) FROM \"foo\".\"bar\".cpu WHERE time > now() - 7d"
|
||||
|
|
Loading…
Reference in New Issue