Merge lp:~rharding/charms/precise/mongodb/persistent_storage into lp:charms/mongodb

Proposed by Richard Harding
Status: Rejected
Rejected by: Juan L. Negron
Proposed branch: lp:~rharding/charms/precise/mongodb/persistent_storage
Merge into: lp:charms/mongodb
Diff against target: 153 lines (+94/-3)
4 files modified
README.md (+15/-1)
config.yaml (+4/-0)
hooks/hooks.py (+74/-1)
revision (+1/-1)
To merge this branch: bzr merge lp:~rharding/charms/precise/mongodb/persistent_storage
Reviewer Review Type Date Requested Status
Juan L. Negron (community) Disapprove
Review via email: mp+148008@code.launchpad.net

Commit message

Add 'persistent' config option to store mongo data.

Description of the change

Adds support for using persistant storage for mongo's data and meta files.

To start with it adds a new config `persistent`. It assumes you've attached a persistent volume to the host. There's a section of docs in the readme with the command expected for adding it.

To post a comment you must log in.
35. By Richard Harding

Remove msg levels not required

Revision history for this message
Juan L. Negron (negronjl) wrote :

Reviewing this now.

-Juan

Revision history for this message
Juan L. Negron (negronjl) wrote :

Although the idea is a really good one, I don't approve. I explain:

The persistent flag works, the logic where MongoDB tries to figure out where the newly created mount point is located, is subject to errors. In my opinion, it would be best to pass the device ( /dev/vdxx ) as a config option. That would alleviate some of the existing logic as it would not have to figure out where the device is. The rationale of my objection is that by passing the device explicitly, there is a chance of passing multiple devices and the charm would still work.

In my opinion, there should be a config options where the user could pass the device explicitly. Of course, this option would only be evaluated if the persistent config option is set to True.

Thanks,

Juan

review: Disapprove

Unmerged revisions

35. By Richard Harding

Remove msg levels not required

34. By Richard Harding

Fix the revision back to original + 1

33. By Richard Harding

Add some extra checks

32. By Richard Harding

Garden

31. By Richard Harding

Update docs

30. By Richard Harding

Update to set up a unformatted disk

29. By Richard Harding

almost have it working, unmounts after config change somehow

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README.md'
2--- README.md 2012-11-18 07:52:57 +0000
3+++ README.md 2013-02-12 17:53:21 +0000
4@@ -279,7 +279,7 @@
5 configsvr:
6 replicaset: configsvr
7 We'll save this one as ~/mongodb-shard.yaml
8-
9+
10
11 ### Bootstrap the environment
12 juju bootstrap
13@@ -303,6 +303,20 @@
14 juju add-realtion mongos:mongos shard2:database
15 juju add-realtion mongos:mongos shard3:database
16
17+## Using persistent storage for data.
18+
19+The script will format a newly created persistent volume if it's not been
20+formatted already.
21+
22+ # Create a new 30gb volume.
23+ euca-attach-volume -z nova -s 30
24+ euca-describe-instances
25+ euca-describe-volumes
26+ euca-attach-volume -d /dev/vdz -i i-00006c74 vol-000000e2
27+ # Wait for the volume to attach.
28+ juju set mongodb persistent=True dbpath=/mnt/mongodb
29+
30+
31 With the above commands, we should now have a three replica-set sharded cluster running.
32 Using the default configuration, here are some details of our sharded cluster:
33 - mongos is running on port 27021
34
35=== modified file 'config.yaml'
36--- config.yaml 2012-08-19 02:31:14 +0000
37+++ config.yaml 2013-02-12 17:53:21 +0000
38@@ -1,4 +1,8 @@
39 options:
40+ persistent:
41+ default: False
42+ type: boolean
43+ description: use mounted persistent storage for mongodb.
44 dbpath:
45 default: "/var/lib/mongodb"
46 type: string
47
48=== modified file 'hooks/hooks.py'
49--- hooks/hooks.py 2012-11-17 03:28:16 +0000
50+++ hooks/hooks.py 2013-02-12 17:53:21 +0000
51@@ -13,7 +13,10 @@
52 import signal
53 import socket
54 import time
55-
56+from grp import getgrnam
57+from os import chown
58+from os import mkdir
59+from pwd import getpwnam
60
61 ###############################################################################
62 # Supporting functions
63@@ -845,6 +848,10 @@
64 print "config_data: ", config_data
65 mongodb_config = open(default_mongodb_config).read()
66
67+ # Setup persistent storage if required.
68+ if config_data.get('persistent') is True:
69+ mount_persistent_storage()
70+
71 # current ports
72 current_mongodb_port = re.search('^#*port\s+=\s+(\w+)',
73 mongodb_config,
74@@ -1126,6 +1133,72 @@
75 return(retVal)
76
77
78+#------------------------------------------------------------------------------
79+# run: Run a command, return the output
80+#------------------------------------------------------------------------------
81+def run(command, exit_on_error=True):
82+ try:
83+ juju_log(command)
84+ return subprocess.check_output(command, shell=True)
85+ except subprocess.CalledProcessError, e:
86+ juju_log("status=%d, output=%s" % (e.returncode, e.output))
87+ if exit_on_error:
88+ sys.exit(e.returncode)
89+ else:
90+ raise
91+
92+
93+def mount_persistent_storage():
94+ """If true, attempt to mount mongodb onto the persistent storage."""
95+ juju_log("Mounting persistent storage")
96+ mongo_dir = '/mnt/mongodb'
97+
98+ dmesg = run("dmesg | grep 'unknown partition table' | tail -n1")
99+ device_id = re.search('vd.:', dmesg)
100+ if device_id is None:
101+ juju_log('no device found in dmesg output: ' + dmesg)
102+ else:
103+ device_id = device_id.group().rstrip(':')
104+
105+ device_path = '/dev/' + device_id
106+ juju_log('mounting device: ' + device_path)
107+
108+ # check for file system on the device to mount.
109+ device_info = run('file -s ' + device_path)
110+
111+ # Make sure we don't run this on some unsuspecting ext3 device on
112+ # the machine.
113+ if not 'ext4' in device_info and 'ext3' in device_info:
114+ # sudo mke2fs -L dataset-1 -m 0 -T ext4 /dev/vdc
115+ juju_log("Existing filesystem on %s not found. %s" % (
116+ device_path,
117+ device_info))
118+ juju_log("Making filesystem on device: %s" % device_path)
119+ format_cmd = "mke2fs -L dataset-1 -m 0 -T ext4 %s" % device_path
120+ run(format_cmd)
121+
122+ # mount /dev/vde /mnt
123+ res = run('mount')
124+ if device_path not in res:
125+ juju_log("Mounting device to /mnt")
126+ command = "mount %s /mnt" % device_path
127+ res = run(command)
128+ else:
129+ juju_log("Mount point already found")
130+ juju_log(res)
131+
132+ # mkdir /mnt/mongodb
133+ if not os.path.isdir(mongo_dir):
134+ mkdir(mongo_dir)
135+
136+ # chown -R mongodb:mongodb /mnt/mongodb
137+ chown(
138+ mongo_dir,
139+ getpwnam('mongodb').pw_uid,
140+ getgrnam('mongodb').gr_gid
141+ )
142+
143+
144 def mongos_relation_broken():
145 # config_servers = load_config_servers(default_mongos_list)
146 # for member in relation_list():
147
148=== modified file 'revision'
149--- revision 2012-11-18 07:54:22 +0000
150+++ revision 2013-02-12 17:53:21 +0000
151@@ -1,1 +1,1 @@
152-25
153+29

Subscribers

People subscribed via source and target branches