CovenantSQL: Index | Files

package twopc

import ""

Package twopc provides a implementation of Two-Phase Commit.


Package Files

doc.go twopc.go

type Coordinator Uses

type Coordinator struct {
    // contains filtered or unexported fields

Coordinator is a 2PC coordinator.

func NewCoordinator Uses

func NewCoordinator(opt *Options) *Coordinator

NewCoordinator creates a new 2PC Coordinator.

func (*Coordinator) Put Uses

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 Uses

type Hook func(ctx context.Context) error

Hook are called during 2PC running.

type Options Uses

type Options struct {
    // contains filtered or unexported fields

Options represents options of a 2PC coordinator.

func NewOptions Uses

func NewOptions(timeout time.Duration) *Options

NewOptions returns a new coordinator option.

func NewOptionsWithCallback Uses

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 Uses

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 Uses

type WriteBatch interface{}

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

Package twopc imports 4 packages (graph) and is imported by 2 packages. Updated 2019-05-05. Refresh now. Tools for package owners.