Class: MongoHelper::DataLocker

Inherits:
Object
  • Object
show all
Defined in:
lib/ec2-consistent-backup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port = 27017, host = 'localhost') ⇒ DataLocker

Returns a new instance of DataLocker.



95
96
97
98
99
100
101
102
# File 'lib/ec2-consistent-backup.rb', line 95

def initialize(port = 27017, host = 'localhost')
  @m = Mongo::Connection.new(host, port)
  args =  @m['admin'].command({'getCmdLineOpts' => 1 })['argv']
  p = args.index('--dbpath')
  @path = args[p+1]
  @path = File.readlink(@path) if File.symlink?(@path)

end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



94
95
96
# File 'lib/ec2-consistent-backup.rb', line 94

def path
  @path
end

Instance Method Details

#lockObject



103
104
105
106
107
108
109
110
# File 'lib/ec2-consistent-backup.rb', line 103

def lock
  return if locked?
  @m.lock!
  while !locked? do
    sleep(1)
  end
  raise "Not locked as asked" if !locked?
end

#locked?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/ec2-consistent-backup.rb', line 111

def locked?
  @m.locked?
end

#unlockObject



114
115
116
117
118
119
120
121
# File 'lib/ec2-consistent-backup.rb', line 114

def unlock
  return if !locked?
  raise "Already unlocked" if !locked?
  @m.unlock!
  while locked? do
    sleep(1)
  end
end