flok 0.0.80 → 0.0.81

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0211bf5635601e2e799ddd564e3612c8a02e1354
4
- data.tar.gz: 45aa0d364ed30d8a2d01e0ca2d4cb2abcd2ab61b
3
+ metadata.gz: 34171632263d52984e5054c52cbe49a8a211a128
4
+ data.tar.gz: 864c32e073e18f76e714883b098c5fe8115b1cb7
5
5
  SHA512:
6
- metadata.gz: f47cfbb76f1f5aa170fb8c38963c9df5a2d0179ef617d90c4f7981b733097cf26e6cc4c26c9a74881c1806c40a73a6935d0063ca489c7102630e767e63f59cdd
7
- data.tar.gz: 2ab9e84d9daeccf7f11877a4443e8f36a4fcd3ede44cf0cc0ee7ee5a3413c946e9b20d694ee36c131633d8a3c568cc720d798064ca2a4817c441c44f0cb03d63
6
+ metadata.gz: 572ef58be4f5556a8627ebbbf9bbb5fd8e8088a435ef114bb539befd061f9790e6f39e9dc1b05134a79ed155a681c8688fe2570b45d3517cc8cbfa0f0847bf96
7
+ data.tar.gz: 479b11b9c06d97ca855c00813aaf7b5eaafa646df33b115df3e19d644c0ef90551bc59d7c6c1fdaf71ce23ce5b86c69963e5f93d2301ff2d4de513f17465a2ec
@@ -29,7 +29,6 @@ service :vm do
29
29
  <%= p[:namespace] %>: {},
30
30
  <% end %>
31
31
  };
32
-
33
32
  ////////////////////////////////////////////////////////////////////////////////////////////
34
33
 
35
34
  //Cache
@@ -118,6 +117,22 @@ service :vm do
118
117
  //Part of the persist module
119
118
  //res is page
120
119
  function int_per_get_res(s, ns, id, res) {
120
+ if (ns === "__reserved__") {
121
+ if (id === "vm_unsynced") {
122
+ var old_vm_unsynced = vm_unsynced;
123
+ vm_unsynced = res;
124
+
125
+ <% @options[:pagers].each do |p| %>
126
+ var old_vm_unsynced_ns = old_vm_unsynced.<%= p[:namespace] %>;
127
+ var ids = Object.keys(old_vm_unsynced_ns);
128
+ for (var i = 0; i < ids.length; ++i) {
129
+ vm_unsynced.<%= p[:namespace] %>[ids[i]] = old_vm_unsynced_ns[ids[i]];
130
+ }
131
+ <% end %>
132
+ }
133
+ return;
134
+ }
135
+
121
136
  if (res !== null) {
122
137
  //Write out to the cache
123
138
  vm_transaction_begin();
@@ -517,7 +532,12 @@ service :vm do
517
532
  <% end %>
518
533
  };
519
534
 
535
+ //Does it need to be written to disk?
536
+ vm_unsynced_is_dirty = false;
537
+
520
538
  function vm_pg_mark_needs_sync(ns, page_id) {
539
+ vm_unsynced_is_dirty = true;
540
+
521
541
  //Add to list
522
542
  vm_unsynced[ns][page_id] = 0;
523
543
 
@@ -538,6 +558,8 @@ service :vm do
538
558
  }
539
559
 
540
560
  function vm_pg_unmark_needs_sync(ns, page_id) {
561
+ vm_unsynced_is_dirty = true;
562
+
541
563
  delete vm_unsynced[ns][page_id];
542
564
  }
543
565
 
@@ -557,6 +579,25 @@ service :vm do
557
579
  }
558
580
  <% end %>
559
581
  }
582
+
583
+ vm_unsynced_paged_in = false;
584
+ function vm_pg_sync_pagein() {
585
+ //Only pages-in if necessary
586
+ if (vm_unsynced_paged_in === false) {
587
+ vm_unsynced_paged_in = true;
588
+
589
+ //Send a disk read request
590
+ SEND("disk", "if_per_get", "vm", "__reserved__", "vm_unsynced");
591
+ }
592
+ }
593
+
594
+ function vm_pg_sync_pageout() {
595
+ //Only page-out if necessary
596
+ if (vm_unsynced_is_dirty === true) {
597
+ vm_unsynced_is_dirty = false;
598
+ SEND("disk", "if_per_set", "__reserved__", "vm_unsynced", JSON.stringify(vm_unsynced));
599
+ }
600
+ }
560
601
  ///////////////////////////////////////////////////////////////////////////
561
602
  }
562
603
 
@@ -765,5 +806,10 @@ service :vm do
765
806
  every 20.seconds, %{
766
807
  vm_pageout();
767
808
  vm_pg_sync_wakeup();
809
+ vm_pg_sync_pageout();
810
+ }
811
+
812
+ every 2.seconds, %{
813
+ vm_pg_sync_pagein();
768
814
  }
