Consoles
 

Archive for the ‘Engineering’ Category

Bzr to Git Migration

by Abhishek Mukherjee, March 8th, 2010 at 12:44pm - No Comments »
Tagged As: , ,
Posted in: Infrastructure

When I joined Agora, one of the first things I did was talk up git and how it’ll cure cancer, AIDS, and solve world peace. All at once. What that means for me is I’ve basically been tasked with the job of migrating anything that’s not git to git.

For some things these kinds of migration are first class citizens. Conveniently SVN, our old VCS is one of those. One of my new migrations was, less conveniently, Bazaar. Now we have nothing against Bazaar at Agora but we agreed we would rather only have one VCS in house.

After looking around and trying some fancy tools that didn’t work (read: tailor), I stumbled on a really quick solution that seems like it does everything necessary. Both Git and Bazaar (via plugins) support the fast-import/export format. I’m not sure about the mystic ways of how this format works but I do know it made my Bazaar repository a Git repository, and that makes me pleased.

Getting the bzr plugin

The first step would be to get the fast-import plugin for Bazaar from the launchpad mirror.

mkdir -p ~/.bzr/plugins
cd ~/.bzr/plugins
bzr clone lp:bzr-fastimport fastimport

You can make sure it installed properly using a bzr fast-export --help and ensure that it doesn’t complain.

Copy the repository

Now that we have all the tools, time to copy it over

mkdir ~/project.git
cd ~/project.git
git init
bzr fast-export --plain ~/path/to/bzr/branch | git fast-import
git checkout master  # only needed for a non-bare repository, like I made above

Wait a little while (or a long while if you’re testing the above code on a netbook for some reason like me). And that should be it.

I’m not sure how well this works with multiple Bazaar branches. There may be some crazy --flags on each side to make it work but running the code I put above on a full repo makes fast-export complain that I’m not pointing it to a valid branch. Please give us your comments if you know how to do this :).

  • Reddit
  • Digg
  • del.icio.us
  • Technorati

Watching Trees

by Jason LaPorte, February 23rd, 2010 at 09:43am - No Comments »
Tagged As: ,
Posted in: Engineering, Infrastructure

As a SysAdmin, my job more-or-less exists by knowing miscellaneous arcana that most software engineers aren’t aware of.

When a particular co-worker here at Agora has a problem with his Linux machine, I provide advice and show him how to fix it. Some months after he had joined Agora, I discovered that after each troubleshooting session, he copy-and-pastes the entire text terminal log into a text file that he keeps on his desktop. He has dozens of transcripts at this point; I bet if I were to look through it, it would read something like the Tao te Ching or Bhagavad Gita, only concerning UNIX instead of right living.

(Of course, there’s not much of a difference between UNIX and right living, but that’s a topic for another day.)

In the spirit of allowing you to build your own little collection, here is a simple trick that came in handy to me yesterday.

(more…)

  • Reddit
  • Digg
  • del.icio.us
  • Technorati

Experimenting with Redis

by David Czarnecki, February 23rd, 2010 at 09:05am - 2 Comments »
Tagged As: , ,
Posted in: Engineering, Infrastructure, Uncategorized

Yesterday I started looking at ways to do inter-application communication. In a number of projects we’ve done here at Agora Games, we’ve used queues to make that happen. Redis has been on my radar for awhile now, but yesterday I drove my Chevy to the levee and guess what? The levee is NOT dry people. I mean, who drinks rye anyway these days? Old people.

(more…)

  • Reddit
  • Digg
  • del.icio.us
  • Technorati

And now for some couchdb

by Brian Corrigan, February 22nd, 2010 at 11:20pm - No Comments »
Posted in: Engineering, Infrastructure

I had occasion tonight to give a quick demo of CouchDB.  This is so simple its almost not worth blogging about, but hey, good software is supposed to be simple.

Install
On your Mac:

sudo port install couchdb
sudo launchctl load -w /Library/LaunchDaemons/org.apache.couchdb.plist

On Ubuntu:

sudo apt-get install couchdb

