Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

todo : reenabled #copy for Tyrant (Edo and Tokyo) - closes gh-19

(would be good to have one at hand for tyrant tables)
  • Loading branch information...
commit 3bbc937e508fee0757106db3130c53ef384679a2 1 parent e44436f
@jmettraux authored
View
2  CHANGELOG.txt
@@ -23,6 +23,8 @@
not being supported (Edo and Tokyo)
- added : can set built-in or custom comparison functions for b-tree databases
(Edo interface only)
+- todo : reenabled #copy for Tyrant (Edo and Tokyo)
+
== rufus-tokyo - 1.0.1 released 2009/09/18
View
3  TODO.txt
@@ -21,6 +21,7 @@
[o] implement q.metasearch(q, u)
[o] table/delete_keys_with_prefix, use searchout
[o] default value / default_proc for cabinets
+[o] self.open for tables
[ ] ldelete for tables ?
@@ -32,5 +33,5 @@
[ ] wire setmutex for Cabinet (and ?)
-[ ] self.open for tables
+[ ] copy for tyrant tables ?
View
12 lib/rufus/edo/ntyrant/abstract.rb
@@ -119,14 +119,18 @@ def weight
self.stat['size']
end
- # isn't that a bit dangerous ? it creates a file on the server...
+ # Tells the Tyrant server to create a copy of itself at the given (remote)
+ # target_path.
#
- # DISABLED.
+ # Returns true when successful.
+ #
+ # Note : if you started your ttserver with a path like "tyrants/data.tch"
+ # you have to provide a target path in the same subdir, like
+ # "tyrants/data_prime.tch".
#
def copy (target_path)
- #@db.copy(target_path)
- raise 'not allowed to create files on the server'
+ @db.copy(target_path) || raise_error
end
# Copies the current cabinet to a new file.
View
20 lib/rufus/tokyo/tyrant/abstract.rb
@@ -123,20 +123,25 @@ def lib
TyrantLib
end
- # isn't that a bit dangerous ? it creates a file on the server...
+ # Tells the Tyrant server to create a copy of itself at the given (remote)
+ # target_path.
#
- # DISABLED.
+ # Returns true when successful.
+ #
+ # Note : if you started your ttserver with a path like "tyrants/data.tch"
+ # you have to provide a target path in the same subdir, like
+ # "tyrants/data_prime.tch".
#
def copy (target_path)
- #@db.copy(target_path)
- raise 'not allowed to create files on the server'
+ (lib.abs_copy(@db, target_path) == 1) || raise_error
end
# Tyrant databases DO NOT support the 'defrag' call. Calling this method
# will raise an exception.
#
def defrag
+
raise(NoMethodError.new("Tyrant dbs don't support #defrag"))
end
@@ -154,6 +159,13 @@ def do_stat
lib.tcrdbstat(@db)
end
+
+ def raise_error
+
+ code = lib.abs_ecode(@db)
+ message = lib.abs_errmsg(@db, code)
+ raise TokyoError.new("(err #{code}) #{message}")
+ end
end
end
View
5 lib/rufus/tokyo/tyrant/lib.rb
@@ -64,6 +64,9 @@ class << self
attfunc :tcrdbopen, [ :pointer, :string, :int ], :int
attfunc :abs_close, :tcrdbclose, [ :pointer ], :int
+ attfunc :abs_ecode, :tcrdbecode, [ :pointer ], :int
+ attfunc :abs_errmsg, :tcrdberrmsg, [ :pointer, :int ], :string
+
attfunc :abs_del, :tcrdbdel, [ :pointer ], :void
attfunc :abs_rnum, :tcrdbrnum, [ :pointer ], :uint64
@@ -110,7 +113,7 @@ class << self
attfunc :tab_out, :tcrdbtblout, [ :pointer, :string, :int ], :int
attfunc :tab_ecode, :tcrdbecode, [ :pointer ], :int
- attfunc :tab_errmsg, :tcrdberrmsg, [ :int ], :string
+ attfunc :tab_errmsg, :tcrdberrmsg, [ :pointer, :int ], :string
attfunc :tab_del, :tcrdbdel, [ :pointer ], :void
View
1  spec/edo_ntyrant_spec.rb
@@ -103,6 +103,7 @@
end
behaves_like 'a Tyrant structure (no transactions)'
+ behaves_like 'a Tyrant structure (copy method)'
end
describe Rufus::Edo::NetTyrant do
View
18 spec/shared_tyrant_spec.rb
@@ -22,3 +22,21 @@
end
end
+shared 'a Tyrant structure (copy method)' do
+
+ it 'should accept #copy calls' do
+
+ SOURCE = 'tmp/tyrant.tch'
+
+ TARGET = File.expand_path(
+ File.join(File.dirname(__FILE__), '../tmp/tyrant_copy.tch'))
+
+ @db.copy(TARGET)
+
+ File.exist?(TARGET).should.be.true
+ File.stat(TARGET).size.should.equal(File.stat(SOURCE).size)
+
+ FileUtils.rm(TARGET)
+ end
+end
+
View
1  spec/start_tyrants.sh
@@ -15,6 +15,7 @@ ttserver \
-port 45000 \
-pid $TMP/t_spec.pid -rts $TMP/t_spec.rts \
-log $TMP/t.log \
+ -unmask copy \
$TMP/tyrant.tch
ttserver \
View
1  spec/tyrant_spec.rb
@@ -90,6 +90,7 @@
behaves_like 'an abstract structure'
behaves_like 'a Tyrant structure (no transactions)'
+ behaves_like 'a Tyrant structure (copy method)'
it 'should respond to stat' do
Please sign in to comment.
Something went wrong with that request. Please try again.