/
rados.go
79 lines (66 loc) · 1.7 KB
/
rados.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package ceph
import "github.com/journeymidnight/radoshttpd/rados"
// Interfaces for underlying rados lib, mainly to ease testing/mocking
type RadosConn interface {
OpenPool(name string) (Pool, error)
GetClusterStats() (rados.ClusterStat, error)
Shutdown()
}
type Pool interface {
Write(oid string, data []byte, offset uint64) error
Read(oid string, data []byte, offset uint64) (int, error)
Delete(oid string) error
Truncate(oid string, size uint64) error
Destroy()
CreateStriper() (StriperPool, error)
WriteSmallObject(oid string, data []byte) error
}
type StriperPool interface {
Read(oid string, data []byte, offset uint64) (int, error)
Write(oid string, data []byte, offset uint64) (int, error)
WriteAIO(oid string, data []byte, offset uint64) (AioCompletion, error)
Delete(oid string) error
Destroy()
SetLayoutStripeUnit(uint uint) int
SetLayoutStripeCount(count uint) int
SetLayoutObjectSize(size uint) int
}
type AioCompletion interface {
WaitForComplete()
Release()
IsComplete() int
GetReturnValue() int
}
type radosConn struct {
*rados.Conn
}
func (c radosConn) OpenPool(name string) (Pool, error) {
p, err := c.Conn.OpenPool(name)
if err != nil {
return nil, err
}
return pool{p}, nil
}
type pool struct {
*rados.Pool
}
func (p pool) CreateStriper() (StriperPool, error) {
s, err := p.Pool.CreateStriper()
if err != nil {
return nil, err
}
return striperPool{&s}, nil
}
type striperPool struct {
*rados.StriperPool
}
func (sp striperPool) WriteAIO(oid string,
data []byte, offset uint64) (AioCompletion, error) {
aio := &rados.AioCompletion{}
err := aio.Create()
if err != nil {
return nil, err
}
_, err = sp.StriperPool.WriteAIO(aio, oid, data, offset)
return aio, err
}