rados

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2020 License: MIT Imports: 9 Imported by: 125

Documentation

Overview

Package rados contains a set of wrappers around Ceph's librados API.

Index

Constants

View Source
const (
	// ErrNotFound indicates a missing resource.
	ErrNotFound = radosError(-C.ENOENT)
	// ErrPermissionDenied indicates a permissions issue.
	ErrPermissionDenied = radosError(-C.EPERM)
	// ErrObjectExists indicates that an exclusive object creation failed.
	ErrObjectExists = radosError(-C.EEXIST)

	// RadosErrorNotFound indicates a missing resource.
	//
	// Deprecated: use ErrNotFound instead
	RadosErrorNotFound = ErrNotFound
	// RadosErrorPermissionDenied indicates a permissions issue.
	//
	// Deprecated: use ErrPermissionDenied instead
	RadosErrorPermissionDenied = ErrPermissionDenied
)
View Source
const (
	// CreateExclusive if used with IOContext.Create() and the object
	// already exists, the function will return an error.
	CreateExclusive = C.LIBRADOS_CREATE_EXCLUSIVE
	// CreateIdempotent if used with IOContext.Create() and the object
	// already exists, the function will not return an error.
	CreateIdempotent = C.LIBRADOS_CREATE_IDEMPOTENT
)
View Source
const (
	// AllNamespaces is used to reset a selected namespace to all
	// namespaces. See the IOContext SetNamespace function.
	AllNamespaces = C.LIBRADOS_ALL_NSPACES

	// RadosAllNamespaces is used to reset a selected namespace to all
	// namespaces. See the IOContext SetNamespace function.
	//
	// Deprecated: use AllNamespaces instead
	RadosAllNamespaces = AllNamespaces
)

SnapHead is the representation of LIBRADOS_SNAP_HEAD from librados. SnapHead can be used to reset the IOContext to stop reading from a snapshot.

Variables

View Source
var (
	// ErrNotConnected is returned when functions are called
	// without a RADOS connection.
	ErrNotConnected = errors.New("RADOS not connected")
	// ErrEmptyArgument may be returned if a function argument is passed
	// a zero-length slice or map.
	ErrEmptyArgument = errors.New("Argument must contain at least one item")
	// ErrInvalidIOContext may be returned if an api call requires an IOContext
	// but IOContext is not ready for use.
	ErrInvalidIOContext = errors.New("IOContext is not ready for use")
)

Functions

func Version

func Version() (int, int, int)

Version returns the major, minor, and patch components of the version of the RADOS library linked against.

Types

type ClusterRef

type ClusterRef C.rados_t

ClusterRef represents a fundamental RADOS cluster connection.

type ClusterStat

type ClusterStat struct {
	Kb          uint64
	Kb_used     uint64
	Kb_avail    uint64
	Num_objects uint64
}

ClusterStat represents Ceph cluster statistics.

type Conn

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

Conn is a connection handle to a Ceph cluster.

func NewConn

func NewConn() (*Conn, error)

NewConn creates a new connection object. It returns the connection and an error, if any.

func NewConnWithClusterAndUser

func NewConnWithClusterAndUser(clusterName string, userName string) (*Conn, error)

NewConnWithClusterAndUser creates a new connection object for a specific cluster and username. It returns the connection and an error, if any.

func NewConnWithUser

func NewConnWithUser(user string) (*Conn, error)

NewConnWithUser creates a new connection object with a custom username. It returns the connection and an error, if any.

func (*Conn) Cluster

func (c *Conn) Cluster() ClusterRef

Cluster returns the underlying RADOS cluster reference for this Conn.

func (*Conn) Connect

func (c *Conn) Connect() error

Connect establishes a connection to a RADOS cluster. It returns an error, if any.

func (*Conn) DeletePool

func (c *Conn) DeletePool(name string) error

DeletePool deletes a pool and all the data inside the pool.

func (*Conn) GetClusterStats

func (c *Conn) GetClusterStats() (stat ClusterStat, err error)

GetClusterStats returns statistics about the cluster associated with the connection.

func (*Conn) GetConfigOption

