├── .gitignore ├── MongoMultiMaster.egg-info ├── not-zip-safe ├── top_level.txt ├── dependency_links.txt ├── requires.txt ├── SOURCES.txt └── PKG-INFO ├── mmm ├── __init__.py ├── main.py ├── triggers.py └── slave.py ├── setup.cfg ├── MANIFEST.in ├── NOTICE ├── test.yml ├── setup.bash ├── logging.ini ├── setup.py ├── scripts └── mmm ├── Vagrantfile ├── README.md ├── README.rst └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | dist/* 3 | -------------------------------------------------------------------------------- /MongoMultiMaster.egg-info/not-zip-safe: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /MongoMultiMaster.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | mmm 2 | -------------------------------------------------------------------------------- /MongoMultiMaster.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /mmm/__init__.py: -------------------------------------------------------------------------------- 1 | from slave import ReplicationSlave 2 | -------------------------------------------------------------------------------- /MongoMultiMaster.egg-info/requires.txt: -------------------------------------------------------------------------------- 1 | gevent 2 | pymongo 3 | pyyaml -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [egg_info] 2 | tag_build = dev 3 | tag_svn_revision = true 4 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.rst 3 | recursive-include mmm *.py 4 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | MongoMultiMaster 2 | Copyright 2012 Arborian Consulting LLC 3 | 4 | This product includes software developed at Arborian Consulting LLC. 5 | -------------------------------------------------------------------------------- /test.yml: -------------------------------------------------------------------------------- 1 | server_a: 2 | id: '2c88ae84-7cb9-40f7-835d-c05e981f564d' 3 | uri: 'mongodb://localhost:27019' 4 | server_b: 5 | id: '0d9c284b-b47c-40b5-932c-547b8685edd0' 6 | uri: 'mongodb://localhost:27017' 7 | -------------------------------------------------------------------------------- /setup.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mmm -c $1 replicate --src=server_a/test.foo --dst=server_b/test.foo 3 | mmm -c $1 replicate --src=server_a/test.bar --dst=server_b/test.bar 4 | mmm -c $1 replicate --src=server_b/test.foo --dst=server_a/test.foo 5 | mmm -c $1 replicate --src=server_b/test.bar --dst=server_a/test.bar 6 | -------------------------------------------------------------------------------- /logging.ini: -------------------------------------------------------------------------------- 1 | [loggers] 2 | keys = root 3 | 4 | [handlers] 5 | keys = console 6 | 7 | [formatters] 8 | keys = console 9 | 10 | [logger_root] 11 | level = DEBUG 12 | handlers = console 13 | 14 | [handler_console] 15 | class = StreamHandler 16 | args = (sys.stderr,) 17 | level = NOTSET 18 | formatter = console 19 | 20 | [formatter_console] 21 | format = %(asctime)s %(name)-12s %(levelname)-8s %(message)s 22 | datefmt = %m-%d %H:%M 23 | -------------------------------------------------------------------------------- /MongoMultiMaster.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | LICENSE 2 | MANIFEST.in 3 | README.rst 4 | setup.cfg 5 | setup.py 6 | MongoMultiMaster.egg-info/PKG-INFO 7 | MongoMultiMaster.egg-info/SOURCES.txt 8 | MongoMultiMaster.egg-info/dependency_links.txt 9 | MongoMultiMaster.egg-info/not-zip-safe 10 | MongoMultiMaster.egg-info/requires.txt 11 | MongoMultiMaster.egg-info/top_level.txt 12 | mmm/__init__.py 13 | mmm/main.py 14 | mmm/slave.py 15 | mmm/triggers.py 16 | scripts/mmm -------------------------------------------------------------------------------- /mmm/main.py: -------------------------------------------------------------------------------- 1 | import gevent 2 | 3 | from .slave import ReplicationSlave 4 | 5 | def main(): 6 | a_uri = 'mongodb://localhost:27019' 7 | b_uri = 'mongodb://localhost:27017' 8 | s_a = ReplicationSlave(a_uri) 9 | s_b = ReplicationSlave(b_uri) 10 | # Make test.foo on a_uri be a slave of test.bar on b_uri 11 | s_a['test.foo'] << (b_uri, 'test.bar') 12 | # Make test.bar on b_uri be a slave of test.foo on a_uri 13 | s_b['test.bar'] << (a_uri, 'test.foo') 14 | s_a.start() 15 | s_b.start() 16 | while True: 17 | gevent.sleep(5) 18 | print '=== mark ===' 19 | 20 | if __name__ == '__main__': 21 | main() 22 | 23 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | import os 3 | 4 | version = '0.0.4' 5 | with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as fp: 6 | long_description = fp.read() 7 | 8 | setup(name='MongoMultiMaster', 9 | version=version, 10 | description="Multimaster replication for MongoDB", 11 | long_description=long_description, 12 | classifiers=[ 13 | 'Development Status :: 3 - Alpha', 14 | 'Environment :: Console', 15 | 'Intended Audience :: Developers', 16 | 'License :: OSI Approved :: Apache Software License', 17 | 'Natural Language :: English', 18 | 'Operating System :: OS Independent', 19 | 'Programming Language :: Python :: 2.7', 20 | 'Topic :: Database :: Database Engines/Servers', 21 | 'Topic :: Utilities' ], 22 | keywords='mongodb,replication', 23 | author='Rick Copeland', 24 | author_email='rick@arborian.com', 25 | url='https://github.com/rick446/mmm', 26 | license='Apache License, Version 2.0', 27 | packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), 28 | include_package_data=True, 29 | zip_safe=False, 30 | install_requires=[ 31 | 'gevent', 32 | 'pymongo', 33 | 'pyyaml', 34 | ], 35 | scripts=['scripts/mmm'], 36 | entry_points="") 37 | -------------------------------------------------------------------------------- /mmm/triggers.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from collections import defaultdict 3 | 4 | import gevent 5 | 6 | log = logging.getLogger(__name__) 7 | 8 | class Triggers(object): 9 | 10 | def __init__(self, connection, checkpoint): 11 | self._conn = connection 12 | self._oplog = self._conn.local.oplog.rs 13 | self._oplog.ensure_index('ts') 14 | self._callbacks = defaultdict(list) 15 | self.checkpoint = checkpoint 16 | 17 | def run(self): 18 | while True: 19 | yield self.checkpoint 20 | spec = dict(ts={'$gt': self.checkpoint}) 21 | q = self._oplog.find( 22 | spec, tailable=True, await_data=True) 23 | found=False 24 | # log.debug('Query on %s', self._oplog) 25 | for op in q.sort('$natural'): 26 | found = True 27 | self.checkpoint = op['ts'] 28 | for callback in self._callbacks.get( 29 | (op['ns'], op['op']), []): 30 | callback(**op) 31 | if found: 32 | gevent.sleep(0) 33 | else: 34 | gevent.sleep(1) 35 | 36 | def register(self, namespace, operations, func=None): 37 | def wrapper(func): 38 | for op in operations: 39 | self._callbacks[namespace, op].append(func) 40 | return func 41 | if func: 42 | return wrapper(func) 43 | else: 44 | return wrapper 45 | 46 | -------------------------------------------------------------------------------- /scripts/mmm: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import gevent.monkey 3 | gevent.monkey.patch_all() 4 | 5 | import json 6 | import bson 7 | import argparse 8 | import logging.config 9 | 10 | import yaml 11 | 12 | def main(): 13 | global log 14 | parser = argparse.ArgumentParser() 15 | parser.add_argument( 16 | '-l', '--logging', dest='logging', default=None, 17 | help='Logging config file') 18 | parser.add_argument( 19 | '-c', '--config', dest='config', default='test.yml', 20 | help='Topology config file', 21 | required=True) 22 | subparsers = parser.add_subparsers( 23 | title='subcommands', 24 | description='valid subcommands') 25 | 26 | dump_config = subparsers.add_parser( 27 | 'dump-config', description='Show the replication configuration') 28 | dump_config.set_defaults(func=run_dump_config) 29 | 30 | clear_config = subparsers.add_parser( 31 | 'clear-config', description='Reset the server(s) to not be replicating') 32 | clear_config.add_argument( 33 | '-s', '--slave', dest='slave', default=None, 34 | help='Restrict operations to a particular named slave') 35 | clear_config.set_defaults(func=run_clear_config) 36 | 37 | replicate = subparsers.add_parser( 38 | 'replicate', description='Create a replication link') 39 | replicate.add_argument('-s', '--src', dest='src', required=True) 40 | replicate.add_argument('-d', '--dst', dest='dst', required=True) 41 | replicate.add_argument('-o', '--ops', dest='ops', default='iud') 42 | replicate.set_defaults(func=run_replicate) 43 | 44 | run = subparsers.add_parser( 45 | 'run', description='Run the replication engine') 46 | run.add_argument( 47 | '-s', '--slave', dest='slave', default=None, 48 | help='Restrict operations to a particular named slave') 49 | run.set_defaults(func=run_main) 50 | 51 | args = parser.parse_args() 52 | if args.logging: 53 | logging.config.fileConfig(args.logging) 54 | else: 55 | logging.basicConfig( 56 | format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', 57 | datefmt='%Y-%m-%d %H:%M:%S', 58 | level=logging.INFO) 59 | log = logging.getLogger('mmm') 60 | 61 | from mmm.slave import ReplicationSlave 62 | 63 | with open(args.config) as fp: 64 | config = yaml.load(fp) 65 | servers = {} 66 | for name, sconfig in config.items(): 67 | slave = ReplicationSlave(config, name=name) 68 | slave.load_config() 69 | servers[name] = slave 70 | 71 | args.func(config, servers, args) 72 | 73 | def run_dump_config(config, servers, args): 74 | print '=== Server Config ===' 75 | for id, server in servers.items(): 76 | print '%s (%s) => %s' % ( 77 | server.name, server.id, server.uri) 78 | print 79 | for name, server in servers.items(): 80 | config = server.dump_config() 81 | print '=== %s Replication Config' % server.name 82 | for mname, mconfig in config.items(): 83 | for repl in mconfig['replication']: 84 | print ' - %s <= %s/%s (%s)' % ( 85 | repl['dst'], mname, repl['src'], repl['ops']) 86 | print 87 | 88 | def run_clear_config(config, servers, args): 89 | if args.slave: 90 | servers = [ servers[args.slave] ] 91 | else: 92 | servers = servers.values() 93 | 94 | yn = raw_input('About to clear config on servers: %s, are you sure? (yN) ' % 95 | [ server.name for server in servers ]) 96 | if yn.lower()[0] != 'y': 97 | print 'Aborted.' 98 | return 99 | for server in servers: 100 | print 'Clear config for %s' % server.name 101 | server.clear_config() 102 | 103 | def run_replicate(config, servers, args): 104 | s_src, ns_src = args.src.split('/', 1) 105 | s_dst, ns_dst = args.dst.split('/', 1) 106 | servers[s_dst].set_replication( 107 | s_src, ns_src=ns_src, ns_dst=ns_dst, ops=args.ops) 108 | 109 | def run_main(config, servers, args): 110 | log = logging.getLogger('mmm') 111 | for s in servers.values(): 112 | s.start() 113 | while True: 114 | gevent.sleep(5) 115 | log.info('=== mark ===') 116 | 117 | 118 | 119 | 120 | 121 | if __name__ == '__main__': 122 | main() 123 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | Vagrant::Config.run do |config| 5 | # All Vagrant configuration is done here. The most common configuration 6 | # options are documented and commented below. For a complete reference, 7 | # please see the online documentation at vagrantup.com. 8 | 9 | # Every Vagrant virtual environment requires a box to build off of. 10 | config.vm.box = "precise64" 11 | 12 | # The url from where the 'config.vm.box' box will be fetched if it 13 | # doesn't already exist on the user's system. 14 | # config.vm.box_url = "http://domain.com/path/to/above.box" 15 | 16 | # Boot with a GUI so you can see the screen. (Default is headless) 17 | # config.vm.boot_mode = :gui 18 | 19 | # Assign this VM to a host-only network IP, allowing you to access it 20 | # via the IP. Host-only networks can talk to the host machine as well as 21 | # any other machines on the same network, but cannot be accessed (through this 22 | # network interface) by any external networks. 23 | # config.vm.network :hostonly, "192.168.33.10" 24 | 25 | # Assign this VM to a bridged network, allowing you to connect directly to a 26 | # network using the host's network device. This makes the VM appear as another 27 | # physical device on your network. 28 | # config.vm.network :bridged 29 | 30 | # Forward a port from the guest to the host, which allows for outside 31 | # computers to access the VM, whereas host only networking does not. 32 | # config.vm.forward_port 80, 8080 33 | config.vm.forward_port 27017,27019 34 | 35 | # Share an additional folder to the guest VM. The first argument is 36 | # an identifier, the second is the path on the guest to mount the 37 | # folder, and the third is the path on the host to the actual folder. 38 | # config.vm.share_folder "v-data", "/vagrant_data", "../data" 39 | 40 | # Enable provisioning with Puppet stand alone. Puppet manifests 41 | # are contained in a directory path relative to this Vagrantfile. 42 | # You will need to create the manifests directory and a manifest in 43 | # the file precise64.pp in the manifests_path directory. 44 | # 45 | # An example Puppet manifest to provision the message of the day: 46 | # 47 | # # group { "puppet": 48 | # # ensure => "present", 49 | # # } 50 | # # 51 | # # File { owner => 0, group => 0, mode => 0644 } 52 | # # 53 | # # file { '/etc/motd': 54 | # # content => "Welcome to your Vagrant-built virtual machine! 55 | # # Managed by Puppet.\n" 56 | # # } 57 | # 58 | # config.vm.provision :puppet do |puppet| 59 | # puppet.manifests_path = "manifests" 60 | # puppet.manifest_file = "precise64.pp" 61 | # end 62 | 63 | # Enable provisioning with chef solo, specifying a cookbooks path, roles 64 | # path, and data_bags path (all relative to this Vagrantfile), and adding 65 | # some recipes and/or roles. 66 | # 67 | # config.vm.provision :chef_solo do |chef| 68 | # chef.cookbooks_path = "../my-recipes/cookbooks" 69 | # chef.roles_path = "../my-recipes/roles" 70 | # chef.data_bags_path = "../my-recipes/data_bags" 71 | # chef.add_recipe "mysql" 72 | # chef.add_role "web" 73 | # 74 | # # You may also specify custom JSON attributes: 75 | # chef.json = { :mysql_password => "foo" } 76 | # end 77 | 78 | # Enable provisioning with chef server, specifying the chef server URL, 79 | # and the path to the validation key (relative to this Vagrantfile). 80 | # 81 | # The Opscode Platform uses HTTPS. Substitute your organization for 82 | # ORGNAME in the URL and validation key. 83 | # 84 | # If you have your own Chef Server, use the appropriate URL, which may be 85 | # HTTP instead of HTTPS depending on your configuration. Also change the 86 | # validation key to validation.pem. 87 | # 88 | # config.vm.provision :chef_client do |chef| 89 | # chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME" 90 | # chef.validation_key_path = "ORGNAME-validator.pem" 91 | # end 92 | # 93 | # If you're using the Opscode platform, your validator client is 94 | # ORGNAME-validator, replacing ORGNAME with your organization name. 95 | # 96 | # IF you have your own Chef Server, the default validation client name is 97 | # chef-validator, unless you changed the configuration. 98 | # 99 | # chef.validation_client_name = "ORGNAME-validator" 100 | end 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MongoMultiMaster 2 | 3 | This is a tool which allows you to set up multi-master replication with 4 | MongoDB. It is emphatically *not* supported by 10gen, the makers of MongoDB. 5 | 6 | It works by querying the oplog on one replica set and applying its operations to 7 | another replica set. It supports bidirectional replication by tagging each 8 | document replicated with its source. 9 | 10 | ## Installing 11 | 12 | To install, use pip: 13 | 14 | pip install MongoMultiMaster 15 | 16 | ## MongoDB Setup 17 | 18 | MMM needs access to the replica set oplog for each master. This means it doesn't 19 | work with servers that are configured as standalone servers. To convert a 20 | standalone server to a singleton replica set, first you need to tell it about the 21 | set it's in at launch time: 22 | 23 | ~~~~ 24 | $ mongod --replSet foo 25 | ~~~~ 26 | 27 | Then, to start the replica set, you need to execute the following at the `mongo` 28 | shell: 29 | 30 | ~~~~ 31 | > rs.initiate() 32 | ~~~~ 33 | 34 | ## MongoMultiMaster Replication Setup 35 | 36 | Once you've created the replica set master, you'll need to tell MMM where the 37 | servers are. This is done through a YAML config file. A sample config file with 38 | two servers is included below: 39 | 40 | ~~~~ 41 | server_a: 42 | id: '2c88ae84-7cb9-40f7-835d-c05e981f564d' 43 | uri: 'mongodb://localhost:27019' 44 | server_b: 45 | id: '0d9c284b-b47c-40b5-932c-547b8685edd0' 46 | uri: 'mongodb://localhost:27017' 47 | ~~~~ 48 | 49 | First, let's verify that there's no configuration and that we can connect to all 50 | the servers in the config file: 51 | 52 | ~~~~ 53 | $ mmm -c test.yml clear-config 54 | About to clear config on servers: ['server_a', 'server_b'], are you sure? (yN) y 55 | Clear config for server_a 56 | Clear config for server_b 57 | $ mmm -c test.yml dump-config 58 | === Server Config === 59 | server_a (2c88ae84-7cb9-40f7-835d-c05e981f564d) => mongodb://localhost:27019 60 | server_b (0d9c284b-b47c-40b5-932c-547b8685edd0) => mongodb://localhost:27017 61 | 62 | === server_a Replication Config 63 | === server_b Replication Config 64 | 65 | ~~~~ 66 | 67 | Next, we'll set up two replicated collections: 68 | 69 | ~~~~ 70 | $ mmm -c test.yml replicate --src=server_a/test.foo --dst=server_b/test.foo 71 | $ mmm -c test.yml replicate --src=server_a/test.bar --dst=server_b/test.bar 72 | ~~~~ 73 | 74 | And confirm they're configured correctly: 75 | 76 | ~~~~ 77 | $ mmm -c test.yml dump-config 78 | === Server Config === 79 | server_a (2c88ae84-7cb9-40f7-835d-c05e981f564d) => mongodb://localhost:27019 80 | server_b (0d9c284b-b47c-40b5-932c-547b8685edd0) => mongodb://localhost:27017 81 | 82 | === server_a Replication Config 83 | === server_b Replication Config 84 | - test.foo <= server_a/test.foo 85 | - test.bar <= server_a/test.bar 86 | ~~~~ 87 | 88 | Now, let's make the replication bidirectional: 89 | 90 | ~~~~ 91 | $ mmm -c test.yml replicate --src=server_b/test.foo --dst=server_a/test.foo 92 | $ mmm -c test.yml replicate --src=server_b/test.bar --dst=server_a/test.bar 93 | ~~~~ 94 | 95 | And verify that it's correct... 96 | 97 | ~~~~ 98 | $ mmm -c test.yml dump-config 99 | === Server Config === 100 | server_a (2c88ae84-7cb9-40f7-835d-c05e981f564d) => mongodb://localhost:27019 101 | server_b (0d9c284b-b47c-40b5-932c-547b8685edd0) => mongodb://localhost:27017 102 | 103 | === server_a Replication Config 104 | - test.foo <= server_b/test.foo 105 | - test.bar <= server_b/test.bar 106 | === server_b Replication Config 107 | - test.foo <= server_a/test.foo 108 | - test.bar <= server_a/test.bar 109 | ~~~~ 110 | 111 | Now we can run the replicator: 112 | 113 | ~~~~ 114 | $ mmm -c test.yml run 115 | ~~~~ 116 | 117 | ## Things to Consider 118 | 119 | - Replication can fall behind if you're writing a lot. This is not handled at 120 | all. 121 | - Replication begins at the time when `mmm run` was first called. You should be 122 | able to stop/start `mmm` and have it pick up where it left off. 123 | - Conflicts between masters aren't handled; if you're writing to the same 124 | document on both heads frequently, you can get out of sync. 125 | - Replication inserts a bookkeeping field into each document to signify the 126 | server UUID that last wrote the document. This expands the size of each 127 | document slightly. 128 | 129 | 130 | There are probably sharp edges, other missed bugs, and various nasty things 131 | waiting for you if you use MMM in a production system without thorough 132 | testing. But if you like running with scissors and otherwise living dangerously, 133 | feel free to try it out. 134 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | MongoMultiMaster 2 | ================ 3 | 4 | This is a tool which allows you to set up multi-master replication with 5 | MongoDB. It is emphatically *not* supported by 10gen, the makers of 6 | MongoDB. 7 | 8 | It works by querying the oplog on one replica set and applying its 9 | operations to another replica set. It supports bidirectional replication 10 | by tagging each document replicated with its source. 11 | 12 | Installing 13 | ---------- 14 | 15 | To install, use pip: 16 | 17 | :: 18 | 19 | pip install MongoMultiMaster 20 | 21 | MongoDB Setup 22 | ------------- 23 | 24 | MMM needs access to the replica set oplog for each master. This means it 25 | doesn't work with servers that are configured as standalone servers. To 26 | convert a standalone server to a singleton replica set, first you need 27 | to tell it about the set it's in at launch time: 28 | 29 | :: 30 | 31 | $ mongod --replSet foo 32 | 33 | Then, to start the replica set, you need to execute the following at the 34 | ``mongo`` shell: 35 | 36 | :: 37 | 38 | > rs.initiate() 39 | 40 | MongoMultiMaster Replication Setup 41 | ---------------------------------- 42 | 43 | Once you've created the replica set master, you'll need to tell MMM 44 | where the servers are. This is done through a YAML config file. A sample 45 | config file with two servers is included below: 46 | 47 | :: 48 | 49 | server_a: 50 | id: '2c88ae84-7cb9-40f7-835d-c05e981f564d' 51 | uri: 'mongodb://localhost:27019' 52 | server_b: 53 | id: '0d9c284b-b47c-40b5-932c-547b8685edd0' 54 | uri: 'mongodb://localhost:27017' 55 | 56 | First, let's verify that there's no configuration and that we can 57 | connect to all the servers in the config file: 58 | 59 | :: 60 | 61 | $ mmm -c test.yml clear-config 62 | About to clear config on servers: ['server_a', 'server_b'], are you sure? (yN) y 63 | Clear config for server_a 64 | Clear config for server_b 65 | $ mmm -c test.yml dump-config 66 | === Server Config === 67 | server_a (2c88ae84-7cb9-40f7-835d-c05e981f564d) => mongodb://localhost:27019 68 | server_b (0d9c284b-b47c-40b5-932c-547b8685edd0) => mongodb://localhost:27017 69 | 70 | === server_a Replication Config 71 | === server_b Replication Config 72 | 73 | Next, we'll set up two replicated collections: 74 | 75 | :: 76 | 77 | $ mmm -c test.yml replicate --src=server_a/test.foo --dst=server_b/test.foo 78 | $ mmm -c test.yml replicate --src=server_a/test.bar --dst=server_b/test.bar 79 | 80 | And confirm they're configured correctly: 81 | 82 | :: 83 | 84 | $ mmm -c test.yml dump-config 85 | === Server Config === 86 | server_a (2c88ae84-7cb9-40f7-835d-c05e981f564d) => mongodb://localhost:27019 87 | server_b (0d9c284b-b47c-40b5-932c-547b8685edd0) => mongodb://localhost:27017 88 | 89 | === server_a Replication Config 90 | === server_b Replication Config 91 | - test.foo <= server_a/test.foo 92 | - test.bar <= server_a/test.bar 93 | 94 | Now, let's make the replication bidirectional: 95 | 96 | :: 97 | 98 | $ mmm -c test.yml replicate --src=server_b/test.foo --dst=server_a/test.foo 99 | $ mmm -c test.yml replicate --src=server_b/test.bar --dst=server_a/test.bar 100 | 101 | And verify that it's correct... 102 | 103 | :: 104 | 105 | $ mmm -c test.yml dump-config 106 | === Server Config === 107 | server_a (2c88ae84-7cb9-40f7-835d-c05e981f564d) => mongodb://localhost:27019 108 | server_b (0d9c284b-b47c-40b5-932c-547b8685edd0) => mongodb://localhost:27017 109 | 110 | === server_a Replication Config 111 | - test.foo <= server_b/test.foo 112 | - test.bar <= server_b/test.bar 113 | === server_b Replication Config 114 | - test.foo <= server_a/test.foo 115 | - test.bar <= server_a/test.bar 116 | 117 | Now we can run the replicator: 118 | 119 | :: 120 | 121 | $ mmm -c test.yml run 122 | 123 | Things to Consider 124 | ------------------ 125 | 126 | - Replication can fall behind if you're writing a lot. This is not 127 | handled at all. 128 | - Replication begins at the time when ``mmm run`` was first called. You 129 | should be able to stop/start ``mmm`` and have it pick up where it 130 | left off. 131 | - Conflicts between masters aren't handled; if you're writing to the 132 | same document on both heads frequently, you can get out of sync. 133 | - Replication inserts a bookkeeping field into each document to signify 134 | the server UUID that last wrote the document. This expands the size 135 | of each document slightly. 136 | 137 | There are probably sharp edges, other missed bugs, and various nasty 138 | things waiting for you if you use MMM in a production system without 139 | thorough testing. But if you like running with scissors and otherwise 140 | living dangerously, feel free to try it out. 141 | -------------------------------------------------------------------------------- /MongoMultiMaster.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 1.1 2 | Name: MongoMultiMaster 3 | Version: 0.0.4dev 4 | Summary: Multimaster replication for MongoDB 5 | Home-page: https://github.com/rick446/mmm 6 | Author: Rick Copeland 7 | Author-email: rick@arborian.com 8 | License: Apache License, Version 2.0 9 | Description: MongoMultiMaster 10 | ================ 11 | 12 | This is a tool which allows you to set up multi-master replication with 13 | MongoDB. It is emphatically *not* supported by 10gen, the makers of 14 | MongoDB. 15 | 16 | It works by querying the oplog on one replica set and applying its 17 | operations to another replica set. It supports bidirectional replication 18 | by tagging each document replicated with its source. 19 | 20 | Installing 21 | ---------- 22 | 23 | To install, use pip: 24 | 25 | :: 26 | 27 | pip install MongoMultiMaster 28 | 29 | MongoDB Setup 30 | ------------- 31 | 32 | MMM needs access to the replica set oplog for each master. This means it 33 | doesn't work with servers that are configured as standalone servers. To 34 | convert a standalone server to a singleton replica set, first you need 35 | to tell it about the set it's in at launch time: 36 | 37 | :: 38 | 39 | $ mongod --replSet foo 40 | 41 | Then, to start the replica set, you need to execute the following at the 42 | ``mongo`` shell: 43 | 44 | :: 45 | 46 | > rs.initiate() 47 | 48 | MongoMultiMaster Replication Setup 49 | ---------------------------------- 50 | 51 | Once you've created the replica set master, you'll need to tell MMM 52 | where the servers are. This is done through a YAML config file. A sample 53 | config file with two servers is included below: 54 | 55 | :: 56 | 57 | server_a: 58 | id: '2c88ae84-7cb9-40f7-835d-c05e981f564d' 59 | uri: 'mongodb://localhost:27019' 60 | server_b: 61 | id: '0d9c284b-b47c-40b5-932c-547b8685edd0' 62 | uri: 'mongodb://localhost:27017' 63 | 64 | First, let's verify that there's no configuration and that we can 65 | connect to all the servers in the config file: 66 | 67 | :: 68 | 69 | $ mmm -c test.yml clear-config 70 | About to clear config on servers: ['server_a', 'server_b'], are you sure? (yN) y 71 | Clear config for server_a 72 | Clear config for server_b 73 | $ mmm -c test.yml dump-config 74 | === Server Config === 75 | server_a (2c88ae84-7cb9-40f7-835d-c05e981f564d) => mongodb://localhost:27019 76 | server_b (0d9c284b-b47c-40b5-932c-547b8685edd0) => mongodb://localhost:27017 77 | 78 | === server_a Replication Config 79 | === server_b Replication Config 80 | 81 | Next, we'll set up two replicated collections: 82 | 83 | :: 84 | 85 | $ mmm -c test.yml replicate --src=server_a/test.foo --dst=server_b/test.foo 86 | $ mmm -c test.yml replicate --src=server_a/test.bar --dst=server_b/test.bar 87 | 88 | And confirm they're configured correctly: 89 | 90 | :: 91 | 92 | $ mmm -c test.yml dump-config 93 | === Server Config === 94 | server_a (2c88ae84-7cb9-40f7-835d-c05e981f564d) => mongodb://localhost:27019 95 | server_b (0d9c284b-b47c-40b5-932c-547b8685edd0) => mongodb://localhost:27017 96 | 97 | === server_a Replication Config 98 | === server_b Replication Config 99 | - test.foo <= server_a/test.foo 100 | - test.bar <= server_a/test.bar 101 | 102 | Now, let's make the replication bidirectional: 103 | 104 | :: 105 | 106 | $ mmm -c test.yml replicate --src=server_b/test.foo --dst=server_a/test.foo 107 | $ mmm -c test.yml replicate --src=server_b/test.bar --dst=server_a/test.bar 108 | 109 | And verify that it's correct... 110 | 111 | :: 112 | 113 | $ mmm -c test.yml dump-config 114 | === Server Config === 115 | server_a (2c88ae84-7cb9-40f7-835d-c05e981f564d) => mongodb://localhost:27019 116 | server_b (0d9c284b-b47c-40b5-932c-547b8685edd0) => mongodb://localhost:27017 117 | 118 | === server_a Replication Config 119 | - test.foo <= server_b/test.foo 120 | - test.bar <= server_b/test.bar 121 | === server_b Replication Config 122 | - test.foo <= server_a/test.foo 123 | - test.bar <= server_a/test.bar 124 | 125 | Now we can run the replicator: 126 | 127 | :: 128 | 129 | $ mmm -c test.yml run 130 | 131 | Things to Consider 132 | ------------------ 133 | 134 | - Replication can fall behind if you're writing a lot. This is not 135 | handled at all. 136 | - Replication begins at the time when ``mmm run`` was first called. You 137 | should be able to stop/start ``mmm`` and have it pick up where it 138 | left off. 139 | - Conflicts between masters aren't handled; if you're writing to the 140 | same document on both heads frequently, you can get out of sync. 141 | - Replication inserts a bookkeeping field into each document to signify 142 | the server UUID that last wrote the document. This expands the size 143 | of each document slightly. 144 | 145 | There are probably sharp edges, other missed bugs, and various nasty 146 | things waiting for you if you use MMM in a production system without 147 | thorough testing. But if you like running with scissors and otherwise 148 | living dangerously, feel free to try it out. 149 | 150 | Keywords: mongodb,replication 151 | Platform: UNKNOWN 152 | Classifier: Development Status :: 3 - Alpha 153 | Classifier: Environment :: Console 154 | Classifier: Intended Audience :: Developers 155 | Classifier: License :: OSI Approved :: Apache Software License 156 | Classifier: Natural Language :: English 157 | Classifier: Operating System :: OS Independent 158 | Classifier: Programming Language :: Python :: 2.7 159 | Classifier: Topic :: Database :: Database Engines/Servers 160 | Classifier: Topic :: Utilities 161 | -------------------------------------------------------------------------------- /mmm/slave.py: -------------------------------------------------------------------------------- 1 | import copy 2 | import time 3 | import uuid 4 | import logging 5 | 6 | import gevent 7 | 8 | from .triggers import Triggers 9 | 10 | log = logging.getLogger(__name__) 11 | 12 | MMM_DB_NAME = 'mmm' 13 | MMM_REPL_FLAG = '__mmm' 14 | 15 | class ReplicationSlave(object): 16 | '''Sets up replication based on info in the local 'mmm' collection. 17 | 18 | Each 'master' connection has its own document in mmm: 19 | 20 | { _id: some_uuid, 21 | checkpoint: ..., // timestamp offset in the oplog 22 | replication: [ { 23 | dst: 'slave-db.collection', 24 | src: 'master-db.collection', 25 | ops:'iud' }, 26 | ... ] 27 | } 28 | ''' 29 | 30 | def __init__(self, topology, name, connect=None, timestamp=None): 31 | if connect: self.connect = connect 32 | if timestamp: self.timestamp = timestamp 33 | self._topology = topology 34 | self.name = name 35 | topo = topology[name] 36 | self.id = topo['id'] 37 | if isinstance(self.id, basestring): 38 | self.id = uuid.UUID(self.id) 39 | self.uri = topo['uri'] 40 | self._conn = self.connect(self.uri) 41 | self._coll = self._conn.local[MMM_DB_NAME] 42 | self._config = {} 43 | self._greenlets = [] 44 | 45 | def connect(self, *args, **kwargs): 46 | '''Connect to a mongod server. Factored into a method so we can delay 47 | importing Connection until gevent.monkey.patch_all() is called. You could 48 | also insert another connect function to set options if you so desire. 49 | ''' 50 | from pymongo import Connection 51 | return Connection(*args, **kwargs) 52 | 53 | def timestamp(self, *args, **kwargs): 54 | '''Create a bson.Timestamp. Factored into a method so we can delay 55 | importing socket until gevent.monkey.patch_all() is called. You could 56 | also insert another timestamp function to set options if you so desire. 57 | ''' 58 | import bson 59 | return bson.Timestamp(*args, **kwargs) 60 | 61 | def start(self, checkpoint=None): 62 | for gl in self._greenlets: 63 | gl.kill() 64 | self.load_config() 65 | self._greenlets = [ 66 | gevent.spawn_link_exception(self.periodic_checkpoint, 5) ] 67 | for master_uri in self._config: 68 | self._greenlets.append( 69 | gevent.spawn_link_exception( 70 | self.replicate, master_uri, checkpoint)) 71 | 72 | def load_config(self): 73 | self._config = {} 74 | name_by_id = dict( 75 | (sconf['id'], name) 76 | for name, sconf in self._topology.items()) 77 | for master in self._coll.find(): 78 | self._config[name_by_id[master['_id']]] = master 79 | 80 | def clear_config(self): 81 | self._config = {} 82 | self._coll.remove() 83 | 84 | def dump_config(self): 85 | result = {} 86 | for name, sconfig in self._config.items(): 87 | d = copy.deepcopy(sconfig) 88 | d.pop('checkpoint', None) 89 | result[name] = d 90 | return result 91 | 92 | def set_replication(self, master_name, ns_dst, ns_src, ops='iud'): 93 | master_id = self._topology[master_name]['id'] 94 | self._coll.update( 95 | dict(_id=master_id), 96 | { '$pull': { 'replication': dict(dst=ns_dst, src=ns_src) } }) 97 | master = self._coll.find_and_modify( 98 | dict(_id=master_id), 99 | { '$push': {'replication': dict(dst=ns_dst, src=ns_src, ops=ops) }}, 100 | upsert=True, 101 | new=True) 102 | self._config[master_name] = master 103 | 104 | def unset_replication(self, master_name, ns_dst=None, ns_src=None): 105 | master_id = self._topology[master_name]['id'] 106 | to_pull = dict() 107 | if ns_dst is not None: to_pull['dst'] = ns_dst 108 | if ns_src is not None: to_pull['src'] = ns_src 109 | if ns_dst or ns_src: 110 | # Stop replication on one namespace 111 | master = self._coll.find_and_modify( 112 | dict(_id=master_id), 113 | { '$pull': { 'replication': to_pull } }, 114 | new=True) 115 | self._config[master_name] = master 116 | else: 117 | # Stop replication on the whole master 118 | self._coll.remove(dict(_id=master_id)) 119 | self._config.pop(master_name, None) 120 | 121 | def checkpoint(self, master_uri=None): 122 | if master_uri is None: 123 | masters = self._config.items() 124 | else: 125 | masters = [ 126 | (master_uri, self._config[master_uri]) ] 127 | for _id, master in masters: 128 | self._coll.update( 129 | dict(_id=_id), 130 | { '$set': { 'checkpoint': master['checkpoint'] } }) 131 | 132 | def replicate(self, master_name, checkpoint=None): 133 | '''Actual replication loop for replicating off of master_uri''' 134 | master_repl_config = self._config[master_name] 135 | master_info = self._topology[master_name] 136 | master_id = master_repl_config['_id'] 137 | conn = self.connect(master_info['uri']) 138 | if checkpoint is None: 139 | checkpoint = master_repl_config.get('checkpoint') 140 | if checkpoint is None: 141 | # By default, start replicating as of NOW 142 | checkpoint = self.timestamp(long(time.time()), 0) 143 | triggers = Triggers(conn, checkpoint) 144 | for repl in master_repl_config['replication']: 145 | triggers.register( 146 | repl['src'], repl['ops'], 147 | self._replicate_to_trigger(master_id, repl['dst'])) 148 | for checkpoint in triggers.run(): 149 | master_repl_config['checkpoint'] = checkpoint 150 | 151 | def periodic_checkpoint(self, period=1.0): 152 | '''Periodically call self.checkpoint() to allow restarts''' 153 | while True: 154 | gevent.sleep(period) 155 | self.checkpoint() 156 | 157 | def _replicate_to_trigger(self, src_id, dst): 158 | if isinstance(src_id, basestring): 159 | src_id = uuid.UUID(src_id) 160 | db, cname = dst.split('.', 1) 161 | collection = self._conn[db][cname] 162 | def trigger(ts, h, op, ns, o, o2=None, b=False): 163 | log.info('%s <= %s: %s %s', self.id, src_id, op, ns) 164 | if op == 'i': 165 | if o.get(MMM_REPL_FLAG) == self.id: 166 | log.debug('%s: skip', self.id) 167 | return 168 | o.setdefault(MMM_REPL_FLAG, src_id) 169 | collection.insert(o) 170 | elif op == 'u': 171 | log.debug('o %s, o2 %s', o, o2) 172 | upsert = b 173 | if any(k.startswith('$') for k in o): 174 | # With modifiers, check & update setters 175 | setters = o.setdefault('$set', {}) 176 | else: 177 | # Without modifiers, check & update the doc directly 178 | setters = o 179 | if setters.get(MMM_REPL_FLAG) == self.id: 180 | log.debug('%s: skip', self.id) 181 | return 182 | setters.setdefault(MMM_REPL_FLAG, src_id) 183 | 184 | log.debug('o %s, o2 %s', o, o2) 185 | collection.update(o2, o, upsert) 186 | elif op == 'd': 187 | justOne = b 188 | collection.remove(o) 189 | return trigger 190 | 191 | def __getitem__(self, ns_dst): 192 | return _ReplLHS(self, ns_dst) 193 | 194 | class _ReplLHS(object): 195 | 196 | def __init__(self, slave, ns_dst): 197 | self.slave = slave 198 | self.ns_dst = ns_dst 199 | 200 | def __lshift__(self, (master_uri, ns_src)): 201 | self.slave.set_replication( 202 | master_uri, ns_dst=self.ns_dst, ns_src=ns_src) 203 | return self 204 | 205 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------