Class: Rados::Pool
- Inherits:
-
Object
- Object
- Rados::Pool
- Defined in:
- lib/rados.rb
Overview
Represents a Pool in the cluster. Use Pool.find to get a pool from the cluster and Pool.create to create new ones.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of this pool.
-
#objects ⇒ Object
readonly
The objects in this pool.
Class Method Summary collapse
-
.create(name) ⇒ Object
Create a new pool in the cluster with the given name.
-
.find(name) ⇒ Object
Get the named pool from the cluster.
Instance Method Summary collapse
-
#destroy ⇒ Object
Destroy the pool.
-
#destroyed? ⇒ Boolean
Returns true if the pool as been marked as destroyed since instantiated.
-
#initialize(name) ⇒ Pool
constructor
:nodoc:.
-
#pool ⇒ Object
The internal Rados pool data stucture.
-
#read(oid, options = {}) ⇒ Object
Reads data from the object id
oid
in the pool. -
#remove(oid) ⇒ Object
Deletes the object id
oid
from the pool. -
#write(oid, buf, options = {}) ⇒ Object
Write the data
buf
to the object idoid
in the pool.
Constructor Details
#initialize(name) ⇒ Pool
:nodoc:
106 107 108 109 |
# File 'lib/rados.rb', line 106 def initialize(name) #:nodoc: @name = name @objects = ObjectCollection.new(self) end |
Instance Attribute Details
#name ⇒ Object (readonly)
The name of this pool
102 103 104 |
# File 'lib/rados.rb', line 102 def name @name end |
#objects ⇒ Object (readonly)
The objects in this pool. See Rados::ObjectCollection.
104 105 106 |
# File 'lib/rados.rb', line 104 def objects @objects end |
Class Method Details
.create(name) ⇒ Object
Create a new pool in the cluster with the given name. Returns a Pool instance. Raises a RadosError exception if the pool could not be created.
122 123 124 125 126 127 128 129 |
# File 'lib/rados.rb', line 122 def self.create(name) ret = Lib.rados_create_pool(name) if ret < 0 raise RadosError, "creating pool #{name}" else new(name) end end |
.find(name) ⇒ Object
Get the named pool from the cluster. Returns a Pool instance. Raises Rados::PoolNotFound if Pool doesn’t exist
113 114 115 116 117 |
# File 'lib/rados.rb', line 113 def self.find(name) p = new(name) p.pool p end |
Instance Method Details
#destroy ⇒ Object
Destroy the pool. Raises a RadosError exception if the pool could not be deleted.
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/rados.rb', line 144 def destroy sanity_check "destroy already" ret = Lib.rados_delete_pool(pool) if ret < 0 raise RadosError, "deleting pool #{name}" else @destroyed = true self end end |
#destroyed? ⇒ Boolean
Returns true if the pool as been marked as destroyed since instantiated.
157 158 159 |
# File 'lib/rados.rb', line 157 def destroyed? @destroyed == true end |
#pool ⇒ Object
The internal Rados pool data stucture
132 133 134 135 136 137 138 139 140 |
# File 'lib/rados.rb', line 132 def pool #:nodoc: return @pool unless @pool.nil? @pool_pointer = FFI::MemoryPointer.new :pointer ret = Lib.rados_open_pool name, @pool_pointer if ret < 0 raise PoolNotFound, name end @pool = @pool_pointer.get_pointer(0) end |
#read(oid, options = {}) ⇒ Object
Reads data from the object id oid
in the pool. Returns the data as a string. If no object with the oid exists, a Rados::ObjectNotFound exception is raised. If the read fails then a Rados::ReadError exception is raised.
Available options are:
-
:size
- The amount of data to read. As objects can be huge, it is unlikely that you’ll want to load the entire thing into ram, so defaults to 8192 bytes. -
:offset
- The number of bytes from the beginning of the object to start writing at. Defaults to 0.
192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/rados.rb', line 192 def read(oid, = {}) sanity_check "read from" offset = .fetch(:offset, 0) len = .fetch(:size, 8192) buf = FFI::MemoryPointer.new :char, len ret = Lib.rados_read(pool, oid, offset, buf, len) if ret == -2 raise ObjectNotFound, "reading from '#{oid}' in pool #{name}" elsif ret < 0 raise ReadError, "reading #{len} bytes at offset #{offset} from #{oid} in pool #{name}: #{ret}" end buf.read_string(ret) end |
#remove(oid) ⇒ Object
Deletes the object id oid
from the pool. If the object could not be removed then a Rados::RemoveError exception is raised.
209 210 211 212 213 214 215 216 |
# File 'lib/rados.rb', line 209 def remove(oid) sanity_check "remove from" ret = Lib.rados_remove(pool, oid) if ret < 0 raise RemoveError, "removing #{oid} from pool #{name}" end true end |
#write(oid, buf, options = {}) ⇒ Object
Write the data buf
to the object id oid
in the pool. Both oid
and buf
should be strings. Returns the number of bytes written. If the write fails then a Rados::WriteError exception is raised. If the data was only partly written then a Rados::ShortWriteError exception is raised.
Available options are:
-
:size
- Number of bytes to write. Defaults to the size ofbuf
-
:offset
- The number of bytes from the beginning of the object to start writing at. Defaults to 0.
171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/rados.rb', line 171 def write(oid, buf, = {}) sanity_check "write to" offset = .fetch(:offset, 0) len = .fetch(:size, buf.size) ret = Lib.rados_write(pool, oid, offset, buf, len) if ret < 0 raise WriteError, "writing #{len} bytes at offset #{offset} to #{oid} in pool #{name}: #{ret}" elsif ret < len raise ShortWriteError, "writing #{len} bytes to pool #{name} only wrote #{ret}" end ret end |