func (c *Conn) GetConfigOption(name string) (value string, err error)

GetConfigOption returns the value of the Ceph configuration option identified by the given name.

func (*Conn) GetFSID

func (c *Conn) GetFSID() (fsid string, err error)

GetFSID returns the fsid of the cluster as a hexadecimal string. The fsid is a unique identifier of an entire Ceph cluster.

func (*Conn) GetInstanceID

func (c *Conn) GetInstanceID() uint64

GetInstanceID returns a globally unique identifier for the cluster connection instance.

func (*Conn) GetPoolByID

func (c *Conn) GetPoolByID(id int64) (string, error)

GetPoolByID returns the name of a pool by a given ID.

func (*Conn) GetPoolByName

func (c *Conn) GetPoolByName(name string) (int64, error)

GetPoolByName returns the ID of the pool with a given name.

func (*Conn) ListPools

func (c *Conn) ListPools() (names []string, err error)

ListPools returns the names of all existing pools.

func (*Conn) MakePool

func (c *Conn) MakePool(name string) error

MakePool creates a new pool with default settings.

func (*Conn) MgrCommand added in v0.4.0

func (c *Conn) MgrCommand(args [][]byte) ([]byte, string, error)

MgrCommand sends a command to a ceph-mgr.

func (*Conn) MgrCommandWithInputBuffer added in v0.4.0

func (c *Conn) MgrCommandWithInputBuffer(args [][]byte, inputBuffer []byte) ([]byte, string, error)

MgrCommandWithInputBuffer sends a command, with an input buffer, to a ceph-mgr.

Implements:

int rados_mgr_command(rados_t cluster, const char **cmd,
                       size_t cmdlen, const char *inbuf,
                       size_t inbuflen, char **outbuf,
                       size_t *outbuflen, char **outs,
                        size_t *outslen);

func (*Conn) MonCommand

func (c *Conn) MonCommand(args []byte) ([]byte, string, error)

MonCommand sends a command to one of the monitors

func (*Conn) MonCommandTarget added in v0.4.0

func (c *Conn) MonCommandTarget(name string, args [][]byte) ([]byte, string, error)

MonCommandTarget sends a command to a specified monitor.

func (*Conn) MonCommandTargetWithInputBuffer added in v0.4.0

func (c *Conn) MonCommandTargetWithInputBuffer(
	name string, args [][]byte, inputBuffer []byte) ([]byte, string, error)

MonCommandTargetWithInputBuffer sends a command, with an input buffer, to a specified monitor.

Implements:

int rados_mon_command_target(rados_t cluster, const char *name,
                             const char **cmd, size_t cmdlen,
                             const char *inbuf, size_t inbuflen,
                             char **outbuf, size_t *outbuflen,
                             char **outs, size_t *outslen);

func (*Conn) MonCommandWithInputBuffer

func (c *Conn) MonCommandWithInputBuffer(args, inputBuffer []byte) ([]byte, string, error)

MonCommandWithInputBuffer sends a command to one of the monitors, with an input buffer

func (*Conn) OpenIOContext

func (c *Conn) OpenIOContext(pool string) (*IOContext, error)

OpenIOContext creates and returns a new IOContext for the given pool.

Implements:

int rados_ioctx_create(rados_t cluster, const char *pool_name,
                       rados_ioctx_t *ioctx);

func (*Conn) OsdCommand added in v0.4.0

func (c *Conn) OsdCommand(osd int, args [][]byte) ([]byte, string, error)

OsdCommand sends a command to the specified ceph OSD.

func (*Conn) OsdCommandWithInputBuffer added in v0.4.0

func (c *Conn) OsdCommandWithInputBuffer(
	osd int, args [][]byte, inputBuffer []byte) ([]byte, string, error)

OsdCommandWithInputBuffer sends a command, with an input buffer, to the specified ceph OSD.

Implements:

int rados_osd_command(rados_t cluster, int osdid,
                                     const char **cmd, size_t cmdlen,
                                     const char *inbuf, size_t inbuflen,
                                     char **outbuf, size_t *outbuflen,
                                     char **outs, size_t *outslen);

