Skip to content

Commit

Permalink
server: include WAL failover path within the stores status
Browse files Browse the repository at this point in the history
Expand the response from the /_status/stores endpoint to include the store's
data directory and the path to the configured WAL failover secondary if
configured.

Close #119795.

Epic: CRDB-35401
Release note (ops change): Adds node ID, dir and wal_failover_path fields to
the /_status/stores endpoint.
  • Loading branch information
jbowens committed Mar 19, 2024
1 parent 629aee7 commit 857d4d1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 24 deletions.
3 changes: 3 additions & 0 deletions docs/generated/http/full.md
Original file line number Diff line number Diff line change
Expand Up @@ -4090,11 +4090,14 @@ Support status: [reserved](#support-status)
| Field | Type | Label | Description | Support status |
| ----- | ---- | ----- | ----------- | -------------- |
| store_id | [int32](#cockroach.server.serverpb.StoresResponse-int32) | | | [reserved](#support-status) |
| node_id | [int32](#cockroach.server.serverpb.StoresResponse-int32) | | | [reserved](#support-status) |
| encryption_status | [bytes](#cockroach.server.serverpb.StoresResponse-bytes) | | encryption_status is a serialized ccl/storageccl/engineccl/enginepbccl/stats.go::EncryptionStatus protobuf. | [reserved](#support-status) |
| total_files | [uint64](#cockroach.server.serverpb.StoresResponse-uint64) | | Basic file stats when encryption is enabled. Total files/bytes. | [reserved](#support-status) |
| total_bytes | [uint64](#cockroach.server.serverpb.StoresResponse-uint64) | | | [reserved](#support-status) |
| active_key_files | [uint64](#cockroach.server.serverpb.StoresResponse-uint64) | | Files/bytes using the active data key. | [reserved](#support-status) |
| active_key_bytes | [uint64](#cockroach.server.serverpb.StoresResponse-uint64) | | | [reserved](#support-status) |
| dir | [string](#cockroach.server.serverpb.StoresResponse-string) | | dir is the path to the store's data directory on the node. | [reserved](#support-status) |
| wal_failover_path | [string](#cockroach.server.serverpb.StoresResponse-string) | | wal_failover_path encodes the path to the secondary WAL directory used for failover in the event of high write latency to the primary WAL. | [reserved](#support-status) |



Expand Down
5 changes: 5 additions & 0 deletions pkg/roachpb/metadata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ message StoreProperties {
optional bool encrypted = 1 [(gogoproto.nullable) = false];
// read_only indicates whether the store is attached read_only.
optional bool read_only = 2 [(gogoproto.nullable) = false];
// dir is the path to the store's data directory on the node.
optional string dir = 4 [(gogoproto.nullable) = false];
// wal_failover_path encodes the path to the secondary WAL directory used for
// failover in the event of high write latency to the primary WAL.
optional string wal_failover_path = 5;

// disk_properties reports details about the underlying filesystem,
// when the store is supported by a file store. Unset otherwise.
Expand Down
10 changes: 10 additions & 0 deletions pkg/server/serverpb/status.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,11 @@ message StoreDetails {
(gogoproto.casttype) =
"github.com/cockroachdb/cockroach/pkg/roachpb.StoreID"
];
int32 node_id = 7 [
(gogoproto.customname) = "NodeID",
(gogoproto.casttype) =
"github.com/cockroachdb/cockroach/pkg/roachpb.NodeID"
];

// TODO(mberhault): add a lot more information about stores. eg:
// - path
Expand All @@ -1615,6 +1620,11 @@ message StoreDetails {
// Files/bytes using the active data key.
uint64 active_key_files = 5;
uint64 active_key_bytes = 6;
// dir is the path to the store's data directory on the node.
string dir = 8;
// wal_failover_path encodes the path to the secondary WAL directory used for
// failover in the event of high write latency to the primary WAL.
string wal_failover_path = 9 [(gogoproto.nullable) = true];
}

message StoresResponse {
Expand Down
29 changes: 15 additions & 14 deletions pkg/server/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3748,25 +3748,26 @@ func (s *systemStatusServer) Stores(

resp := &serverpb.StoresResponse{}
err = s.stores.VisitStores(func(store *kvserver.Store) error {
storeDetails := serverpb.StoreDetails{
StoreID: store.Ident.StoreID,
}

envStats, err := store.TODOEngine().GetEnvStats()
eng := store.TODOEngine()
envStats, err := eng.GetEnvStats()
if err != nil {
return err
}

if len(envStats.EncryptionStatus) > 0 {
storeDetails.EncryptionStatus = envStats.EncryptionStatus
props := eng.Properties()
storeDetails := serverpb.StoreDetails{
StoreID: store.Ident.StoreID,
NodeID: nodeID,
EncryptionStatus: envStats.EncryptionStatus,
TotalFiles: envStats.TotalFiles,
TotalBytes: envStats.TotalBytes,
ActiveKeyFiles: envStats.ActiveKeyFiles,
ActiveKeyBytes: envStats.ActiveKeyBytes,
Dir: props.Dir,
}
if props.WalFailoverPath != nil {
storeDetails.WalFailoverPath = *props.WalFailoverPath
}
storeDetails.TotalFiles = envStats.TotalFiles
storeDetails.TotalBytes = envStats.TotalBytes
storeDetails.ActiveKeyFiles = envStats.ActiveKeyFiles
storeDetails.ActiveKeyBytes = envStats.ActiveKeyBytes

resp.Stores = append(resp.Stores, storeDetails)

return nil
})
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions pkg/storage/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,6 @@ func newPebble(ctx context.Context, cfg PebbleConfig) (p *Pebble, err error) {
}
}

storeProps := computeStoreProperties(ctx, cfg.Dir, opts.ReadOnly, cfg.Env.Encryption != nil /* encryptionEnabled */)

p = &Pebble{
FS: opts.FS,
readOnly: opts.ReadOnly,
Expand All @@ -1112,7 +1110,7 @@ func newPebble(ctx context.Context, cfg PebbleConfig) (p *Pebble, err error) {
ballastSize: cfg.BallastSize,
maxSize: cfg.MaxSize,
attrs: cfg.Attrs,
properties: storeProps,
properties: computeStoreProperties(ctx, cfg),
settings: cfg.Settings,
env: cfg.Env,
logger: opts.LoggerAndTracer,
Expand Down
17 changes: 10 additions & 7 deletions pkg/storage/store_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,23 @@ import (
"github.com/elastic/gosigar"
)

func computeStoreProperties(
ctx context.Context, dir string, readonly bool, encryptionEnabled bool,
) roachpb.StoreProperties {
func computeStoreProperties(ctx context.Context, cfg PebbleConfig) roachpb.StoreProperties {
props := roachpb.StoreProperties{
ReadOnly: readonly,
Encrypted: encryptionEnabled,
Dir: cfg.Dir,
ReadOnly: cfg.Env.IsReadOnly(),
Encrypted: cfg.Env.Encryption != nil,
}
if cfg.Opts.WALFailover != nil {
props.WalFailoverPath = new(string)
*props.WalFailoverPath = cfg.Opts.WALFailover.Secondary.Dirname
}

// In-memory store?
if dir == "" {
if cfg.Dir == "" {
return props
}

fsprops := getFileSystemProperties(ctx, dir)
fsprops := getFileSystemProperties(ctx, cfg.Dir)
props.FileStoreProperties = &fsprops
return props
}
Expand Down

0 comments on commit 857d4d1

Please sign in to comment.