Skip to content

Commit

Permalink
add json output to Conclude command
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
  • Loading branch information
harshit-gangal committed Sep 11, 2024
1 parent 89d22e3 commit 5facda3
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions go/cmd/vtctldclient/command/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ var (
}
)

type ConcludeTransactionOutput struct {
Dtid string `json:"dtid"`
Message string `json:"message"`
Error string `json:"error,omitempty"`
}

const (
concludeSuccess = "Successfully concluded the distributed transaction"
concludeFailure = "Failed to conclude the distributed transaction"
)

func commandGetUnresolvedTransactions(cmd *cobra.Command, args []string) error {
cli.FinishedParsing(cmd)

Expand All @@ -74,7 +85,7 @@ func commandGetUnresolvedTransactions(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
fmt.Printf("%s\n", data)
fmt.Println(string(data))
return nil
}

Expand All @@ -94,17 +105,25 @@ func commandConcludeTransaction(cmd *cobra.Command, args []string) error {
Shard: shard.Name,
})
}
output := ConcludeTransactionOutput{
Dtid: dtid,
Message: concludeSuccess,
}

_, err = client.ConcludeTransaction(commandCtx,
&vtctldatapb.ConcludeTransactionRequest{
Dtid: dtid,
Participants: participants,
})
if err != nil {
return err
output.Message = concludeFailure
output.Error = err.Error()
}
fmt.Println("Successfully concluded the distributed transaction")

return nil
data, _ := cli.MarshalJSON(output)
fmt.Println(string(data))

return err
}

func init() {
Expand Down

0 comments on commit 5facda3

Please sign in to comment.