func (*Conn) PGCommand

func (c *Conn) PGCommand(pgid []byte, args [][]byte) ([]byte, string, error)

PGCommand sends a command to one of the PGs

Implements:

int rados_pg_command(rados_t cluster, const char *pgstr,
                     const char **cmd, size_t cmdlen,
                     const char *inbuf, size_t inbuflen,
                     char **outbuf, size_t *outbuflen,
                     char **outs, size_t *outslen);

func (*Conn) PGCommandWithInputBuffer

func (c *Conn) PGCommandWithInputBuffer(pgid []byte, args [][]byte, inputBuffer []byte) ([]byte, string, error)

PGCommandWithInputBuffer sends a command to one of the PGs, with an input buffer

Implements:

int rados_pg_command(rados_t cluster, const char *pgstr,
                     const char **cmd, size_t cmdlen,
                     const char *inbuf, size_t inbuflen,
                     char **outbuf, size_t *outbuflen,
                     char **outs, size_t *outslen);

func (*Conn) ParseCmdLineArgs

func (c *Conn) ParseCmdLineArgs(args []string) error

ParseCmdLineArgs configures the connection from command line arguments.

This function passes a placeholder value to Ceph as argv[0], see ParseConfigArgv for a version of this function that allows the caller to specify argv[0].

func (*Conn) ParseConfigArgv added in v0.5.0

func (c *Conn) ParseConfigArgv(argv []string) error

ParseConfigArgv configures the connection using a unix style command line argument vector.

Implements:

int rados_conf_parse_argv(rados_t cluster, int argc,
                          const char **argv);

func (*Conn) ParseDefaultConfigEnv

func (c *Conn) ParseDefaultConfigEnv() error

ParseDefaultConfigEnv configures the connection from the default Ceph environment variable CEPH_ARGS.

func (*Conn) PingMonitor

func (c *Conn) PingMonitor(id string) (string, error)

PingMonitor sends a ping to a monitor and returns the reply.

func (*Conn) ReadConfigFile

func (c *Conn) ReadConfigFile(path string) error

ReadConfigFile configures the connection using a Ceph configuration file.

func (*Conn) ReadDefaultConfigFile

func (c *Conn) ReadDefaultConfigFile() error

ReadDefaultConfigFile configures the connection using a Ceph configuration file located at default locations.

func (*Conn) SetConfigOption

func (c *Conn) SetConfigOption(option, value string) error

SetConfigOption sets the value of the configuration option identified by the given name.

func (*Conn) Shutdown

func (c *Conn) Shutdown()

Shutdown disconnects from the cluster.

func (*Conn) WaitForLatestOSDMap

func (c *Conn) WaitForLatestOSDMap() error

WaitForLatestOSDMap blocks the caller until the latest OSD map has been retrieved.

type CreateOption

type CreateOption int

CreateOption is passed to IOContext.Create() and should be one of CreateExclusive or CreateIdempotent.

type IOContext

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

IOContext represents a context for performing I/O within a pool.

func (*IOContext) Append

func (ioctx *IOContext) Append(oid string, data []byte) error

Append appends len(data) bytes to the object with key oid. The object is appended with the provided data. If the object exists, it is atomically appended to. It returns an error, if any.

func (*IOContext) BreakLock

func (ioctx *IOContext) BreakLock(oid, name, client, cookie string) (int, error)

BreakLock releases a shared or exclusive lock on an object, which was taken by the specified client.

func (*IOContext) CleanOmap

func (ioctx *IOContext) CleanOmap(oid string) error

CleanOmap clears the omap `oid`

func (*IOContext) Create

func (ioctx *IOContext) Create(oid string, exclusive CreateOption) error

Create a new object with key oid.

Implements:

void rados_write_op_create(rados_write_op_t write_op, int exclusive,
                           const char* category)

func (*IOContext) CreateSnap added in v0.5.0

func (ioctx *IOContext) CreateSnap(snapName string) error

CreateSnap creates a pool-wide snapshot.

Implements: int rados_ioctx_snap_create(rados_ioctx_t io, const char *snapname)

func (*IOContext) Delete

