You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: transaction.go
    path of file: ./repos/google-cloud-go/spanner/test/cloudexecutor/executor/actions
    
    the code of the file until where you have to start completion: // Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package actions

import (
	"context"
	"log"
	"time"

	"cloud.google.com/go/spanner"
	sppb "cloud.google.com/go/spanner/apiv1/spannerpb"
	"cloud.google.com/go/spanner/executor/apiv1/executorpb"
	"cloud.google.com/go/spanner/test/cloudexecutor/executor/internal/outputstream"
	"cloud.google.com/go/spanner/test/cloudexecutor/executor/internal/utility"
	"google.golang.org/api/option"
	spb "google.golang.org/genproto/googleapis/rpc/status"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	"google.golang.org/protobuf/types/known/timestamppb"
)

// StartTxnHandler holds the necessary components and options required for start transaction action.
type StartTxnHandler struct {
	Action        *executorpb.StartTransactionAction
	FlowContext   *ExecutionFlowContext
	OutcomeSender *outputstream.OutcomeSender
	Options       []option.ClientOption
}

// ExecuteAction that starts a read-write or read-only transaction.
func (h *StartTxnHandler) ExecuteAction(ctx context.Context) error {
	h.FlowContext.mu.Lock()
	defer h.FlowContext.mu.Unlock()
	if h.FlowContext.Database == "" {
		return h.OutcomeSender.FinishWithError(spanner.ToSpannerError(status.Error(codes.Invalid
    
func (h *FinishTxnHandler) ExecuteAction(ctx context.Context) error {
	h.FlowContext.mu.Lock()
	defer h.FlowContext.mu.Unlock()
	log.Printf("Finishing transaction %s\n %v", h.FlowContext.transactionSeed, h.Action)

	if h.FlowContext.numPendingReads > 0 {
		return h.OutcomeSender.FinishWithError(spanner.ToSpannerError(status.Error(codes.FailedPrecondition, "Reads pending when trying to finish")))
	}
	outcome := &executorpb.SpannerActionOutcome{Status: &spb.Status{Code: int32(codes.OK)}}

	// Finish active transaction in given finishMode, then send outcome back to client.
	if h.FlowContext.roTxn != nil {
		// Finish a read-only transaction. Note that timestamp may not be available
		// if there were no reads or queries.
		ts, err := h.FlowContext.roTxn.Timestamp()
		if err != nil {
			return h.OutcomeSender.FinishWithError(err)
		}
		outcome.CommitTime = timestamppb.New(ts)

		h.FlowContext.roTxn.Close()
		h.FlowContext.clear()
		return h.OutcomeSender.SendOutcome(outcome)
	}

	if h.FlowContext.rwTxn != nil {
		// Finish a read-write transaction.
		txnFinishMode := h.Action.GetMode()
		restarted, ts, spanErr, internalErr := h.FlowContext.finish(ctx, txnFinishMode)
		if internalErr != nil {
			log.Printf("Unexpected error when finishing read-write transaction: %s", internalErr.Error())
			return h.OutcomeSender.FinishWithError(internalErr)
		} else if spanErr != nil {
			outcome.Status = utility.ErrToStatus(spanErr)
			h.FlowContext.clear()
		} else if restarted {
			log.Println("Transaction restarted")
			transactionRestarted := true
			outcome.TransactionRestarted = &transactionRestarted
		} else {
			if ts != nil {
				outcome.CommitTime = timestamppb.New(*ts)
			}
			h.FlowContext.clear()
		}
		return h.OutcomeSender.SendOutcome(outcome)
	}

	if h.FlowContext.batchTxn != nil {
		return h.OutcomeSender.FinishWithError(spanner.ToSpannerError(status.Error(codes.InvalidArgument, "Can't commit/abort a batch transaction")))
	}
	return h.OutcomeSender.FinishWithError(spanner.ToSpannerError(status.Error(codes.InvalidArgument, "no currently active transaction")))
}