769
815
  end
data/lib/flok/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Flok
2
- VERSION = "0.0.80"
2
+ VERSION = "0.0.81"
3
3
  end
@@ -0,0 +1,19 @@
1
+ #Simple service config that uses built-in spec service to create a instance called 'spec'
2
+ service_instance :vm, :vm, {
3
+ :pagers => [
4
+ {
5
+ :name => "pg_spec0",
6
+ :namespace => "spec",
7
+ :options => {
8
+ "hello" => "world"
9
+ }
10
+ },
11
+ {
12
+ :name => "pg_spec1",
13
+ :namespace => "spec1",
14
+ :options => {
15
+ "hello" => "world"
16
+ }
17
+ }
18
+ ]
19
+ }
@@ -0,0 +1,253 @@
1
+ #The vm service unsynced to ensure that the unsynced survives a restart
2
+ #by saving to the disk cache
3
+
4
+ Dir.chdir File.join File.dirname(__FILE__), '../../'
5
+ require './spec/env/kern.rb'
6
+ require './spec/lib/helpers.rb'
7
+ require './spec/lib/io_extensions.rb'
8
+ require './spec/lib/rspec_extensions.rb'
9
+ require 'zlib'
10
+
11
+ RSpec.describe "kern:vm_service unsynced (persist)" do
12
+ include Zlib
13
+ include_context "kern"
14
+
15
+ it "Should have called vm_pg_sync_pagein after 2 seconds" do
16
+ ctx = flok_new_user File.read('./spec/kern/assets/vm/controller0.rb'), File.read("./spec/kern/assets/vm/config5c.rb")
17
+ dump = ctx.evald %{
18
+ //Needed to initialize pagers
19
+ base = _embed("my_controller", 0, {}, null);
20
+ }
21
+
22
+ #Should not be loaded at this time
23
+ expect(ctx.eval("vm_unsynced_paged_in")).to eq(false)
24
+
25
+ #Call the timer for 2 seconds (should invoke the load for the pg_spec0_sync_request)
26
+ (2*4).times do
27
+ @driver.int "int_timer", []
28
+ end
29
+
30
+ #Should be loaded at this time
31
+ expect(ctx.eval("vm_unsynced_paged_in")).to eq(true)
32
+ end
33
+
34
+ it "vm_pg_sync_pagein should make a disk request; and only once if called multiple times" do
35
+ ctx = flok_new_user File.read('./spec/kern/assets/vm/controller0.rb'), File.read("./spec/kern/assets/vm/config5c.rb")
36
+ dump = ctx.evald %{
37
+ //Needed to initialize pagers
38
+ base = _embed("my_controller", 0, {}, null);
39
+
40
+ vm_pg_sync_pagein();
41
+ vm_pg_sync_pagein();
42
+
43
+ int_dispatch([]);
44
+ }
45
+
46
+ #Should be loaded (manually called)
47
+ expect(ctx.eval("vm_unsynced_paged_in")).to eq(true)
48
+
49
+ #Should have made a disk request
50
+ @driver.ignore_up_to "if_per_get", 2
51
+
52
+ #Expect a request for the special page that holds vm_unsynced
53
+ res = @driver.get "if_per_get", 2
54
+ expect(res[1]).to eq("__reserved__")
55
+ expect(res[2]).to eq("vm_unsynced")
56
+
57
+ @driver.expect_not_to_contain "if_per_get"
58
+ end
59
+
60
+ it "vm_pg_sync_pagein should write out the read to vm_unsynced" do
61
+ ctx = flok_new_user File.read('./spec/kern/assets/vm/controller0.rb'), File.read("./spec/kern/assets/vm/config5c.rb")
62
+ dump = ctx.evald %{
63
+ //Needed to initialize pagers
64
+ base = _embed("my_controller", 0, {}, null);
65
+
66
+ vm_pg_sync_pagein();
67
+
68
+ int_dispatch([]);
69
+ }
70
+
71
+ #Should be loaded (manually called)
72
+ expect(ctx.eval("vm_unsynced_paged_in")).to eq(true)
73
+
74
+ #Expect a request for the special page that holds vm_unsynced
75
+ @driver.ignore_up_to "if_per_get", 2
76
+ res = @driver.get "if_per_get", 2
77
+ expect(res[1]).to eq("__reserved__")
78
+ expect(res[2]).to eq("vm_unsynced")
79
+
80
+ #Return the vm_unsynced
81
+ @driver.int "int_per_get_res", [
82
+ "vm",
83
+ "__reserved__",
84
+ "vm_unsynced",
85
+ {
86
+ "spec" => {
87
+ "test" => 1
88
+ }
89
+ }
90
+ ]
91
+
92
+ #Expect vm_unsynced to have loaded the data
93
+ res = @ctx.dump("vm_unsynced")
94
+ expect(res).to eq({
95
+ "spec" => {
96
+ "test" => 1
97
+ }
98
+ })
99
+ end
100
+
101
+ it "vm_pg_sync_pagein should write out the read to vm_unsynced and merge if there are any existing elements" do
102
+ ctx = flok_new_user File.read('./spec/kern/assets/vm/controller0.rb'), File.read("./spec/kern/assets/vm/config5d.rb")
103
+ dump = ctx.evald %{
104
+ //Needed to initialize pagers
105
+ base = _embed("my_controller", 0, {}, null);
106
+
107
+ vm_pg_sync_pagein();
108
+
109
+ vm_unsynced = {
110
+ "spec": {
111
+ "foo": 0
112
+ },
113
+
114
+ "spec1": {
115
+ "bar": 1
116
+ }
117
+ }
118
+
119
+ int_dispatch([]);
120
+ }
121
+
122
+ #Should be loaded (manually called)
123
+ expect(ctx.eval("vm_unsynced_paged_in")).to eq(true)
124
+
125
+ #Expect a request for the special page that holds vm_unsynced
126
+ @driver.ignore_up_to "if_per_get", 2
127
+ res = @driver.get "if_per_get", 2
128
+ expect(res[1]).to eq("__reserved__")
129
+ expect(res[2]).to eq("vm_unsynced")
130
+
131
+ #Return the vm_unsynced
132
+ @driver.int "int_per_get_res", [
133
+ "vm",
134
+ "__reserved__",
135
+ "vm_unsynced",
136
+ {
137
+ "spec" => {
138
+ "holah" => 1,
139
+ },
140
+ "spec1" => {
141
+ }
142
+ }
143
+ ]
144
+
145
+ #Expect vm_unsynced to have loaded the data
146
+ res = @ctx.dump("vm_unsynced")
147
+ expect(res).to eq({
148
+ "spec" => {
149
+ "foo" => 0,
150
+ "holah" => 1,
151
+ },
152
+ "spec1" => {
153
+ "bar" => 1
154
+ }
155
+ })
156
+ end
157
+
158
+ it "vm_pg_sync_pageout should save the vm_unsynced data to disk; and only once on multiple calls" do
159
+ ctx = flok_new_user File.read('./spec/kern/assets/vm/controller0.rb'), File.read("./spec/kern/assets/vm/config5c.rb")
160
+ dump = ctx.evald %{
161
+ //Needed to initialize pagers
162
+ base = _embed("my_controller", 0, {}, null);
163
+
164
+ vm_unsynced = {
165
+ "spec": {
166
+ "foo": 0
167
+ },
168
+
169
+ "spec1": {
170
+ "bar": 1
171
+ }
172
+ }
173
+
174
+ //Request a save
175
+ vm_unsynced_is_dirty = true;
176
+ vm_pg_sync_pageout();
177
+ vm_pg_sync_pageout();
178
+
179
+ int_dispatch([]);
180
+ }
181
+
182
+ #Expect a write out
183
+ @driver.ignore_up_to "if_per_set", 2
184
+ res = @driver.get "if_per_set", 2
185
+ expect(res[0]).to eq("__reserved__")
186
+ expect(res[1]).to eq("vm_unsynced")
187
+ vm_unsynced_json = res[2]
188
+ expect(JSON.parse(vm_unsynced_json)).to eq({
189
+ "spec" => {
190
+ "foo" => 0
191
+ },
192
+ "spec1" => {
193
+ "bar" => 1
194
+ }
195
+ })
196
+
197
+ #Should not have two requests
198
+ @driver.expect_not_to_contain "if_per_set"
199
+
200
+ expect(ctx.eval("vm_unsynced_is_dirty")).to eq(false)
201
+ end
202
+
203
+ it "vm_pg_sync_pageout should be called periodically every 20 seconds" do
204
+ ctx = flok_new_user File.read('./spec/kern/assets/vm/controller0.rb'), File.read("./spec/kern/assets/vm/config5c.rb")
205
+ dump = ctx.evald %{
206
+ //Needed to initialize pagers
207
+ base = _embed("my_controller", 0, {}, null);
208
+
209
+ vm_unsynced = {
210
+ "spec": {
211
+ "foo": 0
212
+ },
213
+
214
+ "spec1": {
215
+ "bar": 1
216
+ }
217
+ }
218
+
219
+ //Ensure that pageout is going to be called
220
+ vm_unsynced_is_dirty = true;
221
+
222
+ int_dispatch([]);
223
+ }
224
+
225
+ #Expect no write out yet until 20s have passed
226
+ @driver.expect_not_to_contain "if_per_set"
227
+ (20*4).times do
228
+ @driver.int "int_timer", []
229
+ end
230
+
231
+ #Now we expect a write out as 20s have passed
232
+ #And the 0s should now be 1 because we called vm_pg_sync_wakeup() right before hand
233
+ @driver.ignore_up_to "if_per_set"
234
+ res = @driver.get "if_per_set", 2
235
+ expect(JSON.parse(res[2])).to eq(
236
+ "spec" => {
237
+ "foo" => 1
238
+ },
239
+
240
+ "spec1" => {
241
+ "bar" => 1
242
+ }
243
+ )
244
+
245
+ #Wait again 20 seconds
246
+ (20*4).times do
247
+ @driver.int "int_timer", []
248
+ end
249
+
250
+ #Expect no write out as we are not dirty
251
+ @driver.expect_not_to_contain "if_per_set"
252
+ end
253
+ end
@@ -7,7 +7,7 @@ require './spec/lib/io_extensions.rb'
7
7
  require './spec/lib/rspec_extensions.rb'
