client

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: MIT Imports: 29 Imported by: 3

README

InfiniStore Client Library

Client Library for InfiniStore

Examples

A simple client example with PUT/GET:


package main

import (
	"github.com/ds2-lab/infinistore/client"
	"fmt"
	"math/rand"
	"strings"
)

var addrList = "127.0.0.1:6378"

func main() {
	// initial object with random value
	var val []byte
	val = make([]byte, 1024)
	rand.Read(val)

	// parse server address
	addrArr := strings.Split(addrList, ",")

	// initial new ecRedis client
	cli := client.NewClient(10, 2, 32)

	// start dial and PUT/GET
	cli.Dial(addrArr)
	cli.Set("foo", val)
	reader, ok := cli.Get("foo")
	if ok {
		fmt.Printf("GET foo:%s\n", string(reader.ReadAll()))
	}
}

Documentation

Index

Constants

View Source
const (
	LargeObjectThreshold = 30000000 // 20 MB per chunk
	LargeObjectSplitUnit = 10000000 // 10 MB per chunk
)

Variables

View Source
var (
	Hasher   = &hasher{partitionCount: 271}
	ECConfig = consistent.Config{
		PartitionCount:    271,
		ReplicationFactor: 20,
		Load:              1.25,
		Hasher:            Hasher,
	}
	ErrNotFound     = errors.New("not found")
	ErrClient       = errors.New("client internal error")
	ErrDialShortcut = errors.New("failed to dial shortcut, check the RedisAdapter")
	ErrNoRequest    = errors.New("request not present")
	ErrClientClosed = errors.New("client closed")

	CtxKeyECRet = reqCtxKey("ecret")
)
View Source
var (
	// ErrUnexpectedResponse Unexplected response
	ErrUnexpectedResponse      = errors.New("unexpected response")
	ErrUnexpectedPreflightPong = errors.New("unexpected preflight pong")
	ErrMaxPreflightsReached    = errors.New("max preflight attempts reached")
	ErrAbandonRequest          = errors.New("abandon request")
	ErrKeyNotFound             = errors.New("key not found")
	ErrEmptyChunk              = errors.New("empty chunk")
	ErrUnknown                 = errors.New("unknown error")
	RequestAttempts            = 3

	OccupantReadAllCloser = &JoinReader{}
)
View Source
var (
	// MaxLambdaStores This setting will avoid network contention. Must equal or smaller than config.NumLambdaClusters
	MaxLambdaStores int = config.SliceSize

	// Timeout The timeout of a single operation
	Timeout = 1 * time.Second

	// Timeout The timeout for sending header fields, and reading response headers.
	HeaderTimeout = 1 * time.Second
)
View Source
var (
	ErrInvalidSize         = errors.New("invalid size")
	ErrInvalidNumFragments = errors.New("invalid number of fragments")
	ErrAbandon             = errors.New("late chunk abandoned")
	ErrCorrupted           = errors.New("data corrupted")
)
View Source
var (
	// ErrNotImplemented The error indicates specified function is not implemented.
	ErrNotImplemented = errors.New("not implemented")
)

Functions

func CreateLog

func CreateLog(opts map[string]interface{})

CreateLog Enabling evaluation log in client lib.

func FlushLog

func FlushLog()

FlushLog Flush logs to the file.y

func NewEncoder

func NewEncoder(dataShards int, parityShards int, ecMaxGoroutine int) reedsolomon.Encoder

NewEncoder Helper function to create a encoder

func SetLogger

func SetLogger(l func(nanolog.Handle, ...interface{}) error)

SetLogger set customized evaluation logger

Types

type ByteJoiner

type ByteJoiner func(io.Writer, [][]byte, int) error

Joiner The utility function helps to concat an array of []bytes.

type Client

type Client struct {
	EC           reedsolomon.Encoder
	Ring         *consistent.Consistent
	DataShards   int
	ParityShards int
	Shards       int
	// contains filtered or unexported fields
}

Client defines a InfiniStore client

func NewClient

func NewClient(dataShards int, parityShards int, ecMaxGoroutine int) *Client

NewClient Create a client instance.

func (*Client) Close

func (c *Client) Close()

Close Close the client

func (*Client) Dial

func (c *Client) Dial(addrArr []string) bool

Dial Dial proxies

func (*Client) EcGet

func (c *Client) EcGet(key string, args ...interface{}) (string, ReadAllCloser, error)