func (ioctx *IOContext) Delete(oid string) error

Delete deletes the object with key oid. It returns an error, if any.

func (*IOContext) Destroy

func (ioctx *IOContext) Destroy()

Destroy informs librados that the I/O context is no longer in use. Resources associated with the context may not be freed immediately, and the context should not be used again after calling this method.

func (*IOContext) GetAllOmapValues

func (ioctx *IOContext) GetAllOmapValues(oid string, startAfter string, filterPrefix string, iteratorSize int64) (map[string][]byte, error)

GetAllOmapValues fetches all the keys and their values from an omap and returns then as a map `startAfter`: retrieve only the keys after this specified one `filterPrefix`: retrieve only the keys beginning with this prefix `iteratorSize`: internal number of keys to fetch during a read operation

func (*IOContext) GetLastVersion added in v0.5.0

func (ioctx *IOContext) GetLastVersion() (uint64, error)

GetLastVersion will return the version number of the last object read or written to.

Implements:

uint64_t rados_get_last_version(rados_ioctx_t io);

func (*IOContext) GetOmapValues

func (ioctx *IOContext) GetOmapValues(oid string, startAfter string, filterPrefix string, maxReturn int64) (map[string][]byte, error)

GetOmapValues fetches a set of keys and their values from an omap and returns then as a map `startAfter`: retrieve only the keys after this specified one `filterPrefix`: retrieve only the keys beginning with this prefix `maxReturn`: retrieve no more than `maxReturn` key/value pairs

func (*IOContext) GetPoolID added in v0.5.0

func (ioctx *IOContext) GetPoolID() int64

GetPoolID returns the pool ID associated with the I/O context.

Implements:

int64_t rados_ioctx_get_id(rados_ioctx_t io)

func (*IOContext) GetPoolName

func (ioctx *IOContext) GetPoolName() (name string, err error)

GetPoolName returns the name of the pool associated with the I/O context.

func (*IOContext) GetPoolStats

func (ioctx *IOContext) GetPoolStats() (stat PoolStat, err error)

GetPoolStats returns a set of statistics about the pool associated with this I/O context.

Implements:

int rados_ioctx_pool_stat(rados_ioctx_t io,
                          struct rados_pool_stat_t *stats);

func (*IOContext) GetSnapName added in v0.5.0

func (ioctx *IOContext) GetSnapName(snapID SnapID) (string, error)

GetSnapName returns the name of a pool snapshot with the given snapshot ID.

Implements:

int rados_ioctx_snap_get_name(rados_ioctx_t io, rados_snap_t id, char *name, int maxlen)

func (*IOContext) GetSnapStamp added in v0.5.0

func (ioctx *IOContext) GetSnapStamp(snapID SnapID) (time.Time, error)

GetSnapStamp returns the time of the pool snapshot creation.

Implements:

int rados_ioctx_snap_get_stamp(rados_ioctx_t io, rados_snap_t id, time_t *t)

func (*IOContext) GetXattr

func (ioctx *IOContext) GetXattr(object string, name string, data []byte) (int, error)

GetXattr gets an xattr with key `name`, it returns the length of the key read or an error if not successful

func (*IOContext) Iter

func (ioctx *IOContext) Iter() (*Iter, error)

Iter returns a Iterator object that can be used to list the object names in the current pool

func (*IOContext) ListLockers

func (ioctx *IOContext) ListLockers(oid, name string) (*LockInfo, error)

ListLockers lists clients that have locked the named object lock and information about the lock. The number of bytes required in each buffer is put in the corresponding size out parameter. If any of the provided buffers are too short, -ERANGE is returned after these sizes are filled in.

func (*IOContext) ListObjects

func (ioctx *IOContext) ListObjects(listFn ObjectListFunc) error

ListObjects lists all of the objects in the pool associated with the I/O context, and called the provided listFn function for each object, passing to the function the name of the object. Call SetNamespace with RadosAllNamespaces before calling this function to return objects from all namespaces

func (*IOContext) ListOmapValues

func (ioctx *IOContext) ListOmapValues(oid string, startAfter string, filterPrefix string, maxReturn int64, listFn OmapListFunc) error

