twopc

package
v0.0.0-...-020e20f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package twopc provides a implementation of Two-Phase Commit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Coordinator

type Coordinator struct {
	// contains filtered or unexported fields
}

Coordinator is a 2PC coordinator.

func NewCoordinator

func NewCoordinator(opt *Options) *Coordinator

NewCoordinator creates a new 2PC Coordinator.

func (*Coordinator) Put

func (c *Coordinator) Put(workers []Worker, wb WriteBatch) (result interface{}, err error)

Put initiates a 2PC process to apply given WriteBatch on all workers.

type Hook

type Hook func(ctx context.Context) error

Hook are called during 2PC running.

type Options

type Options struct {
	// contains filtered or unexported fields
}

Options represents options of a 2PC coordinator.

func NewOptions

func NewOptions(timeout time.Duration) *Options

NewOptions returns a new coordinator option.

func NewOptionsWithCallback

func NewOptionsWithCallback(timeout time.Duration,
	beforePrepare Hook, beforeCommit Hook, beforeRollback Hook, afterCommit Hook) *Options

NewOptionsWithCallback returns a new coordinator option with before prepare/commit/rollback callback.

type Worker

type Worker interface {
	Prepare(ctx context.Context, wb WriteBatch) error
	Commit(ctx context.Context, wb WriteBatch) (interface{}, error)
	Rollback(ctx context.Context, wb WriteBatch) error
}

Worker represents a 2PC worker who implements Prepare, Commit, and Rollback.

type WriteBatch

type WriteBatch interface{}

WriteBatch is an empty interface which will be passed to Worker methods.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL