store

package
v0.0.0-...-e215c4f Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Copyright 2018 The Google Authors.

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, initFunc InitFunc)

Types

type DataVersion

type DataVersion int64

type DistLock

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

* DistLock is based on vitess lock.go

func NewDistLock

func NewDistLock(ctx context.Context, client *clientv3.Client, key string, timeout time.Duration) *DistLock

func (*DistLock) KeepAliveOnce

func (dl *DistLock) KeepAliveOnce()

func (*DistLock) Lock

func (dl *DistLock) Lock() (err error)

func (*DistLock) TryLock

func (dl *DistLock) TryLock() (bool, error)

func (*DistLock) Unlock

func (dl *DistLock) Unlock() error

type EtcdStore

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

func (*EtcdStore) Create

func (store *EtcdStore) Create(ctx context.Context, key string, value []byte) error

if key already in , it will check version if same insert else ????? if key is not in , it will put

func (*EtcdStore) CreateWithTTL

func (store *EtcdStore) CreateWithTTL(ctx context.Context, key string, value []byte, ttl time.Duration) error

CreateWithTTL will create the key-value if key already in , it will overwrite if key is not in , it will put

func (*EtcdStore) Delete

func (store *EtcdStore) Delete(ctx context.Context, key string) error

func (*EtcdStore) Get

func (store *EtcdStore) Get(ctx context.Context, key string) ([]byte, error)

func (*EtcdStore) KeepAlive

func (store *EtcdStore) KeepAlive(ctx context.Context, key string, value []byte, ttl time.Duration) (<-chan *clientv3.LeaseKeepAliveResponse, error)

func (*EtcdStore) NewIDGenerate

func (store *EtcdStore) NewIDGenerate(ctx context.Context, key string, base int64, timeout time.Duration) (int64, error)

func (*EtcdStore) NewLock

func (store *EtcdStore) NewLock(ctx context.Context, key string, timeout time.Duration) *DistLock

func (*EtcdStore) PrefixScan

func (store *EtcdStore) PrefixScan(ctx context.Context, prefix string) ([][]byte, [][]byte, error)

func (*EtcdStore) Put

func (store *EtcdStore) Put(ctx context.Context, key string, value []byte) error

put kv if already exits it will overwrite

func (*EtcdStore) PutWithLeaseId

func (store *EtcdStore) PutWithLeaseId(ctx context.Context, key string, value []byte, ttl time.Duration, leaseId clientv3.LeaseID) error

func (*EtcdStore) STM

func (store *EtcdStore) STM(ctx context.Context, apply func(stm concurrency.STM) error) error

func (*EtcdStore) Update

func (store *EtcdStore) Update(ctx context.Context, key string, value []byte) error

func (*EtcdStore) WatchPrefix

func (store *EtcdStore) WatchPrefix(ctx context.Context, key string) (clientv3.WatchChan, error)

type InitFunc

type InitFunc func(serverAddr []string) (Store, error)

type Store

type Store interface {
	Put(ctx context.Context, key string, value []byte) error
	Create(ctx context.Context, key string, value []byte) error
	CreateWithTTL(ctx context.Context, key string, value []byte, ttl time.Duration) error
	KeepAlive(ctx context.Context, key string, value []byte, ttl time.Duration) (<-chan *clientv3.LeaseKeepAliveResponse, error)
	PutWithLeaseId(ctx context.Context, key string, value []byte, ttl time.Duration, leaseId clientv3.LeaseID) error
	Update(ctx context.Context, key string, value []byte) error
	Get(ctx context.Context, key string) ([]byte, error)
	PrefixScan(ctx context.Context, prefix string) ([][]byte, [][]byte, error)
	Delete(ctx context.Context, key string) error
	//Here we should not use the STM structure of etcd, but should define a data structure
	//equivalent to STM in the store, and then convert it in etcdstorage.go, on the one hand, the
	//decoupling of etcd and master logic, on the other hand Easy to extend other types of storage
	STM(ctx context.Context, apply func(stm concurrency.STM) error) error
	NewLock(ctx context.Context, key string, timeout time.Duration) *DistLock
	//it to generate increment unique id
	NewIDGenerate(ctx context.Context, key string, base int64, timeout time.Duration) (int64, error)
	WatchPrefix(ctx context.Context, key string) (clientv3.WatchChan, error)
}

func NewEtcdStore

func NewEtcdStore(serverAddrs []string) (Store, error)

NewEtcdStore is used to register etcd store init function

func OpenStore

func OpenStore(implementation string, serverAddress []string) (Store, error)

type WatcherJob

type WatcherJob interface {
	Put(event *clientv3.Event)
	Delete(event *clientv3.Event)
	Start()
	Stop()
}

Jump to

Keyboard shortcuts

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