@@ -13,6 +13,7 @@ import (
13
13
14
14
"github.com/cockroachdb/cockroach/pkg/keys"
15
15
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb"
16
+ "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvstorage/wag/wagpb"
16
17
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/raftlog"
17
18
"github.com/cockroachdb/cockroach/pkg/raft/raftpb"
18
19
"github.com/cockroachdb/cockroach/pkg/roachpb"
@@ -23,6 +24,7 @@ import (
23
24
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
24
25
"github.com/cockroachdb/errors"
25
26
"github.com/cockroachdb/pebble"
27
+ "github.com/kr/text"
26
28
)
27
29
28
30
// PrintEngineKeyValue attempts to print the given key-value pair to
@@ -136,14 +138,16 @@ func SprintMVCCKeyValue(kv storage.MVCCKeyValue, printKey bool) string {
136
138
137
139
// TODO(pav-kv): some functions here do not check the key, so can accidentally
138
140
// succeed parsing values that have a different "type", and print them in a
139
- // misleading way. Make all these functions key-aware.
141
+ // misleading way. Make all these functions key-aware, and use lookups for
142
+ // efficiency.
140
143
decoders := append (DebugSprintMVCCKeyValueDecoders ,
141
144
tryRangeIDKey ,
142
145
tryRangeDescriptor ,
143
146
tryMeta ,
144
147
tryTxn ,
145
148
tryTimeSeries ,
146
149
tryIntent ,
150
+ tryWAGKey ,
147
151
func (kv storage.MVCCKeyValue ) (string , error ) {
148
152
// No better idea, just print raw bytes and hope that folks use `less -S`.
149
153
return fmt .Sprintf ("%q" , kv .Value ), nil
@@ -465,6 +469,40 @@ func tryRangeIDKey(kv storage.MVCCKeyValue) (string, error) {
465
469
return msg .String (), nil
466
470
}
467
471
472
+ func tryWAGKey (kv storage.MVCCKeyValue ) (string , error ) {
473
+ if ! bytes .HasPrefix (kv .Key .Key , keys .StoreWAGPrefix ()) {
474
+ return "" , errors .New ("not a WAG node key" )
475
+ }
476
+ var node wagpb.Node
477
+ if err := node .Unmarshal (kv .Value ); err != nil { // nolint:protounmarshal
478
+ return "" , err
479
+ }
480
+
481
+ str := fmt .Appendf (nil , "%v %s" , node .Type , node .Addr )
482
+ if c , d := node .Create , node .Destroy ; c != 0 || len (d ) != 0 {
483
+ if c != 0 {
484
+ str = fmt .Appendf (str , " create:%d" , c )
485
+ }
486
+ if len (d ) != 0 {
487
+ str = fmt .Appendf (str , " destroy:%v" , d )
488
+ }
489
+ }
490
+
491
+ if b := node .Mutation .Batch ; len (b ) > 0 {
492
+ bs , err := DecodeWriteBatch (b )
493
+ if err != nil {
494
+ bs = "failed to decode write batch: " + err .Error ()
495
+ }
496
+ str = fmt .Appendf (str , "\n %s" , text .Indent (bs , "> " ))
497
+ }
498
+ if ing := node .Mutation .Ingestion ; ing != nil {
499
+ // TODO(pav-kv): make this format nicely. Currently, this proto is too big.
500
+ str = fmt .Appendf (str , "\n ingestion: %v" , ing )
501
+ }
502
+
503
+ return string (str ), nil
504
+ }
505
+
468
506
func tryMeta (kv storage.MVCCKeyValue ) (string , error ) {
469
507
if ! bytes .HasPrefix (kv .Key .Key , keys .Meta1Prefix ) && ! bytes .HasPrefix (kv .Key .Key , keys .Meta2Prefix ) {
470
508
return "" , errors .New ("not a meta key" )
0 commit comments