In this article I’ll tell you about my pure functional library for Software Transactional Memory (STM)
that I’ve built in C++. I adopted some advanced functional programming concepts that make it composable and convenient to use. Its implementation is rather small and robust, which differentiates the library from competitors. Let’s discuss what STM is and how to use it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace function scheduler.run_tasks() returns void as $$ | |
declare | |
_function_name varchar; | |
_sqlstate text; | |
_message text; | |
_exception_detail text; | |
_exception_hint text; | |
_exception_context text; | |
_run_tasks_counter bigint; | |
_start_time timestamp with time zone; |
Требования
Для работы необходим PostgreSQL-server 9.5 и, более-менее "свежий", Docker
Настройка сервера баз данных
Т.к. app-server и worker работают в docker-контейнерах, то следует прописать его (докера) сеть в pg_hba.conf
host all all 172.17.0.0/24 password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ time ./try_advisory_lock | |
Waiting | |
[5] Done, processed 1274 rows. | |
[7] Done, processed 1236 rows. | |
[2] Done, processed 1252 rows. | |
[4] Done, processed 1237 rows. | |
[8] Done, processed 1257 rows. | |
[6] Done, processed 1257 rows. | |
[3] Done, processed 1244 rows. | |
[1] Done, processed 1243 rows. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do $$ | |
declare | |
_rawjson json; | |
_item record; | |
_id int; | |
_param text; | |
begin | |
for _rawjson in select * from json_array_elements('[{"id" : 42, "params" : ["bad", "sad"] }]'::json) loop | |
_item = (select j from json_to_record(_rawjson) AS j ( | |
id int, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- src/bin/pg_basebackup/pg_basebackup_origin.c 2016-03-24 12:42:30.312362751 +0300 | |
+++ src/bin/pg_basebackup/pg_basebackup.c 2016-03-24 09:45:40.804376436 +0300 | |
@@ -239,6 +239,7 @@ | |
" (in kB/s, or use suffix \"k\" or \"M\")\n")); | |
printf(_(" -R, --write-recovery-conf\n" | |
" write recovery.conf after backup\n")); | |
+ printf(_(" -S, --slot=SLOTNAME replication slot to use\n")); | |
printf(_(" -T, --tablespace-mapping=OLDDIR=NEWDIR\n" | |
" relocate tablespace in OLDDIR to NEWDIR\n")); | |
printf(_(" -x, --xlog include required WAL files in backup (fetch mode)\n")); |