sohm 0.10.1 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sohm/lua/save.lua +2 -1
- data/lib/sohm.rb +65 -47
- data/sohm.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39fb619f570ad3f62832bbcdd996cdc69415be89
|
4
|
+
data.tar.gz: f41f415ad11975dac2524514ad4cbc37cefe850f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d9ed24c9db23f038e4df3f68a2f674668b08f29358266891e4d925799be03efee441910de76a9e61a05213e516287ec9bd07ba26f4dfb9766914ef639c2d5de
|
7
|
+
data.tar.gz: a2a0b78bb3e19a8af9a798059b0bdd80a183482358d997790c77331bf8b303d7fe1961204a578b4659102d0cced8d26b0a6b033faeb9985004ffb1b7eb250425
|
data/lib/sohm/lua/save.lua
CHANGED
@@ -6,7 +6,8 @@ if (not ctoken) or ctoken == ARGV[2] then
|
|
6
6
|
else
|
7
7
|
ntoken = tonumber(ctoken) + 1
|
8
8
|
end
|
9
|
-
redis.call('HMSET', KEYS[1], '_sdata', ARGV[1],
|
9
|
+
redis.call('HMSET', KEYS[1], '_sdata', ARGV[1],
|
10
|
+
'_cas', ntoken, '_ndata', ARGV[3])
|
10
11
|
return ntoken
|
11
12
|
else
|
12
13
|
error('cas_error')
|
data/lib/sohm.rb
CHANGED
@@ -108,6 +108,19 @@ module Sohm
|
|
108
108
|
@mutex
|
109
109
|
end
|
110
110
|
|
111
|
+
# If this is true, Sohm::Model#save would refresh all indices inline
|
112
|
+
# when called, this might hurt performance in certain cases. You can
|
113
|
+
# use this flag here to disable this inline refreshing, then use external
|
114
|
+
# background workers to refresh indices by calling Sohm::Model#refresh_indices
|
115
|
+
@refresh_indices_inline = true
|
116
|
+
def self.refresh_indices_inline=(flag)
|
117
|
+
@refresh_indices_inline = flag
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.refresh_indices_inline
|
121
|
+
@refresh_indices_inline
|
122
|
+
end
|
123
|
+
|
111
124
|
# By default, EVALSHA is used
|
112
125
|
def self.enable_evalsha
|
113
126
|
defined?(@enable_evalsha) ? @enable_evalsha : true
|
@@ -1060,7 +1073,8 @@ module Sohm
|
|
1060
1073
|
if serial_attributes_changed
|
1061
1074
|
response = script(LUA_SAVE, 1, key,
|
1062
1075
|
sanitize_attributes(serial_attributes).to_msgpack,
|
1063
|
-
cas_token
|
1076
|
+
cas_token,
|
1077
|
+
sanitize_attributes(attributes).to_msgpack)
|
1064
1078
|
|
1065
1079
|
if response.is_a?(RuntimeError)
|
1066
1080
|
if response.message =~ /cas_error/
|
@@ -1072,16 +1086,62 @@ module Sohm
|
|
1072
1086
|
|
1073
1087
|
@cas_token = response
|
1074
1088
|
@serial_attributes_changed = false
|
1089
|
+
else
|
1090
|
+
redis.call("HSET", key, "_ndata",
|
1091
|
+
sanitize_attributes(attributes).to_msgpack)
|
1075
1092
|
end
|
1076
1093
|
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
refresh_indices
|
1094
|
+
if Sohm.refresh_indices_inline
|
1095
|
+
refresh_indices
|
1096
|
+
end
|
1081
1097
|
|
1082
1098
|
return self
|
1083
1099
|
end
|
1084
1100
|
|
1101
|
+
# Refresh model indices
|
1102
|
+
def refresh_indices
|
1103
|
+
memo_key = key["_indices"]
|
1104
|
+
# Add new indices first
|
1105
|
+
commands = fetch_indices.each_pair.map do |field, vals|
|
1106
|
+
vals.map do |val|
|
1107
|
+
index_key = model.key["_indices"][field][val]
|
1108
|
+
[["SADD", memo_key, index_key], ["SADD", index_key, id]]
|
1109
|
+
end
|
1110
|
+
end.flatten(2)
|
1111
|
+
|
1112
|
+
model.synchronize do
|
1113
|
+
commands.each do |command|
|
1114
|
+
redis.queue(*command)
|
1115
|
+
end
|
1116
|
+
redis.commit
|
1117
|
+
end
|
1118
|
+
|
1119
|
+
# Remove old indices
|
1120
|
+
index_set = ::Set.new(redis.call("SMEMBERS", memo_key))
|
1121
|
+
# Here we are fetching the latest model to avoid concurrency issue
|
1122
|
+
valid_list = model[id].send(:fetch_indices).each_pair.map do |field, vals|
|
1123
|
+
vals.map do |val|
|
1124
|
+
model.key["_indices"][field][val]
|
1125
|
+
end
|
1126
|
+
end.flatten(1)
|
1127
|
+
valid_set = ::Set.new(valid_list)
|
1128
|
+
diff_set = index_set - valid_set
|
1129
|
+
if diff_set.size > 0
|
1130
|
+
diff_list = diff_set.to_a
|
1131
|
+
commands = diff_list.map do |key|
|
1132
|
+
["SREM", key, id]
|
1133
|
+
end + [["SREM", memo_key] + diff_list]
|
1134
|
+
|
1135
|
+
model.synchronize do
|
1136
|
+
commands.each do |command|
|
1137
|
+
redis.queue(*command)
|
1138
|
+
end
|
1139
|
+
redis.commit
|
1140
|
+
end
|
1141
|
+
end
|
1142
|
+
true
|
1143
|
+
end
|
1144
|
+
|
1085
1145
|
# Delete the model, including all the following keys:
|
1086
1146
|
#
|
1087
1147
|
# - <Model>:<id>
|
@@ -1215,48 +1275,6 @@ module Sohm
|
|
1215
1275
|
indices
|
1216
1276
|
end
|
1217
1277
|
|
1218
|
-
# This is performed asynchronously
|
1219
|
-
def refresh_indices
|
1220
|
-
memo_key = key["_indices"]
|
1221
|
-
# Add new indices first
|
1222
|
-
commands = fetch_indices.each_pair.map do |field, vals|
|
1223
|
-
vals.map do |val|
|
1224
|
-
index_key = model.key["_indices"][field][val]
|
1225
|
-
[["SADD", memo_key, index_key], ["SADD", index_key, id]]
|
1226
|
-
end
|
1227
|
-
end.flatten(2)
|
1228
|
-
|
1229
|
-
# TODO: Think about switching to a redis pool later
|
1230
|
-
model.synchronize do
|
1231
|
-
commands.each do |command|
|
1232
|
-
redis.queue(*command)
|
1233
|
-
end
|
1234
|
-
redis.commit
|
1235
|
-
end
|
1236
|
-
|
1237
|
-
# Remove old indices
|
1238
|
-
# TODO: we can do this asynchronously, or maybe in a background queue
|
1239
|
-
index_set = ::Set.new(redis.call("SMEMBERS", memo_key))
|
1240
|
-
valid_list = model[id].send(:fetch_indices).each_pair.map do |field, vals|
|
1241
|
-
vals.map do |val|
|
1242
|
-
model.key["_indices"][field][val]
|
1243
|
-
end
|
1244
|
-
end.flatten(1)
|
1245
|
-
valid_set = ::Set.new(valid_list)
|
1246
|
-
diff_set = index_set - valid_set
|
1247
|
-
diff_list = diff_set.to_a
|
1248
|
-
commands = diff_list.map do |key|
|
1249
|
-
["SREM", key, id]
|
1250
|
-
end + [["SREM", memo_key] + diff_list]
|
1251
|
-
|
1252
|
-
model.synchronize do
|
1253
|
-
commands.each do |command|
|
1254
|
-
redis.queue(*command)
|
1255
|
-
end
|
1256
|
-
redis.commit
|
1257
|
-
end
|
1258
|
-
end
|
1259
|
-
|
1260
1278
|
# Unpack hash returned by redis, which contains _cas, _sdata, _ndata
|
1261
1279
|
# columns
|
1262
1280
|
def unpack_attrs(attrs)
|
data/sohm.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "sohm"
|
3
|
-
s.version = "0.10.
|
3
|
+
s.version = "0.10.2"
|
4
4
|
s.summary = %{Slim ohm for twemproxy-like system}
|
5
5
|
s.description = %Q{Slim ohm is a forked ohm that works with twemproxy-like redis system, only a limited set of features in ohm is supported}
|
6
6
|
s.authors = ["Xuejie Xiao"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sohm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xuejie Xiao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redic
|