Permalink
Browse files

fixes replication of CAS

  • Loading branch information...
1 parent 995fe9e commit 8aa2dbadd3ae2451f92b3daa7967ab0f2628f6a0 @frsyuki frsyuki committed May 14, 2010
Showing with 36 additions and 22 deletions.
  1. +5 −5 rt/09_cas.rt
  2. +30 −16 src/logic/server/mod_store.cc
  3. +1 −1 src/storage/storage.cc
View
10 rt/09_cas.rt
@@ -4,7 +4,7 @@ require 'common'
include Chukan::Test
LOOP_RESTART = (ARGV[0] || ENV["LOOP_RESTART"] || (ENV["HEAVY"] ? 20 : 3)).to_i
-NUM_STORE = (ARGV[2] || 5).to_i
+NUM_STORE = (ARGV[2] || 500).to_i
NUM_THREAD = (ARGV[3] || 1).to_i
mgr, gw, srv1, srv2, srv3 = init_cluster(false, 3)
@@ -40,25 +40,25 @@ test "run normally" do
begin
- result = c.cas(key) do |val|
+ result = c.cas(key) do |val1|
test "cas success" do
begin
c.cas(key) do |val2|
- "val#{i}"
+ val
end
rescue
raise "cas failed #{key.inspect} => #{val.inspect}: #{$!.inspect}"
end
end
- "val#{i}"
+ val
end
if result =~ /EXISTS/
true
else
- $stderr.puts "cas unexpectedly succeeded #{key.inspect} => #{val.inspect}: #{$!.inspect}"
+ $stderr.puts "cas unexpectedly succeeded #{key.inspect} => #{val.inspect}: #{result.inspect}"
false
end
View
46 src/logic/server/mod_store.cc
@@ -217,6 +217,35 @@ RPC_IMPL(mod_store_t, Set, req, z, response)
SHARED_ZONE(life, z);
+ switch(op) {
+ case OP_SET:
+ case OP_SET_ASYNC:
+ break;
+
+ case OP_CAS: {
+ LOG_TRACE("try cas: ",val.clocktime().get());
+ bool success = share->db().cas(
+ key.raw_data(), key.raw_size(),
+ val.raw_data(), val.raw_size(),
+ cas_require);
+ if(!success) {
+ response.result(false);
+ return;
+ }
+ } break;
+
+ case OP_PREPEND:
+ // FIXME
+ break;
+
+ case OP_APPEND:
+ // FIXME
+ break;
+
+ default:
+ throw std::logic_error("unknown operation");
+ }
+
volatile unsigned int* pcr =
(volatile unsigned int*)life->malloc(sizeof(volatile unsigned int));
if(op == OP_SET_ASYNC) { *pcr = 0; }
@@ -268,24 +297,9 @@ RPC_IMPL(mod_store_t, Set, req, z, response)
val.raw_data(), val.raw_size());
} break;
- case OP_CAS: {
- LOG_TRACE("try cas: ",val.clocktime().get());
- bool success = share->db().cas(
- key.raw_data(), key.raw_size(),
- val.raw_data(), val.raw_size(),
- cas_require);
- if(!success) {
- response.result(false);
- return;
- }
- } break;
-
+ case OP_CAS:
case OP_PREPEND:
- // FIXME
- break;
-
case OP_APPEND:
- // FIXME
break;
default:
View
2 src/storage/storage.cc
@@ -96,7 +96,7 @@ static bool storage_casproc(void* casdata,
const char* oldval, size_t oldvallen)
{
if(oldvallen < Storage::VALUE_CLOCKTIME_SIZE) {
- return true;
+ return false;
}
ClockTime compare =

0 comments on commit 8aa2dba

Please sign in to comment.