8
8
  require 'zlib'
9
9
 
10
- RSpec.describe "kern:vm_service" do
10
+ RSpec.describe "kern:vm_service unsynced" do
11
11
  include Zlib
12
12
  include_context "kern"
13
13
 
@@ -110,7 +110,7 @@ RSpec.describe "kern:vm_service" do
110
110
  vm_pg_mark_needs_sync("spec", "test");
111
111
  }
112
112
 
113
- #Call the timer for 1 shot
113
+ #Call the timer for 1 shot of vm_sync_wakeup
114
114
  (20*4).times do
115
115
  @driver.int "int_timer", []
116
116
  end
@@ -118,7 +118,7 @@ RSpec.describe "kern:vm_service" do
118
118
  #First time, the vm_pg_sync_wakeup should not have triggered anything (vm_unsynced still set to 0)
119
119
  expect(ctx.dump("pg_spec0_sync_requests")).to eq(["test"])
120
120
 
121
- #Call the timer for 1 more shot
121
+ #Call the timer for 1 more shot of vm_sync_wakeup
122
122
  (20*4).times do
123
123
  @driver.int "int_timer", []
124
124
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flok
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.80
4
+ version: 0.0.81
5
5
  platform: ruby
6
6
  authors:
7
7
  - seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-03 00:00:00.000000000 Z
