Permalink
Browse files

Advisory locks baseline implementation

  • Loading branch information...
sbellware committed Jun 4, 2018
1 parent 14f5306 commit 68867eae6abceacb41f81397688463bcd3ced1fe
@@ -18,7 +18,7 @@ BEGIN
message_id = uuid(_id);
stream_name_hash = hash_64(_stream_name);
PERFORM pg_advisory_lock(stream_name_hash);
PERFORM pg_advisory_xact_lock(stream_name_hash);
stream_version := stream_version(_stream_name);
@@ -28,7 +28,6 @@ BEGIN
if _expected_version is not null then
if _expected_version != stream_version then
PERFORM pg_advisory_unlock(stream_name_hash);
raise exception 'Wrong expected version: % (Stream: %, Stream Version: %)', _expected_version, _stream_name, stream_version;
end if;
end if;
@@ -55,8 +54,6 @@ BEGIN
)
;
PERFORM pg_advisory_unlock(stream_name_hash);
return position;
END;
$$ LANGUAGE plpgsql;
@@ -1 +1 @@
SELECT write_message('someStream-123', 'SomeType', '{"someField":"some value"}', '{"someMetadataField":"some metadata value"}', 1);
SELECT write_message(gen_random_uuid()::varchar, 'testWriteIsolation'::varchar, 'SomeType'::varchar, '{"attribute": "79a59e513f9182d5754abdf9b90e2179"}'::jsonb, '{"metaAttribute": "6b3ae03d713a51a445290f3fc4b5223a"}'::jsonb, 1::bigint);
@@ -1 +1 @@
SELECT write_message('someStream-123', 'SomeType', '{"someField":"some value"}', '{"someMetadataField":"some metadata value"}');
SELECT write_message(gen_random_uuid()::varchar, 'testWriteIsolation'::varchar, 'SomeType'::varchar, '{"attribute": "79a59e513f9182d5754abdf9b90e2179"}'::jsonb, '{"metaAttribute": "6b3ae03d713a51a445290f3fc4b5223a"}'::jsonb);
@@ -1,13 +1,16 @@
require_relative 'interactive_init'
message_data = Controls::MessageData::Write.example
stream_name = 'testWriteIsolation'
message_data_1 = Controls::MessageData::Write.example(data: { attribute: 1 })
message_data_2 = Controls::MessageData::Write.example(data: { attribute: 2 })
batch = [message_data_1, message_data_2]
write = Write.build
i = 0
loop do
position = write.(message_data, stream_name)
position = write.(batch, stream_name)
puts "i: #{i}, p: #{position}"
i += 1
end

0 comments on commit 68867ea

Please sign in to comment.