Thu Jun 7 06:01:12 PDT 2007
- Previous message: [Slony1-commit] slony1-engine/src/slon remote_worker.c
- Next message: [Slony1-commit] slony1-engine RELEASE-2.0
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Update of /home/cvsd/slony1/slony1-engine/src/backend In directory main.slony.info:/tmp/cvs-serv25549/src/backend Modified Files: Makefile slony1_funcs.c slony1_funcs.sql Log Message: Attempt to remove the sl_seqlog flood. This patch adds a new function seqtrack(seqid,seqvalue) that will return NULL if called with the same seqvalue before, the seqvalue instead. This function is used to suppress sl_seqlog rows of sequences that didn't change since the last SYNC. Jan Index: slony1_funcs.c =================================================================== RCS file: /home/cvsd/slony1/slony1-engine/src/backend/slony1_funcs.c,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** slony1_funcs.c 31 May 2007 16:46:18 -0000 1.61 --- slony1_funcs.c 7 Jun 2007 13:01:10 -0000 1.62 *************** *** 14,17 **** --- 14,19 ---- #include "config.h" + #include "avl_tree.c" + #include "miscadmin.h" #include "nodes/makefuncs.h" *************** *** 52,55 **** --- 54,58 ---- PG_FUNCTION_INFO_V1(_Slony_I_lockedSet); PG_FUNCTION_INFO_V1(_Slony_I_killBackend); + PG_FUNCTION_INFO_V1(_Slony_I_seqtrack); PG_FUNCTION_INFO_V1(_slon_quote_ident); *************** *** 64,67 **** --- 67,71 ---- Datum _Slony_I_lockedSet(PG_FUNCTION_ARGS); Datum _Slony_I_killBackend(PG_FUNCTION_ARGS); + Datum _Slony_I_seqtrack(PG_FUNCTION_ARGS); Datum _slon_quote_ident(PG_FUNCTION_ARGS); *************** *** 76,84 **** #define PLAN_INSERT_LOG (1 << 2) - #define SLON_ROLE_UNSET 0 - #define SLON_ROLE_NORMAL 1 - #define SLON_ROLE_SLON 2 - - /* ---- --- 80,83 ---- *************** *** 960,963 **** --- 959,1026 ---- + typedef struct { + int32 seqid; + int64 seqval; + } SeqTrack_elem; + + static int + seqtrack_cmp(void *seq1, void *seq2) + { + return (((SeqTrack_elem *)seq1)->seqid - ((SeqTrack_elem *)seq2)->seqid); + } + + static void + seqtrack_free(void *seq) + { + free(seq); + } + + Datum + _Slony_I_seqtrack(PG_FUNCTION_ARGS) + { + static AVLtree seqmem = AVL_INITIALIZER(seqtrack_cmp, seqtrack_free); + AVLnode *node; + SeqTrack_elem *elem; + int32 seqid; + int64 seqval; + + seqid = PG_GETARG_INT32(0); + seqval = PG_GETARG_INT64(1); + + /* + * Try to insert the sequence id into the AVL tree. + */ + if ((node = avl_insert(&seqmem, &seqid)) == NULL) + elog(ERROR, "Slony-I: unexpected NULL return from avl_insert()"); + + if (AVL_DATA(node) == NULL) + { + /* + * This is a new (not seen before) sequence. Create the element, + * remember the current lastval and return it to the caller. + */ + elem = (SeqTrack_elem *)malloc(sizeof(SeqTrack_elem)); + elem->seqid = seqid; + elem->seqval = seqval; + AVL_SETDATA(node, elem); + + PG_RETURN_INT64(seqval); + } + + /* + * This is a sequence seen before. If the value has changed + * remember and return it. If it did not, return NULL. + */ + elem = AVL_DATA(node); + + if (elem->seqval == seqval) + PG_RETURN_NULL(); + else + elem->seqval = seqval; + + PG_RETURN_INT64(seqval); + } + + static char * slon_quote_literal(char *str) *************** *** 1278,1291 **** "insert into %s.sl_seqlog " "(seql_seqid, seql_origin, seql_ev_seqno, seql_last_value) " ! "select seq_id, '%d', currval('%s.sl_event_seq'), seq_last_value " "from %s.sl_seqlastvalue " ! "where seq_origin = '%d'; " ! "insert into %s.sl_seqlog " ! "(seql_seqid, seql_origin, seql_ev_seqno) " ! "select '0', '%d', currval('%s.sl_event_seq'); ", cs->clusterident, cs->localNodeId, cs->clusterident, cs->clusterident, cs->localNodeId, - cs->clusterident, cs->localNodeId, cs->clusterident); --- 1341,1352 ---- "insert into %s.sl_seqlog " "(seql_seqid, seql_origin, seql_ev_seqno, seql_last_value) " ! "select * from (" ! "select seq_id, %d, currval('%s.sl_event_seq'), seq_last_value " "from %s.sl_seqlastvalue " ! "where seq_origin = '%d') as FOO " ! "where NOT %s.seqtrack(seq_id, seq_last_value) IS NULL; ", cs->clusterident, cs->localNodeId, cs->clusterident, cs->clusterident, cs->localNodeId, cs->clusterident); Index: Makefile =================================================================== RCS file: /home/cvsd/slony1/slony1-engine/src/backend/Makefile,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** Makefile 31 May 2007 16:46:18 -0000 1.25 --- Makefile 7 Jun 2007 13:01:10 -0000 1.26 *************** *** 42,47 **** $(SO_NAME): $(SO_OBJS) clean distclean maintainer-clean: ! rm -f $(SO_NAME) $(SO_OBJS) splint: --- 42,55 ---- $(SO_NAME): $(SO_OBJS) + $(NAME).o: $(NAME).c avl_tree.c avl_tree.h + + avl_tree.c: ../misc/avl_tree.c + cp $< $@ + + avl_tree.h: ../misc/avl_tree.h + cp $< $@ + clean distclean maintainer-clean: ! rm -f $(SO_NAME) $(SO_OBJS) avl_tree.c avl_tree.h splint: Index: slony1_funcs.sql =================================================================== RCS file: /home/cvsd/slony1/slony1-engine/src/backend/slony1_funcs.sql,v retrieving revision 1.110 retrieving revision 1.111 diff -C2 -d -r1.110 -r1.111 *** slony1_funcs.sql 31 May 2007 17:44:02 -0000 1.110 --- slony1_funcs.sql 7 Jun 2007 13:01:10 -0000 1.111 *************** *** 256,259 **** --- 256,271 ---- -- ---------------------------------------------------------------------- + -- FUNCTION seqtrack (seqid, seqval) + -- + -- + -- ---------------------------------------------------------------------- + create or replace function @NAMESPACE at .seqtrack (int4, int8) returns int8 + as '$libdir/slony1_funcs', '_Slony_I_seqtrack' + strict language C; + + comment on function @NAMESPACE at .seqtrack(int4, int8) is + 'Returns NULL if seqval has not changed since the last call for seqid'; + + -- ---------------------------------------------------------------------- -- FUNCTION slon_quote_brute(text) --
- Previous message: [Slony1-commit] slony1-engine/src/slon remote_worker.c
- Next message: [Slony1-commit] slony1-engine RELEASE-2.0
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Slony1-commit mailing list