11
+ date: 2015-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs
@@ -1206,6 +1206,7 @@ files:
1206
1206
  - spec/kern/assets/vm/config5.rb
1207
1207
  - spec/kern/assets/vm/config5b.rb
1208
1208
  - spec/kern/assets/vm/config5c.rb
1209
+ - spec/kern/assets/vm/config5d.rb
1209
1210
  - spec/kern/assets/vm/config6.rb
1210
1211
  - spec/kern/assets/vm/controller0.rb
1211
1212
  - spec/kern/assets/vm/controller0_diff.rb
@@ -1304,6 +1305,7 @@ files:
1304
1305
  - spec/kern/vm_service_mem_pagers_spec.rb
1305
1306
  - spec/kern/vm_service_net_sim_pager_spec.rb
1306
1307
  - spec/kern/vm_service_spec.rb
1308
+ - spec/kern/vm_service_unsynced_persist_spec.rb
1307
1309
  - spec/kern/vm_service_unsynced_spec.rb
1308
1310
  - spec/kern/vm_sockio_pager_spec.rb
1309
1311
  - spec/kern/vm_transaction_spec.rb
@@ -2156,6 +2158,7 @@ test_files:
2156
2158
  - spec/kern/assets/vm/config5.rb
2157
2159
  - spec/kern/assets/vm/config5b.rb
2158
2160
  - spec/kern/assets/vm/config5c.rb
2161
+ - spec/kern/assets/vm/config5d.rb
2159
2162
  - spec/kern/assets/vm/config6.rb
2160
2163
  - spec/kern/assets/vm/controller0.rb
2161
2164
  - spec/kern/assets/vm/controller0_diff.rb
@@ -2254,6 +2257,7 @@ test_files:
2254
2257
  - spec/kern/vm_service_mem_pagers_spec.rb
2255
2258
  - spec/kern/vm_service_net_sim_pager_spec.rb
2256
2259
  - spec/kern/vm_service_spec.rb
2260
+ - spec/kern/vm_service_unsynced_persist_spec.rb
2257
2261
  - spec/kern/vm_service_unsynced_spec.rb
2258
2262
  - spec/kern/vm_sockio_pager_spec.rb
2259
2263
  - spec/kern/vm_transaction_spec.rb