sadie 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +2 -1
- data/README +17 -1
- data/lib/lock_manager.rb +4 -1
- data/lib/sadie/version.rb +1 -1
- data/lib/sadie_session.rb +32 -11
- data/spec/sadie_session.rb +7 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dfcdf40230ae04f9b2f48e4cb73aafd71fc8ac7
|
4
|
+
data.tar.gz: 7f6aaca2f1f58be905c70bb428d695c726f1b972
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9668d2c48564497cabfa531bec49ae7178dd764fc897a1f24513c92c85b781fe3d18027e28f4007ecbd92e5eff7059be7c5d96470823a78bc05969c27c2191b
|
7
|
+
data.tar.gz: bf5835fdbcb385b8b3b6c7675908a0fcb1e78d91d921d2e0519ea27d6baef5e74a26ae172118d92e0309960fc8958496bf349e3f6e358b297ff03ddd6fbf88b3
|
data/CHANGELOG
CHANGED
@@ -27,4 +27,5 @@
|
|
27
27
|
[0.0.52] code cleanup
|
28
28
|
[0.1.01] ** ground-up rewrite, ignore everything before this line if you're not a historian **
|
29
29
|
[0.1.8] new version now at capability pairing with old version.
|
30
|
-
[0.1.9] added metadata for keys, abstracted expiry and refresh data structs into timestamp queues, abstracted various mutexes in session into lock manager object in preparation for distributed behavior
|
30
|
+
[0.1.9] added metadata for keys, abstracted expiry and refresh data structs into timestamp queues, abstracted various mutexes in session into lock manager object in preparation for distributed behavior
|
31
|
+
[0.1.10] added important lock to ensure that two threads (refresh and fetch, in this case, but will be more important in distributed case) cannot attempt to prime for the same key at the same time
|
data/README
CHANGED
@@ -60,8 +60,10 @@ Have a look at other primers in test/v2/test_installation/primers for more infor
|
|
60
60
|
Now run the sadie server on whatever directory you set it up on:
|
61
61
|
|
62
62
|
bin/sadie_server.rb --framework-dirpath=/var/sadie
|
63
|
+
|
64
|
+
When the server starts up, because this primer is set to refresh automatically, it will prime this key and it will do so again every 300 seconds as long as the server is running.
|
63
65
|
|
64
|
-
|
66
|
+
So now you can make GET requests on the keys,
|
65
67
|
|
66
68
|
wget http://localhost:4567/test.expires.nsecs -O /tmp/outputfile
|
67
69
|
|
@@ -72,6 +74,20 @@ Or, you can use the sadie session in your Ruby code like this:
|
|
72
74
|
|
73
75
|
That's it!
|
74
76
|
|
77
|
+
==Caveat
|
78
|
+
It's important to note that Sadie is going to be great for things like:
|
79
|
+
* webscraping a pre-defined list of websites
|
80
|
+
* digesting large datasets
|
81
|
+
* log analysis
|
82
|
+
|
83
|
+
but not so great for anything where you'd want to pass parameters to the querying function.
|
84
|
+
|
85
|
+
So it'd be great for grabbing a list of all facebook users who've ever mentioned your name along with everything they've ever written, but it wouldn't be wonderful at grabbing everything some particular facebook user has ever written about you.
|
86
|
+
|
87
|
+
Similarly, it'd be a wonderful tool for performing a statistical analysis on the game of baseball based on data from every baseball game ever played, but it's not well set up for you to ask it about a particular game (unless the game were of such interest that you took the time to write primers that were associated with that particular game).
|
88
|
+
|
89
|
+
Of course, it is, at it's core, a key/value hash and, as such, you could use it to do such things as well as you could any other. It is the primers that are limited, not the storage mechanism.
|
90
|
+
|
75
91
|
==Contribute
|
76
92
|
Do it! The github url for Sadie is at: [https://github.com/FredAtLandMetrics/sadie]
|
77
93
|
|
data/lib/lock_manager.rb
CHANGED
@@ -10,6 +10,9 @@ class LockManager
|
|
10
10
|
systype = params[:systype].to_s
|
11
11
|
locktype = params[:locktype].to_s
|
12
12
|
lock_id = "#{systype}:#{locktype}"
|
13
|
+
if params.has_key?(:key)
|
14
|
+
lock_id += ":#{params[:key].to_s}"
|
15
|
+
end
|
13
16
|
@locks[lock_id] = Mutex.new unless @locks.has_key?( lock_id )
|
14
17
|
lock_id
|
15
18
|
end
|
@@ -41,7 +44,7 @@ class LockManager
|
|
41
44
|
def critical_section_try( lock_id )
|
42
45
|
if block_given?
|
43
46
|
if @locks.has_key?( lock_id )
|
44
|
-
|
47
|
+
unless acquire( lock_id ).nil?
|
45
48
|
yield
|
46
49
|
release( lock_id )
|
47
50
|
end
|
data/lib/sadie/version.rb
CHANGED
data/lib/sadie_session.rb
CHANGED
@@ -114,26 +114,47 @@ class SadieSession
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def get( key )
|
117
|
+
ret = nil
|
117
118
|
if @storage_manager.has_key?( key )
|
118
|
-
@storage_manager.get( key )
|
119
|
+
ret = @storage_manager.get( key )
|
119
120
|
elsif primer_registered?( key )
|
120
|
-
|
121
|
-
|
122
|
-
|
121
|
+
|
122
|
+
@primer_lock = @lockmgr.create( :systype => :session,
|
123
|
+
:locktype => :primer,
|
124
|
+
:key => key )
|
125
|
+
p = nil
|
126
|
+
|
127
|
+
@lockmgr.critical_section_try( @primer_lock ) do
|
128
|
+
p = _get_primed_primer( key )
|
123
129
|
ret = @storage_manager.get( key )
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
130
|
+
if p.expire == :on_get
|
131
|
+
@storage_manager.unset( key )
|
132
|
+
end
|
133
|
+
end
|
134
|
+
if ! p.nil?
|
135
|
+
_manage_refresh( key, p.refresh_rate ) if ( p.refreshes? )
|
136
|
+
else
|
137
|
+
@lockmgr.critical_section_insist( @primer_lock ) do
|
138
|
+
if @storage_manager.has_key?( key )
|
139
|
+
ret = @storage_manager.get( key )
|
140
|
+
else
|
141
|
+
ret = get( key ) # recurse should only happen if primer set to expire on get
|
142
|
+
end
|
143
|
+
end
|
131
144
|
end
|
145
|
+
|
132
146
|
end
|
147
|
+
ret
|
133
148
|
end
|
134
149
|
|
135
150
|
private
|
136
151
|
|
152
|
+
def _get_primed_primer( key )
|
153
|
+
p = Primer.new( :session => self )
|
154
|
+
p.decorate( @registered_key[ key ] )
|
155
|
+
p
|
156
|
+
end
|
157
|
+
|
137
158
|
def _initialize_refresh_thread
|
138
159
|
@refresh_thread = Thread.new do
|
139
160
|
_refresh_loop
|
data/spec/sadie_session.rb
CHANGED
@@ -160,6 +160,13 @@ describe SadieSession do
|
|
160
160
|
|
161
161
|
end
|
162
162
|
|
163
|
+
it "should not be possible to prime the same key more than once at the same time" do
|
164
|
+
val = @session.get("wait.primary")
|
165
|
+
sleep 1
|
166
|
+
val = @session.get("wait.primary")
|
167
|
+
($max > 1).should be_false
|
168
|
+
end
|
169
|
+
|
163
170
|
# --- SLOW!
|
164
171
|
if ENV.has_key?('SADIE_SESSION_TEST_TIMERS') && ENV['SADIE_SESSION_TEST_TIMERS'].to_i == 1
|
165
172
|
|