EcGet Internal API returns reqId, reader, and a bool indicate error. If not found, the reader will be nil.

func (*Client) EcSet

func (c *Client) EcSet(key string, val []byte, args ...interface{}) (string, error)

EcSet Internal API

func (*Client) Get

func (c *Client) Get(key string) (ReadAllCloser, bool)

Get New get API. No size is required. Internal error if the bool is set to false

func (*Client) ReadResponse

func (c *Client) ReadResponse(req client.Request) error

func (*Client) Set

func (c *Client) Set(key string, val []byte) bool

Set New set API Internal error if result is false.

type ClientConnMeta

type ClientConnMeta struct {
	Addr    string
	AddrIdx int
}

type ClientRequest

type ClientRequest struct {
	client.Request
	Cmd    string
	ReqId  string
	Cancel context.CancelFunc
	// contains filtered or unexported fields
}

func (*ClientRequest) Conn

func (r *ClientRequest) Conn() *client.Conn

func (*ClientRequest) SetConn

func (r *ClientRequest) SetConn(cn *client.Conn)

type DummyEncoder

type DummyEncoder struct {
	DataShards int
}

DummyEncoder Dummpy encoder to support 0 parity.

func (*DummyEncoder) Encode

func (enc *DummyEncoder) Encode(shards [][]byte) error

Encode reedsolomon.Encoder implmentation

func (*DummyEncoder) Join

func (enc *DummyEncoder) Join(dst io.Writer, shards [][]byte, outSize int) error

Join reedsolomon.Encoder implmentation

func (*DummyEncoder) Reconstruct

func (enc *DummyEncoder) Reconstruct(shards [][]byte) (err error)

Reconstruct reedsolomon.Encoder implmentation

func (*DummyEncoder) ReconstructData

func (enc *DummyEncoder) ReconstructData(shards [][]byte) (err error)

ReconstructData reedsolomon.Encoder implmentation

func (*DummyEncoder) Split

func (enc *DummyEncoder) Split(data []byte) ([][]byte, error)

Split reedsolomon.Encoder implmentation

func (*DummyEncoder) Update

func (enc *DummyEncoder) Update(shards [][]byte, newDatashards [][]byte) error

Update reedsolomon.Encoder implmentation

func (*DummyEncoder) Verify

func (enc *DummyEncoder) Verify(shards [][]byte) (bool, error)

Verify reedsolomon.Encoder implmentation

type JoinReader

type JoinReader struct {
	io.Reader
	io.Closer
	// contains filtered or unexported fields
}

JoinReader A ReadAllCloser implementation that can concat an array of []bytes

func NewByteJoinReader

func NewByteJoinReader(data [][]byte, size int, joiner ByteJoiner) *JoinReader

NewByteJoinReader Create the join reader for []byte array

func NewJoinReader

func NewJoinReader(data interface{}, size int) *JoinReader

func (*JoinReader) Close

func (r *JoinReader) Close() error

Close ReaderAllCloser implementation Drain reader if any read.

func (*JoinReader) Len

func (r *JoinReader) Len() int

Len ReaderAllCloser implementation

func (*JoinReader) Read

func (r *JoinReader) Read(p []byte) (n int, err error)

Read io.Reader implementation

func (*JoinReader) ReadAll

func (r *JoinReader) ReadAll() (buf []byte, err error)

ReadAll ReaderAllCloser implementation

type PooledClient

type PooledClient struct {
	// Concurrency supported
	Concurrency int

	// Default # of data shards
	NumDataShards int

	// Default # of parity shards
	NumParityShards int

	// Max goroutine used by Erasure Coding
	ECMaxGoroutine int
	// contains filtered or unexported fields
}

func NewPooledClient

func NewPooledClient(addrArr []string, options ...func(*PooledClient)) *PooledClient

func (*PooledClient) Close

func (c *PooledClient) Close()

func (*PooledClient) Get

func (c *PooledClient) Get(key string) (ReadAllCloser, error)

func (*PooledClient) Set

func (c *PooledClient) Set(key string, val []byte) error

type ReadAllCloser

type ReadAllCloser interface {
	io.Reader
	io.Closer

	Len() int
	ReadAll() ([]byte, error)
}

ReadAllCloser Allows to get length and read all from the reader.

type WaitGroup

type WaitGroup interface {
	Add(int)
	Done()
	Wait()
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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