Merge lp:~xfactor973/charm-helpers/ceph-erasure-bug into lp:charm-helpers

Proposed by Chris Holcombe
Status: Merged
Merged at revision: 533
Proposed branch: lp:~xfactor973/charm-helpers/ceph-erasure-bug
Merge into: lp:charm-helpers
Diff against target: 116 lines (+38/-12)
1 file modified
charmhelpers/contrib/storage/linux/ceph.py (+38/-12)
To merge this branch: bzr merge lp:~xfactor973/charm-helpers/ceph-erasure-bug
Reviewer Review Type Date Requested Status
James Page Approve
Review via email: mp+286685@code.launchpad.net

Description of the change

This fixes up a few bugs that I encountered while using my previous erasure code patch. Unfortunately I was using some types incorrectly :(

To post a comment you must log in.
Revision history for this message
James Page (james-page) wrote :

Applied and landed with some amendments - please resync linked ceph branch.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/storage/linux/ceph.py'
2--- charmhelpers/contrib/storage/linux/ceph.py 2015-11-30 18:11:49 +0000
3+++ charmhelpers/contrib/storage/linux/ceph.py 2016-02-19 16:46:19 +0000
4@@ -120,6 +120,7 @@
5 """
6 A custom error to inform the caller that a pool creation failed. Provides an error message
7 """
8+
9 def __init__(self, message):
10 super(PoolCreationError, self).__init__(message)
11
12@@ -129,6 +130,7 @@
13 An object oriented approach to Ceph pool creation. This base class is inherited by ReplicatedPool and ErasurePool.
14 Do not call create() on this base class as it will not do anything. Instantiate a child class and call create().
15 """
16+
17 def __init__(self, service, name):
18 self.service = service
19 self.name = name
20@@ -180,36 +182,41 @@
21 :return: int. The number of pgs to use.
22 """
23 validator(value=pool_size, valid_type=int)
24- osds = get_osds(self.service)
25- if not osds:
26+ osd_list = get_osds(self.service)
27+ osd_list_length = len(osd_list)
28+ if not osd_list:
29 # NOTE(james-page): Default to 200 for older ceph versions
30 # which don't support OSD query from cli
31 return 200
32
33 # Calculate based on Ceph best practices
34- if osds < 5:
35+ if osd_list_length < 5:
36 return 128
37- elif 5 < osds < 10:
38+ elif 5 < osd_list_length < 10:
39 return 512
40- elif 10 < osds < 50:
41+ elif 10 < osd_list_length < 50:
42 return 4096
43 else:
44- estimate = (osds * 100) / pool_size
45+ estimate = (osd_list_length * 100) / pool_size
46 # Return the next nearest power of 2
47 index = bisect.bisect_right(powers_of_two, estimate)
48 return powers_of_two[index]
49
50
51 class ReplicatedPool(Pool):
52- def __init__(self, service, name, replicas=2):
53+ def __init__(self, service, name, pg_num=None, replicas=2):
54 super(ReplicatedPool, self).__init__(service=service, name=name)
55 self.replicas = replicas
56+ if pg_num is None:
57+ self.pg_num = self.get_pgs(self.replicas)
58+ else:
59+ self.pg_num = pg_num
60
61 def create(self):
62 if not pool_exists(self.service, self.name):
63 # Create it
64- pgs = self.get_pgs(self.replicas)
65- cmd = ['ceph', '--id', self.service, 'osd', 'pool', 'create', self.name, str(pgs)]
66+ cmd = ['ceph', '--id', self.service, 'osd', 'pool', 'create',
67+ self.name, str(self.pg_num)]
68 try:
69 check_call(cmd)
70 except CalledProcessError:
71@@ -241,7 +248,7 @@
72
73 pgs = self.get_pgs(int(erasure_profile['k']) + int(erasure_profile['m']))
74 # Create it
75- cmd = ['ceph', '--id', self.service, 'osd', 'pool', 'create', self.name, str(pgs),
76+ cmd = ['ceph', '--id', self.service, 'osd', 'pool', 'create', self.name, str(pgs), str(pgs),
77 'erasure', self.erasure_code_profile]
78 try:
79 check_call(cmd)
80@@ -322,7 +329,8 @@
81 :return: None. Can raise CalledProcessError
82 """
83 # Set a byte quota on a RADOS pool in ceph.
84- cmd = ['ceph', '--id', service, 'osd', 'pool', 'set-quota', pool_name, 'max_bytes', max_bytes]
85+ cmd = ['ceph', '--id', service, 'osd', 'pool', 'set-quota', pool_name,
86+ 'max_bytes', str(max_bytes)]
87 try:
88 check_call(cmd)
89 except CalledProcessError:
90@@ -343,7 +351,25 @@
91 raise
92
93
94-def create_erasure_profile(service, profile_name, erasure_plugin_name='jerasure', failure_domain='host',
95+def remove_erasure_profile(service, profile_name):
96+ """
97+ Create a new erasure code profile if one does not already exist for it. Updates
98+ the profile if it exists. Please see http://docs.ceph.com/docs/master/rados/operations/erasure-code-profile/
99+ for more details
100+ :param service: six.string_types. The Ceph user name to run the command under
101+ :param profile_name: six.string_types
102+ :return: None. Can raise CalledProcessError
103+ """
104+ cmd = ['ceph', '--id', service, 'osd', 'erasure-code-profile', 'rm',
105+ profile_name]
106+ try:
107+ check_call(cmd)
108+ except CalledProcessError:
109+ raise
110+
111+
112+def create_erasure_profile(service, profile_name, erasure_plugin_name='jerasure',
113+ failure_domain='host',
114 data_chunks=2, coding_chunks=1,
115 locality=None, durability_estimator=None):
116 """

Subscribers

People subscribed via source and target branches