You’re done; now to play.

Futon Admin Interface
This allows you to create a DB, create records, etc.

  1. Open http://localhost:5984/_utils/
  2. Prosper

Using our old friend curl

curl -X PUT http://localhost:5984/mlg/ #create a db
curl -X GET http://localhost:5984/mlg/ #get a whole bunch of info about the db
curl -X POST http://localhost:5984/mlg/ -H "Content-Type:application/json" -d '{"body": "Here is a paragraph"}' #create a record
  • Reddit
  • Digg
  • del.icio.us
  • Technorati

Getting started with data_fabric

by David Czarnecki, January 29th, 2010 at 11:46am - No Comments »
Tagged As: , , , ,
Posted in: Bending Rails, Uncategorized

The data_fabric gem “provides flexible database connection switching for ActiveRecord”. If you’re not concerned with database sharding, you might want to skip this blog post. Or not. Either way, I’m not going to be offended.

I have a requirement that certain data in an application that I’m developing will probably have to be sharded because, if you’ll excuse my English, there will a “shit ton” of data. This only affects one model out of the few models I have in the application. I don’t have a requirement that the data will be replicated (which is another feature supported in data_fabric), so I’m not going into that here. In any event, here is a rundown of how I got started developing and testing with data_fabric.

- Configure the data_fabric gem in your config/environment.rb file.


config.gem 'data_fabric'

- In your model(s), decide on which column or how the data is going to be shared.


data_fabric :replicated => false, :shard_by => :initial_code

In this case, inital_code is a method that looks at a piece of the model’s data and gives me the correct shard.

- Setup the database shards in your config/database.yml file. I actually setup only one shard for development and testing environments to make things easier. I’m just including the one for the test environment here. You can read on the data_fabric site about the naming convention for sharded database connections.


test:
adapter: mysql
encoding: utf8
reconnect: false
database: myapp_test
pool: 5
username: root
password:

# This is the database shard
initial_code_testenv_test:
adapter: mysql
encoding: utf8
reconnect: false
database: myapp_test_testenv
pool: 5
username: root
password:

- In config/initializers/my_app_model.rb, I actually stub out the initial_code method to return a single value for the development and test environments. This is merely convenience so I don’t have to include every single database shard for development and testing.


require 'mocha'

if 'development'.eql?(RAILS_ENV)
PromotionCode.stubs(:initial_code).returns('devenv')
end

if 'test'.eql?(RAILS_ENV)
PromotionCode.stubs(:initial_code).returns('testenv')
end

- I copied part of the Rakefile from the data_fabric gem to actually be able to migrate the database for the sharded database connections. This was definitely missing from the data_fabric README.


require 'fileutils'
include FileUtils::Verbose

namespace :db do
task :migrate do
require 'erb'
require 'logger'
require 'active_record'
reference = YAML::load(ERB.new(IO.read("config/database.yml")).result)
env = RAILS_ENV = ENV['RAILS_ENV'] || 'development'
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.logger.level = Logger::WARN
ActiveRecord::Base.configurations = reference.dup
old_config = reference[env]
reference.each_key do |name|
next unless name.include? env
next if name.include? 'slave' # Replicated databases should not be touched directly

puts "Migrating #{name}"
ActiveRecord::Base.clear_active_connections!
ActiveRecord::Base.configurations[env] = reference[name]
ActiveRecord::Base.establish_connection RAILS_ENV
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
end
end
end

- In my test classes that use the sharded model, I have setup and teardown methods that activate and deactivate the shard.


def setup
DataFabric.activate_shard(:initial_code => 'testenv')
end

def teardown
MyAppModel.delete_all
DataFabric.deactivate_shard(:initial_code => 'testenv')
end

I did find that I needed to delete all the objects in the database for the sharded model. I’m still digging into why that’s the case. My ActiveRecord_fu isn’t that strong I guess.

All in all, sharding is relatively easy with data_fabric. Pimping, however, “ain’t easy.” But that’s for another blog post I guess.

  • Reddit
  • Digg
  • del.icio.us
  • Technorati