metry 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +14 -69
- data/TODO +2 -3
- data/cucumber.yml +1 -0
- data/example/example.rb +1 -1
- data/features/psycho/dashboard.feature +17 -0
- data/features/psycho/goals.feature +24 -0
- data/features/psycho/visitor_tracking.feature +32 -0
- data/features/step_definitions/goals.rb +3 -0
- data/features/step_definitions/tracking.rb +1 -1
- data/features/step_definitions/web.rb +14 -2
- data/features/support/env.rb +4 -0
- data/lib/metry.rb +4 -6
- data/lib/metry/experiment.rb +6 -8
- data/lib/metry/psycho.rb +112 -0
- data/lib/metry/psycho/dashboard.erb +14 -0
- data/lib/metry/psycho/layout.erb +8 -0
- data/lib/metry/psycho/new_goal.erb +9 -0
- data/lib/metry/psycho/visitor.erb +7 -0
- data/lib/metry/rack/tracking.rb +17 -13
- data/lib/metry/storage.rb +116 -0
- data/radiant/example/features/metry.feature +8 -8
- data/radiant/example/features/psycho.feature +13 -0
- data/radiant/example/features/step_definitions/experiments.rb +2 -2
- data/radiant/example/features/step_definitions/tracking.rb +1 -1
- data/radiant/example/features/support/env.rb +3 -0
- data/radiant/extension/lib/metry_authenticator.rb +30 -0
- data/radiant/extension/lib/metry_tags.rb +2 -1
- data/radiant/extension/metry_extension.rb +1 -1
- data/test/{test_tokyo.rb → test_storage.rb} +3 -3
- metadata +17 -72
- data/lib/metry/memory.rb +0 -27
- data/lib/metry/tokyo.rb +0 -181
- data/vendor/rufus-tokyo/CHANGELOG.txt +0 -112
- data/vendor/rufus-tokyo/CREDITS.txt +0 -27
- data/vendor/rufus-tokyo/LICENSE.txt +0 -21
- data/vendor/rufus-tokyo/README.txt +0 -310
- data/vendor/rufus-tokyo/Rakefile +0 -118
- data/vendor/rufus-tokyo/TODO.txt +0 -25
- data/vendor/rufus-tokyo/doc/decision_table.numbers +0 -0
- data/vendor/rufus-tokyo/doc/rdoc-style.css +0 -320
- data/vendor/rufus-tokyo/lib/rufus-edo.rb +0 -3
- data/vendor/rufus-tokyo/lib/rufus-tokyo.rb +0 -3
- data/vendor/rufus-tokyo/lib/rufus/edo.rb +0 -39
- data/vendor/rufus-tokyo/lib/rufus/edo/README.txt +0 -106
- data/vendor/rufus-tokyo/lib/rufus/edo/cabcore.rb +0 -333
- data/vendor/rufus-tokyo/lib/rufus/edo/cabinet/abstract.rb +0 -219
- data/vendor/rufus-tokyo/lib/rufus/edo/cabinet/table.rb +0 -159
- data/vendor/rufus-tokyo/lib/rufus/edo/error.rb +0 -36
- data/vendor/rufus-tokyo/lib/rufus/edo/ntyrant.rb +0 -4
- data/vendor/rufus-tokyo/lib/rufus/edo/ntyrant/abstract.rb +0 -137
- data/vendor/rufus-tokyo/lib/rufus/edo/ntyrant/table.rb +0 -141
- data/vendor/rufus-tokyo/lib/rufus/edo/tabcore.rb +0 -567
- data/vendor/rufus-tokyo/lib/rufus/tokyo.rb +0 -58
- data/vendor/rufus-tokyo/lib/rufus/tokyo/cabinet/abstract.rb +0 -568
- data/vendor/rufus-tokyo/lib/rufus/tokyo/cabinet/lib.rb +0 -230
- data/vendor/rufus-tokyo/lib/rufus/tokyo/cabinet/table.rb +0 -753
- data/vendor/rufus-tokyo/lib/rufus/tokyo/cabinet/util.rb +0 -425
- data/vendor/rufus-tokyo/lib/rufus/tokyo/config.rb +0 -161
- data/vendor/rufus-tokyo/lib/rufus/tokyo/dystopia.rb +0 -43
- data/vendor/rufus-tokyo/lib/rufus/tokyo/dystopia/lib.rb +0 -65
- data/vendor/rufus-tokyo/lib/rufus/tokyo/dystopia/words.rb +0 -71
- data/vendor/rufus-tokyo/lib/rufus/tokyo/hmethods.rb +0 -111
- data/vendor/rufus-tokyo/lib/rufus/tokyo/query.rb +0 -102
- data/vendor/rufus-tokyo/lib/rufus/tokyo/transactions.rb +0 -74
- data/vendor/rufus-tokyo/lib/rufus/tokyo/ttcommons.rb +0 -59
- data/vendor/rufus-tokyo/lib/rufus/tokyo/tyrant.rb +0 -35
- data/vendor/rufus-tokyo/lib/rufus/tokyo/tyrant/abstract.rb +0 -146
- data/vendor/rufus-tokyo/lib/rufus/tokyo/tyrant/lib.rb +0 -153
- data/vendor/rufus-tokyo/lib/rufus/tokyo/tyrant/table.rb +0 -162
- data/vendor/rufus-tokyo/rufus-tokyo.gemspec +0 -25
- data/vendor/rufus-tokyo/spec/cabinet_spec.rb +0 -472
- data/vendor/rufus-tokyo/spec/cabinetconfig_spec.rb +0 -82
- data/vendor/rufus-tokyo/spec/edo_cabinet_spec.rb +0 -447
- data/vendor/rufus-tokyo/spec/edo_ntyrant_spec.rb +0 -299
- data/vendor/rufus-tokyo/spec/edo_ntyrant_table_spec.rb +0 -462
- data/vendor/rufus-tokyo/spec/edo_table_spec.rb +0 -560
- data/vendor/rufus-tokyo/spec/hmethods_spec.rb +0 -44
- data/vendor/rufus-tokyo/spec/incr.lua +0 -20
- data/vendor/rufus-tokyo/spec/spec.rb +0 -9
- data/vendor/rufus-tokyo/spec/spec_base.rb +0 -23
- data/vendor/rufus-tokyo/spec/start_tyrants.sh +0 -26
- data/vendor/rufus-tokyo/spec/stop_tyrants.sh +0 -9
- data/vendor/rufus-tokyo/spec/table_spec.rb +0 -567
- data/vendor/rufus-tokyo/spec/tyrant_spec.rb +0 -309
- data/vendor/rufus-tokyo/spec/tyrant_table_spec.rb +0 -479
- data/vendor/rufus-tokyo/spec/util_list_spec.rb +0 -200
- data/vendor/rufus-tokyo/spec/util_map_spec.rb +0 -132
- data/vendor/rufus-tokyo/tasks/dev.rb +0 -70
- data/vendor/rufus-tokyo/test/bm0.rb +0 -353
- data/vendor/rufus-tokyo/test/bm1_compression.rb +0 -54
- data/vendor/rufus-tokyo/test/con0.rb +0 -30
- data/vendor/rufus-tokyo/test/mem.rb +0 -49
- data/vendor/rufus-tokyo/test/mem1.rb +0 -44
- data/vendor/rufus-tokyo/test/readme0.rb +0 -17
- data/vendor/rufus-tokyo/test/readme1.rb +0 -21
- data/vendor/rufus-tokyo/test/readme2.rb +0 -15
- data/vendor/rufus-tokyo/test/readme3.rb +0 -24
- data/vendor/rufus-tokyo/test/readmes_test.sh +0 -17
@@ -1,219 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
3
|
-
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
-
# of this software and associated documentation files (the "Software"), to deal
|
6
|
-
# in the Software without restriction, including without limitation the rights
|
7
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
-
# copies of the Software, and to permit persons to whom the Software is
|
9
|
-
# furnished to do so, subject to the following conditions:
|
10
|
-
#
|
11
|
-
# The above copyright notice and this permission notice shall be included in
|
12
|
-
# all copies or substantial portions of the Software.
|
13
|
-
#
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
-
# THE SOFTWARE.
|
21
|
-
#
|
22
|
-
# Made in Japan.
|
23
|
-
#++
|
24
|
-
|
25
|
-
|
26
|
-
require 'tokyocabinet' # gem install careo-tokyocabinet
|
27
|
-
|
28
|
-
require 'rufus/edo/cabcore'
|
29
|
-
require 'rufus/tokyo/config'
|
30
|
-
|
31
|
-
|
32
|
-
module Rufus::Edo
|
33
|
-
|
34
|
-
#
|
35
|
-
# A cabinet wired 'natively' to the libtokyocabinet.dynlib (approximatevely
|
36
|
-
# 2 times faster than the wiring over FFI).
|
37
|
-
#
|
38
|
-
# This class has the exact same methods as Rufus::Tokyo::Cabinet. It's faster
|
39
|
-
# though. The advantage of Rufus::Tokyo::Cabinet lies in that in runs on
|
40
|
-
# Ruby 1.8, 1.9 and JRuby.
|
41
|
-
#
|
42
|
-
# You need to have Hirabayashi-san's binding installed to use this
|
43
|
-
# Rufus::Edo::Cabinet :
|
44
|
-
#
|
45
|
-
# http://github.com/jmettraux/rufus-tokyo/tree/master/lib/rufus/edo
|
46
|
-
#
|
47
|
-
# You can then write code like :
|
48
|
-
#
|
49
|
-
# require 'rubygems'
|
50
|
-
# require 'rufus/edo' # sudo gem install rufus-tokyo
|
51
|
-
#
|
52
|
-
# db = Rufus::Edo::Cabinet.new('data.tch')
|
53
|
-
#
|
54
|
-
# db['hello'] = 'world'
|
55
|
-
#
|
56
|
-
# puts db['hello']
|
57
|
-
# # -> 'world'
|
58
|
-
#
|
59
|
-
# db.close
|
60
|
-
#
|
61
|
-
# This cabinet wraps hashes, b+ trees and fixed length databases. For tables,
|
62
|
-
# see Rufus::Edo::Table
|
63
|
-
#
|
64
|
-
class Cabinet
|
65
|
-
|
66
|
-
include Rufus::Edo::CabinetCore
|
67
|
-
include Rufus::Tokyo::CabinetConfig
|
68
|
-
|
69
|
-
# Initializes and open a cabinet (hash, b+ tree or fixed-size)
|
70
|
-
#
|
71
|
-
# db = Rufus::Edo::Cabinet.new('data.tch')
|
72
|
-
# # or
|
73
|
-
# db = Rufus::Edo::Cabinet.new('data', :type => :hash)
|
74
|
-
#
|
75
|
-
# 3 types are recognized :hash (.tch), :btree (.tcb) and :fixed (.tcf). For
|
76
|
-
# tables, see Rufus::Edo::Table
|
77
|
-
#
|
78
|
-
# == parameters
|
79
|
-
#
|
80
|
-
# There are two ways to pass parameters at the opening of a db :
|
81
|
-
#
|
82
|
-
# db = Rufus::Edo::Cabinet.new('data.tch#opts=ld#mode=w') # or
|
83
|
-
# db = Rufus::Edo::Cabinet.new('data.tch', :opts => 'ld', :mode => 'w')
|
84
|
-
#
|
85
|
-
# most verbose :
|
86
|
-
#
|
87
|
-
# db = Rufus::Edo::Cabinet.new(
|
88
|
-
# 'data', :type => :hash, :opts => 'ld', :mode => 'w')
|
89
|
-
#
|
90
|
-
# === mode
|
91
|
-
#
|
92
|
-
# * :mode a set of chars ('r'ead, 'w'rite, 'c'reate, 't'runcate,
|
93
|
-
# 'e' non locking, 'f' non blocking lock), default is 'wc'
|
94
|
-
#
|
95
|
-
# === other parameters
|
96
|
-
#
|
97
|
-
# 'On-memory hash database supports "bnum", "capnum", and "capsiz".
|
98
|
-
# On-memory tree database supports "capnum" and "capsiz".
|
99
|
-
# Hash database supports "mode", "bnum", "apow", "fpow", "opts",
|
100
|
-
# "rcnum", and "xmsiz".
|
101
|
-
# B+ tree database supports "mode", "lmemb", "nmemb", "bnum", "apow",
|
102
|
-
# "fpow", "opts", "lcnum", "ncnum", and "xmsiz".
|
103
|
-
# Fixed-length database supports "mode", "width", and "limsiz"'
|
104
|
-
#
|
105
|
-
# * :opts a set of chars ('l'arge, 'd'eflate, 'b'zip2, 't'cbs)
|
106
|
-
# (usually empty or something like 'ld' or 'lb')
|
107
|
-
#
|
108
|
-
# * :bnum number of elements of the bucket array
|
109
|
-
# * :apow size of record alignment by power of 2 (defaults to 4)
|
110
|
-
# * :fpow maximum number of elements of the free block pool by
|
111
|
-
# power of 2 (defaults to 10)
|
112
|
-
# * :mutex when set to true, makes sure only 1 thread at a time
|
113
|
-
# accesses the table (well, Ruby, global thread lock, ...)
|
114
|
-
#
|
115
|
-
# * :rcnum specifies the maximum number of records to be cached.
|
116
|
-
# If it is not more than 0, the record cache is disabled.
|
117
|
-
# It is disabled by default.
|
118
|
-
# * :lcnum specifies the maximum number of leaf nodes to be cached.
|
119
|
-
# If it is not more than 0, the default value is specified.
|
120
|
-
# The default value is 2048.
|
121
|
-
# * :ncnum specifies the maximum number of non-leaf nodes to be
|
122
|
-
# cached. If it is not more than 0, the default value is
|
123
|
-
# specified. The default value is 512.
|
124
|
-
#
|
125
|
-
# * :lmemb number of members in each leaf page (defaults to 128) (btree)
|
126
|
-
# * :nmemb number of members in each non-leaf page (default 256) (btree)
|
127
|
-
#
|
128
|
-
# * :width width of the value of each record (default 255) (fixed)
|
129
|
-
# * :limsiz limit size of the database file (default 268_435_456) (fixed)
|
130
|
-
#
|
131
|
-
# * :xmsiz specifies the size of the extra mapped memory. If it is
|
132
|
-
# not more than 0, the extra mapped memory is disabled.
|
133
|
-
# The default size is 67108864.
|
134
|
-
#
|
135
|
-
# * :capnum specifies the capacity number of records.
|
136
|
-
# * :capsiz specifies the capacity size of using memory.
|
137
|
-
#
|
138
|
-
# * :dfunit unit step number. If it is not more than 0,
|
139
|
-
# the auto defragmentation is disabled. (Since TC 1.4.21)
|
140
|
-
#
|
141
|
-
#
|
142
|
-
# = NOTE :
|
143
|
-
#
|
144
|
-
# On reopening a file, Cabinet will tend to stick to the parameters as
|
145
|
-
# set when the file was opened. To change that, have a look at the
|
146
|
-
# man pages of the various command line tools coming with Tokyo Cabinet.
|
147
|
-
#
|
148
|
-
def initialize (path, params={})
|
149
|
-
|
150
|
-
conf = determine_conf(path, params)
|
151
|
-
|
152
|
-
klass = {
|
153
|
-
:abstract => defined?(TokyoCabinet::ADB) ?
|
154
|
-
TokyoCabinet::ADB : TokyoCabinet::HDB,
|
155
|
-
:hash => TokyoCabinet::HDB,
|
156
|
-
:btree => TokyoCabinet::BDB,
|
157
|
-
:fixed => TokyoCabinet::FDB
|
158
|
-
}[conf[:type]]
|
159
|
-
|
160
|
-
@db = klass.new
|
161
|
-
|
162
|
-
#
|
163
|
-
# tune
|
164
|
-
|
165
|
-
tuning_parameters = case conf[:type]
|
166
|
-
when :abstract then nil
|
167
|
-
when :hash then [ :bnum, :apow, :fpow, :opts ]
|
168
|
-
when :btree then [ :lmemb, :nmemb, :bnum, :apow, :fpow, :opts ]
|
169
|
-
when :fixed then [ :bnum, :width, :limsiz ]
|
170
|
-
end
|
171
|
-
|
172
|
-
@db.tune(*tuning_parameters.collect { |o| conf[o] }) \
|
173
|
-
if tuning_parameters
|
174
|
-
|
175
|
-
#
|
176
|
-
# set cache
|
177
|
-
|
178
|
-
cache_values = case conf[:type]
|
179
|
-
when :abstract then nil
|
180
|
-
when :hash then [ :rcnum ]
|
181
|
-
when :btree then [ :lcnum, :ncnum ]
|
182
|
-
when :fixed then nil
|
183
|
-
end
|
184
|
-
|
185
|
-
@db.setcache(*cache_values.collect { |o| conf[o] }) \
|
186
|
-
if cache_values
|
187
|
-
|
188
|
-
#
|
189
|
-
# set xmsiz
|
190
|
-
|
191
|
-
@db.setxmsiz(conf[:xmsiz]) \
|
192
|
-
unless [ :abstract, :fixed ].include?(conf[:type])
|
193
|
-
|
194
|
-
#
|
195
|
-
# set dfunit (TC > 1.4.21)
|
196
|
-
|
197
|
-
@db.setdfunit(conf[:dfunit]) \
|
198
|
-
if @db.respond_to?(:setdfunit)
|
199
|
-
|
200
|
-
#
|
201
|
-
# open
|
202
|
-
|
203
|
-
@path = conf[:path]
|
204
|
-
|
205
|
-
if @db.class.name == 'TokyoCabinet::ADB'
|
206
|
-
@db.open(@path) || raise_error
|
207
|
-
else
|
208
|
-
@db.open(@path, conf[:mode]) || raise_error
|
209
|
-
end
|
210
|
-
|
211
|
-
#
|
212
|
-
# default
|
213
|
-
|
214
|
-
self.default = params[:default]
|
215
|
-
@default_proc ||= params[:default_proc]
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
@@ -1,159 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
3
|
-
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
-
# of this software and associated documentation files (the "Software"), to deal
|
6
|
-
# in the Software without restriction, including without limitation the rights
|
7
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
-
# copies of the Software, and to permit persons to whom the Software is
|
9
|
-
# furnished to do so, subject to the following conditions:
|
10
|
-
#
|
11
|
-
# The above copyright notice and this permission notice shall be included in
|
12
|
-
# all copies or substantial portions of the Software.
|
13
|
-
#
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
-
# THE SOFTWARE.
|
21
|
-
#
|
22
|
-
# Made in Japan.
|
23
|
-
#++
|
24
|
-
|
25
|
-
|
26
|
-
require 'tokyocabinet'
|
27
|
-
|
28
|
-
require 'rufus/edo/error'
|
29
|
-
require 'rufus/edo/tabcore'
|
30
|
-
require 'rufus/tokyo/config'
|
31
|
-
|
32
|
-
|
33
|
-
module Rufus::Edo
|
34
|
-
|
35
|
-
#
|
36
|
-
# Rufus::Edo::Table wraps Hirabayashi-san's Ruby bindings for Tokyo Cabinet
|
37
|
-
# tables.
|
38
|
-
#
|
39
|
-
# This class has the exact same methods as Rufus::Tokyo::Table. It's faster
|
40
|
-
# though. The advantage of Rufus::Tokyo::Table lies in that in runs on
|
41
|
-
# Ruby 1.8, 1.9 and JRuby.
|
42
|
-
#
|
43
|
-
# You need to have Hirabayashi-san's binding installed to use this
|
44
|
-
# Rufus::Edo::Table :
|
45
|
-
#
|
46
|
-
# http://github.com/jmettraux/rufus-tokyo/tree/master/lib/rufus/edo
|
47
|
-
#
|
48
|
-
# Example usage :
|
49
|
-
#
|
50
|
-
# require 'rufus/edo'
|
51
|
-
# db = Rufus::Edo::Table.new('data.tct')
|
52
|
-
# db['customer1'] = { 'name' => 'Taira no Kyomori', 'age' => '55' }
|
53
|
-
# # ...
|
54
|
-
# db.close
|
55
|
-
#
|
56
|
-
class Table
|
57
|
-
|
58
|
-
include Rufus::Tokyo::CabinetConfig
|
59
|
-
include Rufus::Edo::TableCore
|
60
|
-
|
61
|
-
# Initializes and open a table.
|
62
|
-
#
|
63
|
-
# db = Rufus::Edo::Table.new('data.tct')
|
64
|
-
# # or
|
65
|
-
# db = Rufus::Edo::Table.new('data', :type => :table)
|
66
|
-
# # or
|
67
|
-
# db = Rufus::Edo::Table.new('data')
|
68
|
-
#
|
69
|
-
# == parameters
|
70
|
-
#
|
71
|
-
# There are two ways to pass parameters at the opening of a db :
|
72
|
-
#
|
73
|
-
# db = Rufus::Edo::Table.new('data.tct#opts=ld#mode=w') # or
|
74
|
-
# db = Rufus::Edo::Table.new('data.tct', :opts => 'ld', :mode => 'w')
|
75
|
-
#
|
76
|
-
# === mode
|
77
|
-
#
|
78
|
-
# * :mode a set of chars ('r'ead, 'w'rite, 'c'reate, 't'runcate,
|
79
|
-
# 'e' non locking, 'f' non blocking lock), default is 'wc'
|
80
|
-
#
|
81
|
-
# === other parameters
|
82
|
-
#
|
83
|
-
# * :opts a set of chars ('l'arge, 'd'eflate, 'b'zip2, 't'cbs)
|
84
|
-
# (usually empty or something like 'ld' or 'lb')
|
85
|
-
#
|
86
|
-
# * :bnum number of elements of the bucket array
|
87
|
-
# * :apow size of record alignment by power of 2 (defaults to 4)
|
88
|
-
# * :fpow maximum number of elements of the free block pool by
|
89
|
-
# power of 2 (defaults to 10)
|
90
|
-
#
|
91
|
-
# * :rcnum specifies the maximum number of records to be cached.
|
92
|
-
# If it is not more than 0, the record cache is disabled.
|
93
|
-
# It is disabled by default.
|
94
|
-
# * :lcnum specifies the maximum number of leaf nodes to be cached.
|
95
|
-
# If it is not more than 0, the default value is specified.
|
96
|
-
# The default value is 2048.
|
97
|
-
# * :ncnum specifies the maximum number of non-leaf nodes to be
|
98
|
-
# cached. If it is not more than 0, the default value is
|
99
|
-
# specified. The default value is 512.
|
100
|
-
#
|
101
|
-
# * :dfunit unit step number. If it is not more than 0,
|
102
|
-
# the auto defragmentation is disabled. (Since TC 1.4.21)
|
103
|
-
#
|
104
|
-
# = NOTE :
|
105
|
-
#
|
106
|
-
# On reopening a file, Cabinet will tend to stick to the parameters as
|
107
|
-
# set when the file was opened. To change that, have a look at the
|
108
|
-
# man pages of the various command line tools coming with Tokyo Cabinet.
|
109
|
-
#
|
110
|
-
def initialize (path, params={})
|
111
|
-
|
112
|
-
conf = determine_conf(path, params, :table)
|
113
|
-
|
114
|
-
@db = TokyoCabinet::TDB.new
|
115
|
-
|
116
|
-
#
|
117
|
-
# tune
|
118
|
-
|
119
|
-
@db.tune(conf[:bnum], conf[:apow], conf[:fpow], conf[:opts])
|
120
|
-
|
121
|
-
#
|
122
|
-
# set cache
|
123
|
-
|
124
|
-
@db.setcache(conf[:rcnum], conf[:lcnum], conf[:ncnum])
|
125
|
-
|
126
|
-
#
|
127
|
-
# set xmsiz
|
128
|
-
|
129
|
-
@db.setxmsiz(conf[:xmsiz])
|
130
|
-
|
131
|
-
#
|
132
|
-
# set dfunit (TC > 1.4.21)
|
133
|
-
|
134
|
-
@db.setdfunit(conf[:dfunit]) if @db.respond_to?(:setdfunit)
|
135
|
-
|
136
|
-
#
|
137
|
-
# open
|
138
|
-
|
139
|
-
@path = conf[:path]
|
140
|
-
|
141
|
-
@db.open(@path, conf[:mode]) || raise_error
|
142
|
-
end
|
143
|
-
|
144
|
-
# Returns the path to this table.
|
145
|
-
#
|
146
|
-
def path
|
147
|
-
|
148
|
-
@path
|
149
|
-
end
|
150
|
-
|
151
|
-
protected
|
152
|
-
|
153
|
-
def table_query_class #:nodoc#
|
154
|
-
|
155
|
-
TokyoCabinet::TDBQRY
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
@@ -1,36 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
3
|
-
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
-
# of this software and associated documentation files (the "Software"), to deal
|
6
|
-
# in the Software without restriction, including without limitation the rights
|
7
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
-
# copies of the Software, and to permit persons to whom the Software is
|
9
|
-
# furnished to do so, subject to the following conditions:
|
10
|
-
#
|
11
|
-
# The above copyright notice and this permission notice shall be included in
|
12
|
-
# all copies or substantial portions of the Software.
|
13
|
-
#
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
-
# THE SOFTWARE.
|
21
|
-
#
|
22
|
-
# Made in Japan.
|
23
|
-
#++
|
24
|
-
|
25
|
-
|
26
|
-
module Rufus
|
27
|
-
module Edo
|
28
|
-
|
29
|
-
#
|
30
|
-
# A common error class
|
31
|
-
#
|
32
|
-
class EdoError < RuntimeError; end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
@@ -1,137 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
3
|
-
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
-
# of this software and associated documentation files (the "Software"), to deal
|
6
|
-
# in the Software without restriction, including without limitation the rights
|
7
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
-
# copies of the Software, and to permit persons to whom the Software is
|
9
|
-
# furnished to do so, subject to the following conditions:
|
10
|
-
#
|
11
|
-
# The above copyright notice and this permission notice shall be included in
|
12
|
-
# all copies or substantial portions of the Software.
|
13
|
-
#
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
-
# THE SOFTWARE.
|
21
|
-
#
|
22
|
-
# Made in Japan.
|
23
|
-
#++
|
24
|
-
|
25
|
-
|
26
|
-
require 'tokyotyrant' # gem install careo-tokyotyrant
|
27
|
-
|
28
|
-
require 'rufus/edo/error'
|
29
|
-
require 'rufus/edo/cabcore'
|
30
|
-
require 'rufus/tokyo/ttcommons'
|
31
|
-
|
32
|
-
|
33
|
-
module Rufus::Edo
|
34
|
-
|
35
|
-
#
|
36
|
-
# Connecting to a 'classic' Tokyo Tyrant server remotely
|
37
|
-
#
|
38
|
-
# require 'rufus/edo/ntyrant'
|
39
|
-
# t = Rufus::Edo::NetTyrant.new('127.0.0.1', 44001)
|
40
|
-
# t['toto'] = 'blah blah'
|
41
|
-
# t['toto'] # => 'blah blah'
|
42
|
-
#
|
43
|
-
class NetTyrant
|
44
|
-
|
45
|
-
include Rufus::Edo::CabinetCore
|
46
|
-
include Rufus::Tokyo::TyrantCommons
|
47
|
-
|
48
|
-
attr_reader :host, :port
|
49
|
-
|
50
|
-
# Connects to a given Tokyo Tyrant server.
|
51
|
-
#
|
52
|
-
# Note that if the port is not specified, the host parameter is expected
|
53
|
-
# to hold the path to a unix socket (not a TCP socket).
|
54
|
-
#
|
55
|
-
# (You can start a unix socket listening Tyrant with :
|
56
|
-
#
|
57
|
-
# ttserver -host /tmp/tyrant_socket -port 0 data.tch
|
58
|
-
#
|
59
|
-
# and then connect to it with rufus-tokyo via :
|
60
|
-
#
|
61
|
-
# require 'rufus/edo/ntyrant'
|
62
|
-
# db = Rufus::Edo::NetTyrant.new('/tmp/tyrant_socket')
|
63
|
-
# db['a'] = 'alpha'
|
64
|
-
# db.close
|
65
|
-
# )
|
66
|
-
#
|
67
|
-
# To connect to a classic TCP bound Tyrant (port 44001) :
|
68
|
-
#
|
69
|
-
# t = Rufus::Edo::NetTyrant.new('127.0.0.1', 44001)
|
70
|
-
#
|
71
|
-
def initialize (host, port=0)
|
72
|
-
|
73
|
-
@host = host
|
74
|
-
@port = port
|
75
|
-
|
76
|
-
@db = TokyoTyrant::RDB.new
|
77
|
-
@db.open(host, port) || raise_error
|
78
|
-
|
79
|
-
if self.stat['type'] == 'table'
|
80
|
-
|
81
|
-
@db.close
|
82
|
-
|
83
|
-
raise ArgumentError.new(
|
84
|
-
"tyrant at #{host}:#{port} is a table, " +
|
85
|
-
"use Rufus::Edo::NetTyrantTable instead to access it.")
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# Returns the 'weight' of the db (in bytes)
|
90
|
-
#
|
91
|
-
def weight
|
92
|
-
|
93
|
-
self.stat['size']
|
94
|
-
end
|
95
|
-
|
96
|
-
# isn't that a bit dangerous ? it creates a file on the server...
|
97
|
-
#
|
98
|
-
# DISABLED.
|
99
|
-
#
|
100
|
-
def copy (target_path)
|
101
|
-
|
102
|
-
#@db.copy(target_path)
|
103
|
-
raise 'not allowed to create files on the server'
|
104
|
-
end
|
105
|
-
|
106
|
-
# Copies the current cabinet to a new file.
|
107
|
-
#
|
108
|
-
# Does it by copying each entry afresh to the target file. Spares some
|
109
|
-
# space, hence the 'compact' label...
|
110
|
-
#
|
111
|
-
def compact_copy (target_path)
|
112
|
-
|
113
|
-
raise NotImplementedError.new('not creating files locally')
|
114
|
-
end
|
115
|
-
|
116
|
-
# Calls a lua embedded function
|
117
|
-
# (http://tokyocabinet.sourceforge.net/tyrantdoc/#luaext)
|
118
|
-
#
|
119
|
-
# Options are :global_locking and :record_locking
|
120
|
-
#
|
121
|
-
# Returns the return value of the called function.
|
122
|
-
#
|
123
|
-
# Nil is returned in case of failure.
|
124
|
-
#
|
125
|
-
def ext (func_name, key, value, opts={})
|
126
|
-
|
127
|
-
@db.ext(func_name.to_s, key.to_s, value.to_s, compute_ext_opts(opts))
|
128
|
-
end
|
129
|
-
|
130
|
-
protected
|
131
|
-
|
132
|
-
def do_stat #:nodoc#
|
133
|
-
@db.stat
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|