ListOmapValues iterates over the keys and values in an omap by way of a callback function.

`startAfter`: iterate only on the keys after this specified one `filterPrefix`: iterate only on the keys beginning with this prefix `maxReturn`: iterate no more than `maxReturn` key/value pairs `listFn`: the function called at each iteration

func (*IOContext) ListSnaps added in v0.5.0

func (ioctx *IOContext) ListSnaps() ([]SnapID, error)

ListSnaps returns a slice containing the SnapIDs of existing pool snapshots.

Implements:

int rados_ioctx_snap_list(rados_ioctx_t io, rados_snap_t *snaps, int maxlen)

func (*IOContext) ListXattrs

func (ioctx *IOContext) ListXattrs(oid string) (map[string][]byte, error)

ListXattrs lists all the xattrs for an object. The xattrs are returned as a mapping of string keys and byte-slice values.

func (*IOContext) LockExclusive

func (ioctx *IOContext) LockExclusive(oid, name, cookie, desc string, duration time.Duration, flags *byte) (int, error)

LockExclusive takes an exclusive lock on an object.

func (*IOContext) LockShared

func (ioctx *IOContext) LockShared(oid, name, cookie, tag, desc string, duration time.Duration, flags *byte) (int, error)

LockShared takes a shared lock on an object.

func (*IOContext) LookupSnap added in v0.5.0

func (ioctx *IOContext) LookupSnap(snapName string) (SnapID, error)

LookupSnap returns the ID of a pool snapshot.

Implements:

int rados_ioctx_snap_lookup(rados_ioctx_t io, const char *name, rados_snap_t *id)

func (*IOContext) Pointer

func (ioctx *IOContext) Pointer() unsafe.Pointer

Pointer returns a pointer reference to an internal structure. This function should NOT be used outside of go-ceph itself.

func (*IOContext) Read

func (ioctx *IOContext) Read(oid string, data []byte, offset uint64) (int, error)

Read reads up to len(data) bytes from the object with key oid starting at byte offset offset. It returns the number of bytes read and an error, if any.

func (*IOContext) RemoveSnap added in v0.5.0

func (ioctx *IOContext) RemoveSnap(snapName string) error

RemoveSnap deletes the pool snapshot.

Implements:

int rados_ioctx_snap_remove(rados_ioctx_t io, const char *snapname)

func (*IOContext) RmOmapKeys

func (ioctx *IOContext) RmOmapKeys(oid string, keys []string) error

RmOmapKeys removes the specified `keys` from the omap `oid`

func (*IOContext) RmXattr

func (ioctx *IOContext) RmXattr(oid string, name string) error

RmXattr removes an xattr with key `name` from object `oid`

func (*IOContext) RollbackSnap added in v0.5.0

func (ioctx *IOContext) RollbackSnap(oid, snapName string) error

RollbackSnap rollbacks the object with key oID to the pool snapshot. The contents of the object will be the same as when the snapshot was taken.

Implements:

int rados_ioctx_snap_rollback(rados_ioctx_t io, const char *oid, const char *snapname);

func (*IOContext) SetNamespace

func (ioctx *IOContext) SetNamespace(namespace string)

SetNamespace sets the namespace for objects within this IO context (pool). Setting namespace to a empty or zero length string sets the pool to the default namespace.

func (*IOContext) SetOmap

func (ioctx *IOContext) SetOmap(oid string, pairs map[string][]byte) error

SetOmap appends the map `pairs` to the omap `oid`

func (*IOContext) SetReadSnap added in v0.5.0

func (ioctx *IOContext) SetReadSnap(snapID SnapID) error

SetReadSnap sets the snapshot from which reads are performed. Subsequent reads will return data as it was at the time of that snapshot. Pass SnapHead for no snapshot (i.e. normal operation).

Implements:

void rados_ioctx_snap_set_read(rados_ioctx_t io, rados_snap_t snap);

func (*IOContext) SetXattr

func (ioctx *IOContext) SetXattr(object string, name string, data []byte) error

SetXattr sets an xattr for an object with key `name` with value as `data`

