-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tag TSM stats with database and retention policy #5844
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,13 +141,7 @@ func (s *Store) loadShards() error { | |
continue | ||
} | ||
|
||
sc := ShardConfig{ | ||
Path: path, | ||
WALPath: walPath, | ||
Database: db, | ||
RetentionPolicy: rp.Name(), | ||
} | ||
shard := NewShard(shardID, s.databaseIndexes[db], sc, s.EngineOptions) | ||
shard := NewShard(shardID, s.databaseIndexes[db], path, walPath, s.EngineOptions) | ||
err = shard.Open() | ||
if err != nil { | ||
return fmt.Errorf("failed to open shard %d: %s", shardID, err) | ||
|
@@ -258,13 +252,8 @@ func (s *Store) CreateShard(database, retentionPolicy string, shardID uint64) er | |
s.databaseIndexes[database] = db | ||
} | ||
|
||
sc := ShardConfig{ | ||
Path: filepath.Join(s.path, database, retentionPolicy, strconv.FormatUint(shardID, 10)), | ||
WALPath: walPath, | ||
Database: database, | ||
RetentionPolicy: retentionPolicy, | ||
} | ||
shard := NewShard(shardID, db, sc, s.EngineOptions) | ||
path := filepath.Join(s.path, database, retentionPolicy, strconv.FormatUint(shardID, 10)) | ||
shard := NewShard(shardID, db, path, walPath, s.EngineOptions) | ||
if err := shard.Open(); err != nil { | ||
return err | ||
} | ||
|
@@ -294,11 +283,11 @@ func (s *Store) deleteShard(shardID uint64) error { | |
return err | ||
} | ||
|
||
if err := os.RemoveAll(sh.config.Path); err != nil { | ||
if err := os.RemoveAll(sh.path); err != nil { | ||
return err | ||
} | ||
|
||
if err := os.RemoveAll(sh.config.WALPath); err != nil { | ||
if err := os.RemoveAll(sh.walPath); err != nil { | ||
return err | ||
} | ||
|
||
|
@@ -322,7 +311,7 @@ func (s *Store) DeleteDatabase(name string) error { | |
|
||
// Close and delete all shards on the database. | ||
for shardID, sh := range s.shards { | ||
if sh.config.Database == name { | ||
if sh.database == name { | ||
// Delete the shard from disk. | ||
if err := s.deleteShard(shardID); err != nil { | ||
return err | ||
|
@@ -351,7 +340,7 @@ func (s *Store) DeleteRetentionPolicy(database, name string) error { | |
// Close and delete all shards under the retention policy on the | ||
// database. | ||
for shardID, sh := range s.shards { | ||
if sh.config.Database == database && sh.config.RetentionPolicy == name { | ||
if sh.database == database && sh.retentionPolicy == name { | ||
// Delete the shard from disk. | ||
if err := s.deleteShard(shardID); err != nil { | ||
return err | ||
|
@@ -390,7 +379,7 @@ func (s *Store) DeleteMeasurement(database, name string) error { | |
|
||
// Remove underlying data. | ||
for _, sh := range s.shards { | ||
if sh.config.Database != database { | ||
if sh.database != database { | ||
continue | ||
} | ||
|
||
|
@@ -479,7 +468,7 @@ func (s *Store) BackupShard(id uint64, since time.Time, w io.Writer) error { | |
return fmt.Errorf("shard %d doesn't exist on this server", id) | ||
} | ||
|
||
path, err := relativePath(s.path, shard.config.Path) | ||
path, err := relativePath(s.path, shard.path) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -493,7 +482,7 @@ func (s *Store) ShardRelativePath(id uint64) (string, error) { | |
if shard == nil { | ||
return "", fmt.Errorf("shard %d doesn't exist on this server", id) | ||
} | ||
return relativePath(s.path, shard.config.Path) | ||
return relativePath(s.path, shard.path) | ||
} | ||
|
||
// DeleteSeries loops through the local shards and deletes the series data and metadata for the passed in series keys | ||
|
@@ -568,7 +557,7 @@ func (s *Store) deleteSeries(database string, seriesKeys []string) error { | |
} | ||
|
||
for _, sh := range s.shards { | ||
if sh.config.Database != database { | ||
if sh.database != database { | ||
continue | ||
} | ||
if err := sh.DeleteSeries(seriesKeys); err != nil { | ||
|
@@ -957,6 +946,20 @@ func IsRetryable(err error) bool { | |
return true | ||
} | ||
|
||
// DecodeStorePath extracts the database and retention policy names | ||
// from a given shard or WAL path. | ||
func DecodeStorePath(shardOrWALPath string) (database, retentionPolicy string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I'm overlooking something here, but why can't you just split on parts := strings.Split(pth, "/")
// check parts is of appropriate length.
return parts[len(parts)-3], parts[len(parts)-2] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assumed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea I had behind I guess the issue here is that you haven't implemented the encode version of this function so I can understand your point about being defensive (someone might update how we store dbs/rps and not update this function). Either way, I can't think of a case where your current approach wouldn't also break if things were changed. |
||
// shardOrWALPath format: /maybe/absolute/base/then/:database/:retentionPolicy/:nameOfShardOrWAL | ||
|
||
// Discard the last part of the path (the shard name or the wal name). | ||
path, _ := filepath.Split(filepath.Clean(shardOrWALPath)) | ||
|
||
// Extract the database and retention policy. | ||
path, rp := filepath.Split(filepath.Clean(path)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably not necessary to call clean multiple times. Should you just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is necessary. See golang/go#9928 for a slightly more detailed discussion.
|
||
_, db := filepath.Split(filepath.Clean(path)) | ||
return db, rp | ||
} | ||
|
||
// relativePath will expand out the full paths passed in and return | ||
// the relative shard path from the store | ||
func relativePath(storePath, shardPath string) (string, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this doesn't need a read lock on
s.mu
, I think it should either have one, or the one inDiskSize
should be removed. There are no concurrent writes tos.path
, so technically no lock is currently needed, but it would be better to be consistent either way..If it's decided to add a read lock to
Path()
then you should also movepath
undermu
in theShard
type definition.