rados

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2015 License: MIT Imports: 4 Imported by: 0

README

go-rados - Go bindings for RADOS distributed object store

Build Status Godoc license

This project uses Semantic Versioning (http://semver.org/).

Installation

go get github.com/noahdesu/go-rados

The native RADOS library and development headers are expected to be installed.

Documentation

Detailed documentation is available at http://godoc.org/github.com/noahdesu/go-rados.

Connecting to a cluster

Connect to a Ceph cluster using a configuration file located in the default search paths.

conn, _ := rados.NewConn()
conn.ReadDefaultConfigFile()
conn.Connect()

A connection can be shutdown by calling the Shutdown method on the connection object (e.g. conn.Shutdown()). There are also other methods for configuring the connection. Specific configuration options can be set:

conn.SetConfigOption("log_file", "/dev/null")

and command line options can also be used using the ParseCmdLineArgs method.

args := []string{ "--mon-host", "1.1.1.1" }
err := conn.ParseCmdLineArgs(args)

For other configuration options see the full documentation.

Object I/O

Object in RADOS can be written to and read from with through an interface very similar to a standard file I/O interface:

// open a pool handle
ioctx, err := conn.OpenIOContext("mypool")

// write some data
bytes_in := []byte("input data")
err = ioctx.Write("obj", bytes_in, 0)

// read the data back out
bytes_out := make([]byte, len(bytes_in))
n_out, err := ioctx.Read("obj", bytes_out, 0)

if bytes_in != bytes_out {
    fmt.Println("Output is not input!")
}
Pool maintenance

The list of pools in a cluster can be retreived using the ListPools method on the connection object. On a new cluster the following code snippet:

pools, _ := conn.ListPools()
fmt.Println(pools)

will produce the output [data metadata rbd], along with any other pools that might exist in your cluster. Pools can also be created and destroyed. The following creates a new, empty pool with default settings.

conn.MakePool("new_pool")

Deleting a pool is also easy. Call DeletePool(name string) on a connection object to delete a pool with the given name. The following will delete the pool named new_pool and remove all of the pool's data.

conn.DeletePool("new_pool")

Documentation

Overview

Package noahdesu/go-rados provides access to librados and librbd.

Index

Constants

This section is empty.

Variables

This section is empty.

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 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 (*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)

GetClusterStat 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) 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) OpenIOContext added in v0.2.0

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

func (*Conn) ParseCmdLineArgs

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

ParseCmdLineArgs configures the connection from command line arguments.

func (*Conn) ParseDefaultConfigEnv

func (c *Conn) ParseDefaultConfigEnv() error

ParseDefaultConfigEnv configures the connection from the default Ceph environment variable(s).

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 IOContext added in v0.2.0

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

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

func (*IOContext) Delete added in v0.2.0

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

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

func (*IOContext) Destroy added in v0.2.0

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) GetPoolName added in v0.2.0

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

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

func (*IOContext) GetPoolStats added in v0.2.0

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

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

func (*IOContext) ListObjects added in v0.2.0

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.

func (*IOContext) Read added in v0.2.0

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) Truncate added in v0.2.0

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) Write added in v0.2.0

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.

type ObjectListFunc added in v0.2.0

type ObjectListFunc func(oid string)

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

type PoolStat added in v0.2.0

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 RadosError

type RadosError int

func (RadosError) Error

func (e RadosError) Error() string

Jump to

Keyboard shortcuts

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