func (*IOContext) Stat

func (ioctx *IOContext) Stat(object string) (stat ObjectStat, err error)

Stat returns the size of the object and its last modification time

func (*IOContext) Truncate

func (ioctx *IOContext) Truncate(oid string, size uint64) error

Truncate resizes the object with key oid to size size. If the operation enlarges the object, the new area is logically filled with zeroes. If the operation shrinks the object, the excess data is removed. It returns an error, if any.

func (*IOContext) Unlock

func (ioctx *IOContext) Unlock(oid, name, cookie string) (int, error)

Unlock releases a shared or exclusive lock on an object.

func (*IOContext) Write

func (ioctx *IOContext) Write(oid string, data []byte, offset uint64) error

Write writes len(data) bytes to the object with key oid starting at byte offset offset. It returns an error, if any.

func (*IOContext) WriteFull

func (ioctx *IOContext) WriteFull(oid string, data []byte) error

WriteFull writes len(data) bytes to the object with key oid. The object is filled with the provided data. If the object exists, it is atomically truncated and then written. It returns an error, if any.

type Iter

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

Iter supports iterating over objects in the ioctx.

func (*Iter) Close

func (iter *Iter) Close()

Close the iterator cursor on the server. Be aware that iterators are not closed automatically at the end of iteration.

func (*Iter) Err

func (iter *Iter) Err() error

Err checks whether the iterator has encountered an error.

func (*Iter) Namespace

func (iter *Iter) Namespace() string

Namespace returns the namespace associated with the current value of the iterator (object name), after a successful call to Next.

func (*Iter) Next

func (iter *Iter) Next() bool

Next retrieves the next object name in the pool/namespace iterator. Upon a successful invocation (return value of true), the Value method should be used to obtain the name of the retrieved object name. When the iterator is exhausted, Next returns false. The Err method should used to verify whether the end of the iterator was reached, or the iterator received an error.

Example:

iter := pool.Iter()
defer iter.Close()
for iter.Next() {
	fmt.Printf("%v\n", iter.Value())
}
return iter.Err()

func (*Iter) Seek

func (iter *Iter) Seek(token IterToken)

Seek moves the iterator to the position indicated by the token.

func (*Iter) Token

func (iter *Iter) Token() IterToken

Token returns a token marking the current position of the iterator. To be used in combination with Iter.Seek()

func (*Iter) Value

func (iter *Iter) Value() string

Value returns the current value of the iterator (object name), after a successful call to Next.

type IterToken

type IterToken uint32

IterToken supports reporting on and seeking to different positions.

type LockInfo

type LockInfo struct {
	NumLockers int
	Exclusive  bool
	Tag        string
	Clients    []string
	Cookies    []string
	Addrs      []string
}

LockInfo represents information on a current Ceph lock

type ObjectListFunc

type ObjectListFunc func(oid string)

ObjectListFunc is the type of the function called for each object visited by ListObjects.

type ObjectStat

type ObjectStat struct {
	// current length in bytes
	Size uint64
	// last modification time
	ModTime time.Time
}

ObjectStat represents an object stat information

type OmapListFunc

type OmapListFunc func(key string, value []byte)

OmapListFunc is the type of the function called for each omap key visited by ListOmapValues

type PoolStat

type PoolStat struct {
	// space used in bytes
	Num_bytes uint64
	// space used in KB
	Num_kb uint64
	// number of objects in the pool
	Num_objects uint64
	// number of clones of objects
	Num_object_clones uint64
	// num_objects * num_replicas
	Num_object_copies              uint64
	Num_objects_missing_on_primary uint64
	// number of objects found on no OSDs
	Num_objects_unfound uint64
	// number of objects replicated fewer times than they should be
	// (but found on at least one OSD)
	Num_objects_degraded uint64
	Num_rd               uint64
	Num_rd_kb            uint64
	Num_wr               uint64
	Num_wr_kb            uint64
}

PoolStat represents Ceph pool statistics.

type SnapID added in v0.5.0

type SnapID C.rados_snap_t

SnapID represents the ID of a rados snapshot.

Jump to

Keyboard shortcuts

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